mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-19 23:39:46 +02:00
Merge branch 'origin/2.0.x' to master
All checks were successful
gitea-sync/antosdk-apps/pipeline/head This commit looks good
All checks were successful
gitea-sync/antosdk-apps/pipeline/head This commit looks good
This commit is contained in:
27
Blogger/README.md
Normal file
27
Blogger/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Blogger
|
||||
|
||||
Blackend for my blog at https://blog.iohub.dev
|
||||
|
||||
|
||||
## Change logs
|
||||
|
||||
### v0.2.x-a
|
||||
* Patch 13: fix bug on blog save
|
||||
* Patch 12: support send mail via SSL
|
||||
* Patch 11: Add TFIDF analyse functionality
|
||||
* Patch 10: Migrate code to typescript, use SQLiteDB lib for database access
|
||||
* Patch 9: Update to use the new MDE library
|
||||
* Patch 8: Support for antOS 2.0.x
|
||||
* Patch 7: Fix sendmail API security bug
|
||||
* Patch 6: Chage libraries load order
|
||||
* Patch 5: Add user photo to portfolio
|
||||
* Patch 4: Add package dependencies
|
||||
* Patch 3: Correct JSON text decoding
|
||||
* Patch 2: Bug fix rendering content
|
||||
* Patch 0-1 Important change: Store raw post content to the database instead of base64 string as before
|
||||
|
||||
### v0.1.x-a
|
||||
* Patch 3-4: Enhance youtube video embedding feature in markdown
|
||||
* Patch 2: CV Category now can be created when database is not created yet
|
||||
* Patch 1: Fix package archive broken
|
||||
* Patch 0: Change default email of the sender
|
83
Blogger/api/ai/analyse.lua
Normal file
83
Blogger/api/ai/analyse.lua
Normal file
@ -0,0 +1,83 @@
|
||||
local args = ...
|
||||
|
||||
local ret = {
|
||||
error = false,
|
||||
result = nil
|
||||
}
|
||||
local __dir__ = debug.getinfo(1).source:match("@?(.*/)")
|
||||
LOG_DEBUG("CURRENT PATH:%s", __dir__)
|
||||
local cluster = loadfile(__dir__.."/cluster.lua")()
|
||||
local dbpath = require("vfs").ospath(args.dbpath)
|
||||
LOG_DEBUG("DB PATH:%s", dbpath)
|
||||
|
||||
local gettext = {}
|
||||
gettext.get = function(file)
|
||||
local db = DBModel:new{db=file}
|
||||
db:open()
|
||||
if not db then return nil end
|
||||
local data, sort = db:find("blogs", {
|
||||
where = { publish = 1 },
|
||||
fields = {"id", "content"}
|
||||
})
|
||||
db:close()
|
||||
if not data or #data == 0 then return nil end
|
||||
return data
|
||||
end
|
||||
|
||||
gettext.stopwords = function(ospath)
|
||||
local words = {}
|
||||
for line in io.lines(ospath) do
|
||||
words[line] = true
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
local data = gettext.get(dbpath)
|
||||
local documents = {}
|
||||
if data then
|
||||
local sw = gettext.stopwords(__dir__.."/stopwords.txt")
|
||||
for k, v in pairs(data) do
|
||||
local bag = cluster.bow(data[k].content, sw)
|
||||
documents[data[k].id] = bag
|
||||
end
|
||||
|
||||
cluster.tfidf(documents)
|
||||
-- indexing all terms to cache file
|
||||
local cache_file = dbpath..".index.json"
|
||||
local f = io.open(cache_file, "w")
|
||||
if f then
|
||||
local indexes = {}
|
||||
for id, doc in pairs(documents) do
|
||||
for term,v in pairs(doc) do
|
||||
if not indexes[term] then
|
||||
indexes[term] = {}
|
||||
end
|
||||
indexes[term][tostring(id)] = doc[term].tfidf
|
||||
end
|
||||
end
|
||||
f:write(JSON.encode(indexes))
|
||||
f:close()
|
||||
end
|
||||
--
|
||||
--local v = cluster.search("arm", documents)
|
||||
--echo(JSON.encode(v))
|
||||
local vectors, maxv, size = cluster.get_vectors(documents)
|
||||
local analytical = DBModel:new{db=dbpath}
|
||||
analytical:open()
|
||||
-- purge the table
|
||||
analytical:delete("st_similarity", nil)
|
||||
-- get similarity and put to the table
|
||||
for id, v in pairs(vectors) do
|
||||
local top = cluster.top_similarity(id, vectors, args.top, 0.1)
|
||||
for a, b in pairs(top) do
|
||||
local record = {pid = id, sid = a, score = b}
|
||||
analytical:insert("st_similarity", record)
|
||||
end
|
||||
end
|
||||
analytical:close()
|
||||
ret.result = "Analyse complete"
|
||||
else
|
||||
ret.error = "Unable to query database for post"
|
||||
end
|
||||
|
||||
return ret
|
346
Blogger/api/ai/cluster.lua
Normal file
346
Blogger/api/ai/cluster.lua
Normal file
@ -0,0 +1,346 @@
|
||||
local doclassify = {}
|
||||
local st = require("stmr")
|
||||
doclassify.bow = function(data, stopwords)
|
||||
-- first step get a table of worlds that contain
|
||||
-- world: occurences
|
||||
local bag = {}
|
||||
for w in data:gmatch('%w+') do
|
||||
local word = w:lower()
|
||||
if not stopwords[word] then
|
||||
word = st.stmr(word)
|
||||
if bag[word] then
|
||||
bag[word].count = bag[word].count + 1
|
||||
else
|
||||
bag[word] = {count=0, tf=0, tfidf=0.0}
|
||||
bag[word].count = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
-- now calculate the tf of the bag
|
||||
for k,v in pairs(bag) do
|
||||
bag[k].tf = math.log(1 + bag[k].count)
|
||||
end
|
||||
return bag
|
||||
end
|
||||
doclassify.len = function(table)
|
||||
local cnt = 0
|
||||
for k,v in pairs(table) do cnt = cnt+1 end
|
||||
return cnt
|
||||
end
|
||||
doclassify.tfidf = function(documents)
|
||||
-- now for each term in a bag, calculate
|
||||
-- the inverse document frequency, which
|
||||
-- is a measure of how much information
|
||||
-- the word provides, that is, whether the
|
||||
-- term is common or rare across all documents
|
||||
local ndoc = doclassify.len(documents)
|
||||
for k,bag in pairs(documents) do
|
||||
-- for eacht term in bag
|
||||
-- calculate its idf across all documents
|
||||
for term,b in pairs(bag) do
|
||||
local n = 0
|
||||
for id,doc in pairs(documents) do
|
||||
if doc[term] then n = n+1 end
|
||||
end
|
||||
--echo("term:"..term.." appears in"..n.." documents")
|
||||
b.tfidf = b.tf*math.log(ndoc/n)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
doclassify.search = function(term, documents)
|
||||
local r = {}
|
||||
for id, doc in pairs(documents) do
|
||||
if doc[term:lower()] then
|
||||
r[id] = doc[term].tfidf
|
||||
end
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
doclassify.get_vectors = function(documents)
|
||||
-- get a list of vector from documents
|
||||
local index = 0
|
||||
local vectors = {}
|
||||
local maps = {}
|
||||
local terms = {}
|
||||
local maxv = 0
|
||||
|
||||
for id in pairs(documents) do
|
||||
maps[id] = {}
|
||||
vectors[id] = {}
|
||||
end
|
||||
-- first loop, get the term
|
||||
for id, doc in pairs(documents) do
|
||||
for k,v in pairs(doc) do
|
||||
-- get max value
|
||||
if v.tfidf > maxv then
|
||||
maxv = v.tfidf
|
||||
end
|
||||
-- get the term
|
||||
if not terms[k] then
|
||||
index = index + 1
|
||||
terms[k] = index
|
||||
end
|
||||
for pid in pairs(documents) do
|
||||
if not maps[pid][k] then
|
||||
if id == pid then
|
||||
maps[pid][k] = v.tfidf
|
||||
else
|
||||
maps[pid][k] = 0
|
||||
end
|
||||
else
|
||||
if maps[pid][k] == 0 and id == pid then
|
||||
maps[pid][k] = v.tfidf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- reindexing the vectors
|
||||
for id in pairs(documents) do
|
||||
for k,v in pairs(maps[id]) do
|
||||
vectors[id][terms[k]] = v
|
||||
end
|
||||
end
|
||||
--echo("Max tfidf "..maxv.." in document #"..maxid.." of term "..term)
|
||||
return vectors, maxv, index, terms
|
||||
end
|
||||
|
||||
doclassify.similarity = function(va, vb)
|
||||
-- using cosin similarity
|
||||
local dotp = 0
|
||||
local maga = 0
|
||||
local magb = 0
|
||||
for k = 1,#va do
|
||||
dotp = dotp + va[k]*vb[k]
|
||||
maga = maga + va[k]*va[k]
|
||||
magb = magb + vb[k]*vb[k]
|
||||
end
|
||||
maga = math.sqrt(maga)
|
||||
magb = math.sqrt(magb)
|
||||
local d = 0
|
||||
if maga ~= 0 and magb ~= 0 then
|
||||
d = dotp/ (magb*maga)
|
||||
end
|
||||
return d
|
||||
end
|
||||
doclassify.similarities = function(v1, collection)
|
||||
local similarities = {}
|
||||
assert(#v1 == #(collection[1]), "Incorrect vectors size")
|
||||
for i=1,#collection do
|
||||
similarities[i] = doclassify.similarity(v1, collection[i])
|
||||
end
|
||||
return similarities
|
||||
end
|
||||
|
||||
doclassify.mean_similarity = function(v1, v2)
|
||||
assert(#v1 == #v2, "Incorrect vectors size")
|
||||
local similarities = {}
|
||||
for i = 1,#v1 do similarities[i] = doclassify.similarity(v1[i], v2[i]) end
|
||||
return doclassify.mean(similarities)
|
||||
end
|
||||
doclassify.similarity_chart = function(id, vectors)
|
||||
local vs = {}
|
||||
local cnt = 0
|
||||
local lut = {}
|
||||
for k,v in pairs(vectors) do
|
||||
if k ~= id then
|
||||
cnt = cnt + 1
|
||||
vs[cnt] = v
|
||||
lut[cnt] = k
|
||||
end
|
||||
end
|
||||
if not vs[1] then return {} end
|
||||
return doclassify.similarities(vectors[id], vs), lut
|
||||
end
|
||||
|
||||
doclassify.top_similarity = function(id, vectors, n, th)
|
||||
local chart,lut = doclassify.similarity_chart(id,vectors)
|
||||
--echo(JSON.encode(chart))
|
||||
--echo(JSON.encode(lut))
|
||||
if not lut or #lut <= 0 then return nil end
|
||||
local top = {}
|
||||
|
||||
local j=0
|
||||
local goon = true
|
||||
if not th then
|
||||
goon = false
|
||||
th = 0
|
||||
end
|
||||
|
||||
while j < n or goon
|
||||
do
|
||||
local i,maxv = doclassify.argmax(chart)
|
||||
top[lut[i]] = maxv
|
||||
chart[i] = 0.0
|
||||
j=j+1
|
||||
if maxv < th and goon then
|
||||
goon = false
|
||||
end
|
||||
end
|
||||
|
||||
--for j=1,n do
|
||||
-- local i,maxv = doclassify.argmax(chart)
|
||||
-- top[lut[i]] = maxv
|
||||
-- chart[i] = 0.0
|
||||
--end
|
||||
return top
|
||||
|
||||
end
|
||||
doclassify.save_vectors = function(vectors, name)
|
||||
local f = io.open(name,"w")
|
||||
if f == nil then return false end
|
||||
for id, v in pairs(vectors) do
|
||||
f:write(id)
|
||||
for i=1,#v do f:write(","..v[i]) end
|
||||
f:write("\n")
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
doclassify.save_topchart = function(vectors, name,n)
|
||||
local f = io.open(name,"w")
|
||||
if f == nil then return false end
|
||||
for k,v in pairs(vectors) do
|
||||
local top = doclassify.top_similarity(k,vectors,n, 0.1)
|
||||
for a,b in pairs(top) do
|
||||
f:write(k.." "..a.." "..b.."\n")
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
doclassify.kmean = function(nclass, documents, maxstep, ids)
|
||||
-- now
|
||||
local vectors, maxv, size = doclassify.get_vectors(documents)
|
||||
-- random centroids
|
||||
local centroids = {}
|
||||
local old_centroids = {}
|
||||
local clusters = {}
|
||||
--for pid in pairs(documents) do clusters[pid] = 0 end
|
||||
-- add noise to mean_vector
|
||||
for i = 1,nclass do
|
||||
if ids == nil then
|
||||
centroids[i] = doclassify.random(size,math.floor(maxv))
|
||||
else
|
||||
centroids[i] = vectors[ids[i]]
|
||||
end
|
||||
old_centroids[i] = doclassify.zeros(size)
|
||||
end
|
||||
|
||||
-- loop until convergence or maxstep reached
|
||||
local similarity = doclassify.mean_similarity(centroids, old_centroids)
|
||||
local step = maxstep
|
||||
while 1.0-similarity > 1e-9 and step > 0 do
|
||||
clusters = {}
|
||||
--echo(JSON.encode(centroids))
|
||||
for id,v in pairs(vectors) do
|
||||
local similarities = doclassify.similarities(v, centroids)
|
||||
--echo(JSON.encode(similarities))
|
||||
local cluster, maxvalue = doclassify.argmax(similarities)
|
||||
--echo("doc #"..id.." is in clusters #"..cluster.." max value is "..maxvalue)
|
||||
clusters[id] = cluster
|
||||
end
|
||||
-- storing the old centroids
|
||||
old_centroids = centroids
|
||||
-- calculate new centroids
|
||||
local new_centroids = {}
|
||||
for class in pairs(centroids) do
|
||||
local cnt = 0
|
||||
local cvectors = {}
|
||||
for id,v in pairs(vectors) do
|
||||
if clusters[id] == class then
|
||||
cnt = cnt + 1
|
||||
cvectors[cnt] = v
|
||||
end
|
||||
end
|
||||
new_centroids[class] = doclassify.mean_vector(cvectors, size)
|
||||
end
|
||||
centroids = new_centroids
|
||||
--echo(JSON.encode(centroids))
|
||||
--echo(JSON.encode(old_centroids))
|
||||
similarity = doclassify.mean_similarity(centroids, old_centroids)
|
||||
echo("step #"..step..", similarity "..similarity)
|
||||
step = step - 1
|
||||
end
|
||||
local results = {}
|
||||
for i = 1,nclass do
|
||||
local list = {}
|
||||
local cnt = 0
|
||||
for id,c in pairs(clusters) do
|
||||
if c == i then
|
||||
cnt = cnt + 1
|
||||
list[cnt] = id
|
||||
end
|
||||
end
|
||||
results[i] = list
|
||||
end
|
||||
return results, clusters, centroids
|
||||
end
|
||||
|
||||
doclassify.zeros = function(n)
|
||||
local vector = {}
|
||||
for i = 1,n do vector[i] = 0.0 end
|
||||
return vector
|
||||
end
|
||||
|
||||
doclassify.random = function(n,maxv)
|
||||
local vector = {}
|
||||
for i=1,n do
|
||||
vector[i] = math.random() + math.random(0, maxv)
|
||||
end
|
||||
return vector
|
||||
end
|
||||
|
||||
doclassify.sum = function(v)
|
||||
local sum = 0.0
|
||||
for i=1,#v do sum = sum + v[i] end
|
||||
return sum
|
||||
end
|
||||
|
||||
doclassify.mean = function(v)
|
||||
return doclassify.sum(v)/#v
|
||||
|
||||
end
|
||||
|
||||
doclassify.mean_vector = function(vectors, size)
|
||||
local means = doclassify.zeros(size)
|
||||
if not vectors or #vectors == 0 then return means end
|
||||
--local size = #(vectors[1])
|
||||
local times = 0
|
||||
for k,v in pairs(vectors) do
|
||||
for i=1,#v do means[i] = means[i] + v[i] end
|
||||
times = times + 1
|
||||
end
|
||||
for i = 1,size do means[i] = means[i]/times end
|
||||
return means
|
||||
end
|
||||
|
||||
doclassify.argmin = function(v)
|
||||
local minv = 0.0
|
||||
local mini = 0.0
|
||||
for i = 1,#v do
|
||||
if v[i] <= minv then
|
||||
mini = i
|
||||
minv = v[i]
|
||||
end
|
||||
end
|
||||
--echo("min index"..mini.." val "..minv)
|
||||
return mini, minv
|
||||
end
|
||||
|
||||
doclassify.argmax = function(v)
|
||||
local maxv = 0.0
|
||||
local maxi = 0.0
|
||||
for i = 1,#v do
|
||||
if v[i] >= maxv then
|
||||
maxi = i
|
||||
maxv = v[i]
|
||||
end
|
||||
end
|
||||
return maxi,maxv
|
||||
end
|
||||
|
||||
return doclassify
|
151
Blogger/api/ai/stopwords.txt
Normal file
151
Blogger/api/ai/stopwords.txt
Normal file
@ -0,0 +1,151 @@
|
||||
i
|
||||
me
|
||||
my
|
||||
myself
|
||||
we
|
||||
our
|
||||
ours
|
||||
ourselves
|
||||
you
|
||||
your
|
||||
yours
|
||||
yourself
|
||||
yourselves
|
||||
he
|
||||
him
|
||||
his
|
||||
himself
|
||||
she
|
||||
her
|
||||
hers
|
||||
herself
|
||||
it
|
||||
its
|
||||
itself
|
||||
they
|
||||
them
|
||||
their
|
||||
theirs
|
||||
themselves
|
||||
what
|
||||
which
|
||||
who
|
||||
whom
|
||||
this
|
||||
that
|
||||
these
|
||||
those
|
||||
am
|
||||
is
|
||||
are
|
||||
was
|
||||
were
|
||||
be
|
||||
been
|
||||
being
|
||||
have
|
||||
has
|
||||
had
|
||||
having
|
||||
do
|
||||
does
|
||||
did
|
||||
doing
|
||||
a
|
||||
an
|
||||
the
|
||||
and
|
||||
but
|
||||
if
|
||||
or
|
||||
because
|
||||
as
|
||||
until
|
||||
while
|
||||
of
|
||||
at
|
||||
by
|
||||
for
|
||||
with
|
||||
about
|
||||
against
|
||||
between
|
||||
into
|
||||
through
|
||||
during
|
||||
before
|
||||
after
|
||||
above
|
||||
below
|
||||
to
|
||||
from
|
||||
up
|
||||
down
|
||||
in
|
||||
out
|
||||
on
|
||||
off
|
||||
over
|
||||
under
|
||||
again
|
||||
further
|
||||
then
|
||||
once
|
||||
here
|
||||
there
|
||||
when
|
||||
where
|
||||
why
|
||||
how
|
||||
all
|
||||
any
|
||||
both
|
||||
each
|
||||
few
|
||||
more
|
||||
most
|
||||
other
|
||||
some
|
||||
such
|
||||
no
|
||||
nor
|
||||
not
|
||||
only
|
||||
own
|
||||
same
|
||||
so
|
||||
than
|
||||
too
|
||||
very
|
||||
s
|
||||
t
|
||||
can
|
||||
will
|
||||
just
|
||||
don
|
||||
should
|
||||
now
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
i
|
||||
j
|
||||
k
|
||||
l
|
||||
m
|
||||
n
|
||||
o
|
||||
p
|
||||
q
|
||||
w
|
||||
r
|
||||
s
|
||||
t
|
||||
x
|
||||
y
|
||||
z
|
50
Blogger/api/ai/test.lua
Normal file
50
Blogger/api/ai/test.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local path = require("fs/vfs").ospath("home://aiws/blog-clustering")
|
||||
local gettext = loadfile(path.."/gettext.lua")()
|
||||
local cluster = loadfile(path.."/cluster.lua")()
|
||||
|
||||
local refresh = false
|
||||
|
||||
local file = "/home/mrsang/test.csv"
|
||||
if refresh then
|
||||
local data = gettext.get({publish=1})
|
||||
local documents = {}
|
||||
if data then
|
||||
local sw = gettext.stopwords("home://aiws/blog-clustering/stopwords.txt")
|
||||
for k,v in pairs(data) do
|
||||
local bag = cluster.bow(data[k].content, sw)
|
||||
documents[data[k].id] = bag
|
||||
end
|
||||
cluster.tfidf(documents)
|
||||
--local v = cluster.search("arm", documents)
|
||||
--echo(JSON.encode(v))
|
||||
local vectors, maxv, size = cluster.get_vectors(documents)
|
||||
local s = cluster.save_topchart(vectors,file, 3)
|
||||
if s then echo("file saved") else echo("error save file") end
|
||||
--echo(JSON.encode(r))
|
||||
--r = cluster.similarity(vectors["14"],vectors["16"])
|
||||
--echo("Similarity "..r)
|
||||
|
||||
--local c,l = cluster.kmean(3, documents, 10)
|
||||
--echo(JSON.encode(c))
|
||||
--echo(JSON.encode(l))
|
||||
else
|
||||
echo("Data missing")
|
||||
end
|
||||
else
|
||||
local f = io.open(file,"r")
|
||||
local result = {}
|
||||
for line in f:lines() do
|
||||
local arr = {}
|
||||
local cnt = 0
|
||||
for i in line:gmatch( "%S+") do
|
||||
cnt = cnt + 1
|
||||
arr[cnt] = i
|
||||
end
|
||||
if not result[arr[1]] then result[arr[1]] = {} end
|
||||
result[arr[1]][arr[2]] = tonumber(arr[3])
|
||||
end
|
||||
f:close()
|
||||
echo(JSON.encode(result))
|
||||
--local r = cluster.top_similarity("2",vectors, 3)
|
||||
--echo(JSON.encode(r))
|
||||
end
|
72
Blogger/api/sendmail.lua
Normal file
72
Blogger/api/sendmail.lua
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
local data = ...
|
||||
|
||||
|
||||
-- Michal Kottman, 2011, public domain
|
||||
local socket = require 'socket'
|
||||
local smtp = require 'socket.smtp'
|
||||
local ssl = require 'ssl'
|
||||
local https = require 'ssl.https'
|
||||
local ltn12 = require 'ltn12'
|
||||
|
||||
function sslCreate()
|
||||
local sock = socket.tcp()
|
||||
return setmetatable({
|
||||
connect = function(_, host, port)
|
||||
local r, e = sock:connect(host, port)
|
||||
if not r then return r, e end
|
||||
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1_2'})
|
||||
return sock:dohandshake()
|
||||
end
|
||||
}, {
|
||||
__index = function(t,n)
|
||||
return function(_, ...)
|
||||
return sock[n](sock, ...)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function sendMail(user, password, to,subject, body)
|
||||
local msg = {
|
||||
headers = {
|
||||
from = string.format("%s <%s@iohub.dev>", user, user),
|
||||
to = string.format("%s <%s>",to.text, to.email),
|
||||
subject = subject
|
||||
},
|
||||
body = body
|
||||
}
|
||||
|
||||
local ok, err = smtp.send {
|
||||
from = string.format('<%s@iohub.dev>', user),
|
||||
rcpt = string.format('<%s>', to.email),
|
||||
source = smtp.message(msg),
|
||||
user = string.format('%s@iohub.dev', user),
|
||||
password = password,
|
||||
server = 'iohub.dev',
|
||||
port = 465,
|
||||
create = sslCreate
|
||||
}
|
||||
if not ok then
|
||||
return false, error
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local error_msg = {}
|
||||
local iserror = false
|
||||
|
||||
for k,v in pairs(data.to) do
|
||||
LOG_DEBUG("Send email to:"..v.email)
|
||||
local r,e = sendMail(data.user, data.password, v, data.title, data.content)
|
||||
if not r then
|
||||
iserror = true
|
||||
table.insert(error_msg, v.email)
|
||||
LOG_ERROR(string.format("Unable to send mail to %s: %s",v.email, e))
|
||||
end
|
||||
end
|
||||
local result = {}
|
||||
result.error = iserror
|
||||
result.result = error_msg
|
||||
return result
|
112
Blogger/build.json
Normal file
112
Blogger/build.json
Normal file
@ -0,0 +1,112 @@
|
||||
{
|
||||
"name": "Blogger",
|
||||
"targets": {
|
||||
"init": {
|
||||
"jobs": [
|
||||
{
|
||||
"name": "vfs-mkdir",
|
||||
"data": [
|
||||
"build",
|
||||
"build/debug",
|
||||
"build/release"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"ts": {
|
||||
"require": [
|
||||
"ts"
|
||||
],
|
||||
"jobs": [
|
||||
{
|
||||
"name": "ts-antos-sdk",
|
||||
"data": {
|
||||
"version": "2.0.x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ts-compile",
|
||||
"data": {
|
||||
"src": [
|
||||
"main.ts",
|
||||
"dialogs.ts",
|
||||
"tags.ts"
|
||||
],
|
||||
"dest": "build/debug/main.js"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"uglify": {
|
||||
"require": [
|
||||
"terser"
|
||||
],
|
||||
"jobs": [
|
||||
{
|
||||
"name": "terser-uglify",
|
||||
"data": [
|
||||
"build/debug/main.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"copy": {
|
||||
"jobs": [
|
||||
{
|
||||
"name": "vfs-cp",
|
||||
"data": {
|
||||
"src": [
|
||||
"scheme.html",
|
||||
"api",
|
||||
"package.json",
|
||||
"README.md",
|
||||
"main.css"
|
||||
],
|
||||
"dest": "build/debug"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"locale": {
|
||||
"require": ["locale"],
|
||||
"jobs": [
|
||||
{
|
||||
"name":"locale-gen",
|
||||
"data": {
|
||||
"src": "",
|
||||
"exclude": ["build/", "api/"],
|
||||
"locale": "en_GB",
|
||||
"dest": "package.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"debug": {
|
||||
"depend": [
|
||||
"init",
|
||||
"ts",
|
||||
"copy"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"require": [
|
||||
"zip"
|
||||
],
|
||||
"depend": [
|
||||
"init",
|
||||
"ts",
|
||||
"uglify",
|
||||
"copy"
|
||||
],
|
||||
"jobs": [
|
||||
{
|
||||
"name": "zip-mk",
|
||||
"data": {
|
||||
"src": "build/debug",
|
||||
"dest": "build/release/Blogger.zip"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
27
Blogger/build/debug/README.md
Normal file
27
Blogger/build/debug/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Blogger
|
||||
|
||||
Blackend for my blog at https://blog.iohub.dev
|
||||
|
||||
|
||||
## Change logs
|
||||
|
||||
### v0.2.x-a
|
||||
* Patch 13: fix bug on blog save
|
||||
* Patch 12: support send mail via SSL
|
||||
* Patch 11: Add TFIDF analyse functionality
|
||||
* Patch 10: Migrate code to typescript, use SQLiteDB lib for database access
|
||||
* Patch 9: Update to use the new MDE library
|
||||
* Patch 8: Support for antOS 2.0.x
|
||||
* Patch 7: Fix sendmail API security bug
|
||||
* Patch 6: Chage libraries load order
|
||||
* Patch 5: Add user photo to portfolio
|
||||
* Patch 4: Add package dependencies
|
||||
* Patch 3: Correct JSON text decoding
|
||||
* Patch 2: Bug fix rendering content
|
||||
* Patch 0-1 Important change: Store raw post content to the database instead of base64 string as before
|
||||
|
||||
### v0.1.x-a
|
||||
* Patch 3-4: Enhance youtube video embedding feature in markdown
|
||||
* Patch 2: CV Category now can be created when database is not created yet
|
||||
* Patch 1: Fix package archive broken
|
||||
* Patch 0: Change default email of the sender
|
83
Blogger/build/debug/api/ai/analyse.lua
Normal file
83
Blogger/build/debug/api/ai/analyse.lua
Normal file
@ -0,0 +1,83 @@
|
||||
local args = ...
|
||||
|
||||
local ret = {
|
||||
error = false,
|
||||
result = nil
|
||||
}
|
||||
local __dir__ = debug.getinfo(1).source:match("@?(.*/)")
|
||||
LOG_DEBUG("CURRENT PATH:%s", __dir__)
|
||||
local cluster = loadfile(__dir__.."/cluster.lua")()
|
||||
local dbpath = require("vfs").ospath(args.dbpath)
|
||||
LOG_DEBUG("DB PATH:%s", dbpath)
|
||||
|
||||
local gettext = {}
|
||||
gettext.get = function(file)
|
||||
local db = DBModel:new{db=file}
|
||||
db:open()
|
||||
if not db then return nil end
|
||||
local data, sort = db:find("blogs", {
|
||||
where = { publish = 1 },
|
||||
fields = {"id", "content"}
|
||||
})
|
||||
db:close()
|
||||
if not data or #data == 0 then return nil end
|
||||
return data
|
||||
end
|
||||
|
||||
gettext.stopwords = function(ospath)
|
||||
local words = {}
|
||||
for line in io.lines(ospath) do
|
||||
words[line] = true
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
local data = gettext.get(dbpath)
|
||||
local documents = {}
|
||||
if data then
|
||||
local sw = gettext.stopwords(__dir__.."/stopwords.txt")
|
||||
for k, v in pairs(data) do
|
||||
local bag = cluster.bow(data[k].content, sw)
|
||||
documents[data[k].id] = bag
|
||||
end
|
||||
|
||||
cluster.tfidf(documents)
|
||||
-- indexing all terms to cache file
|
||||
local cache_file = dbpath..".index.json"
|
||||
local f = io.open(cache_file, "w")
|
||||
if f then
|
||||
local indexes = {}
|
||||
for id, doc in pairs(documents) do
|
||||
for term,v in pairs(doc) do
|
||||
if not indexes[term] then
|
||||
indexes[term] = {}
|
||||
end
|
||||
indexes[term][tostring(id)] = doc[term].tfidf
|
||||
end
|
||||
end
|
||||
f:write(JSON.encode(indexes))
|
||||
f:close()
|
||||
end
|
||||
--
|
||||
--local v = cluster.search("arm", documents)
|
||||
--echo(JSON.encode(v))
|
||||
local vectors, maxv, size = cluster.get_vectors(documents)
|
||||
local analytical = DBModel:new{db=dbpath}
|
||||
analytical:open()
|
||||
-- purge the table
|
||||
analytical:delete("st_similarity", nil)
|
||||
-- get similarity and put to the table
|
||||
for id, v in pairs(vectors) do
|
||||
local top = cluster.top_similarity(id, vectors, args.top, 0.1)
|
||||
for a, b in pairs(top) do
|
||||
local record = {pid = id, sid = a, score = b}
|
||||
analytical:insert("st_similarity", record)
|
||||
end
|
||||
end
|
||||
analytical:close()
|
||||
ret.result = "Analyse complete"
|
||||
else
|
||||
ret.error = "Unable to query database for post"
|
||||
end
|
||||
|
||||
return ret
|
346
Blogger/build/debug/api/ai/cluster.lua
Normal file
346
Blogger/build/debug/api/ai/cluster.lua
Normal file
@ -0,0 +1,346 @@
|
||||
local doclassify = {}
|
||||
local st = require("stmr")
|
||||
doclassify.bow = function(data, stopwords)
|
||||
-- first step get a table of worlds that contain
|
||||
-- world: occurences
|
||||
local bag = {}
|
||||
for w in data:gmatch('%w+') do
|
||||
local word = w:lower()
|
||||
if not stopwords[word] then
|
||||
word = st.stmr(word)
|
||||
if bag[word] then
|
||||
bag[word].count = bag[word].count + 1
|
||||
else
|
||||
bag[word] = {count=0, tf=0, tfidf=0.0}
|
||||
bag[word].count = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
-- now calculate the tf of the bag
|
||||
for k,v in pairs(bag) do
|
||||
bag[k].tf = math.log(1 + bag[k].count)
|
||||
end
|
||||
return bag
|
||||
end
|
||||
doclassify.len = function(table)
|
||||
local cnt = 0
|
||||
for k,v in pairs(table) do cnt = cnt+1 end
|
||||
return cnt
|
||||
end
|
||||
doclassify.tfidf = function(documents)
|
||||
-- now for each term in a bag, calculate
|
||||
-- the inverse document frequency, which
|
||||
-- is a measure of how much information
|
||||
-- the word provides, that is, whether the
|
||||
-- term is common or rare across all documents
|
||||
local ndoc = doclassify.len(documents)
|
||||
for k,bag in pairs(documents) do
|
||||
-- for eacht term in bag
|
||||
-- calculate its idf across all documents
|
||||
for term,b in pairs(bag) do
|
||||
local n = 0
|
||||
for id,doc in pairs(documents) do
|
||||
if doc[term] then n = n+1 end
|
||||
end
|
||||
--echo("term:"..term.." appears in"..n.." documents")
|
||||
b.tfidf = b.tf*math.log(ndoc/n)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
doclassify.search = function(term, documents)
|
||||
local r = {}
|
||||
for id, doc in pairs(documents) do
|
||||
if doc[term:lower()] then
|
||||
r[id] = doc[term].tfidf
|
||||
end
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
doclassify.get_vectors = function(documents)
|
||||
-- get a list of vector from documents
|
||||
local index = 0
|
||||
local vectors = {}
|
||||
local maps = {}
|
||||
local terms = {}
|
||||
local maxv = 0
|
||||
|
||||
for id in pairs(documents) do
|
||||
maps[id] = {}
|
||||
vectors[id] = {}
|
||||
end
|
||||
-- first loop, get the term
|
||||
for id, doc in pairs(documents) do
|
||||
for k,v in pairs(doc) do
|
||||
-- get max value
|
||||
if v.tfidf > maxv then
|
||||
maxv = v.tfidf
|
||||
end
|
||||
-- get the term
|
||||
if not terms[k] then
|
||||
index = index + 1
|
||||
terms[k] = index
|
||||
end
|
||||
for pid in pairs(documents) do
|
||||
if not maps[pid][k] then
|
||||
if id == pid then
|
||||
maps[pid][k] = v.tfidf
|
||||
else
|
||||
maps[pid][k] = 0
|
||||
end
|
||||
else
|
||||
if maps[pid][k] == 0 and id == pid then
|
||||
maps[pid][k] = v.tfidf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- reindexing the vectors
|
||||
for id in pairs(documents) do
|
||||
for k,v in pairs(maps[id]) do
|
||||
vectors[id][terms[k]] = v
|
||||
end
|
||||
end
|
||||
--echo("Max tfidf "..maxv.." in document #"..maxid.." of term "..term)
|
||||
return vectors, maxv, index, terms
|
||||
end
|
||||
|
||||
doclassify.similarity = function(va, vb)
|
||||
-- using cosin similarity
|
||||
local dotp = 0
|
||||
local maga = 0
|
||||
local magb = 0
|
||||
for k = 1,#va do
|
||||
dotp = dotp + va[k]*vb[k]
|
||||
maga = maga + va[k]*va[k]
|
||||
magb = magb + vb[k]*vb[k]
|
||||
end
|
||||
maga = math.sqrt(maga)
|
||||
magb = math.sqrt(magb)
|
||||
local d = 0
|
||||
if maga ~= 0 and magb ~= 0 then
|
||||
d = dotp/ (magb*maga)
|
||||
end
|
||||
return d
|
||||
end
|
||||
doclassify.similarities = function(v1, collection)
|
||||
local similarities = {}
|
||||
assert(#v1 == #(collection[1]), "Incorrect vectors size")
|
||||
for i=1,#collection do
|
||||
similarities[i] = doclassify.similarity(v1, collection[i])
|
||||
end
|
||||
return similarities
|
||||
end
|
||||
|
||||
doclassify.mean_similarity = function(v1, v2)
|
||||
assert(#v1 == #v2, "Incorrect vectors size")
|
||||
local similarities = {}
|
||||
for i = 1,#v1 do similarities[i] = doclassify.similarity(v1[i], v2[i]) end
|
||||
return doclassify.mean(similarities)
|
||||
end
|
||||
doclassify.similarity_chart = function(id, vectors)
|
||||
local vs = {}
|
||||
local cnt = 0
|
||||
local lut = {}
|
||||
for k,v in pairs(vectors) do
|
||||
if k ~= id then
|
||||
cnt = cnt + 1
|
||||
vs[cnt] = v
|
||||
lut[cnt] = k
|
||||
end
|
||||
end
|
||||
if not vs[1] then return {} end
|
||||
return doclassify.similarities(vectors[id], vs), lut
|
||||
end
|
||||
|
||||
doclassify.top_similarity = function(id, vectors, n, th)
|
||||
local chart,lut = doclassify.similarity_chart(id,vectors)
|
||||
--echo(JSON.encode(chart))
|
||||
--echo(JSON.encode(lut))
|
||||
if not lut or #lut <= 0 then return nil end
|
||||
local top = {}
|
||||
|
||||
local j=0
|
||||
local goon = true
|
||||
if not th then
|
||||
goon = false
|
||||
th = 0
|
||||
end
|
||||
|
||||
while j < n or goon
|
||||
do
|
||||
local i,maxv = doclassify.argmax(chart)
|
||||
top[lut[i]] = maxv
|
||||
chart[i] = 0.0
|
||||
j=j+1
|
||||
if maxv < th and goon then
|
||||
goon = false
|
||||
end
|
||||
end
|
||||
|
||||
--for j=1,n do
|
||||
-- local i,maxv = doclassify.argmax(chart)
|
||||
-- top[lut[i]] = maxv
|
||||
-- chart[i] = 0.0
|
||||
--end
|
||||
return top
|
||||
|
||||
end
|
||||
doclassify.save_vectors = function(vectors, name)
|
||||
local f = io.open(name,"w")
|
||||
if f == nil then return false end
|
||||
for id, v in pairs(vectors) do
|
||||
f:write(id)
|
||||
for i=1,#v do f:write(","..v[i]) end
|
||||
f:write("\n")
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
doclassify.save_topchart = function(vectors, name,n)
|
||||
local f = io.open(name,"w")
|
||||
if f == nil then return false end
|
||||
for k,v in pairs(vectors) do
|
||||
local top = doclassify.top_similarity(k,vectors,n, 0.1)
|
||||
for a,b in pairs(top) do
|
||||
f:write(k.." "..a.." "..b.."\n")
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
doclassify.kmean = function(nclass, documents, maxstep, ids)
|
||||
-- now
|
||||
local vectors, maxv, size = doclassify.get_vectors(documents)
|
||||
-- random centroids
|
||||
local centroids = {}
|
||||
local old_centroids = {}
|
||||
local clusters = {}
|
||||
--for pid in pairs(documents) do clusters[pid] = 0 end
|
||||
-- add noise to mean_vector
|
||||
for i = 1,nclass do
|
||||
if ids == nil then
|
||||
centroids[i] = doclassify.random(size,math.floor(maxv))
|
||||
else
|
||||
centroids[i] = vectors[ids[i]]
|
||||
end
|
||||
old_centroids[i] = doclassify.zeros(size)
|
||||
end
|
||||
|
||||
-- loop until convergence or maxstep reached
|
||||
local similarity = doclassify.mean_similarity(centroids, old_centroids)
|
||||
local step = maxstep
|
||||
while 1.0-similarity > 1e-9 and step > 0 do
|
||||
clusters = {}
|
||||
--echo(JSON.encode(centroids))
|
||||
for id,v in pairs(vectors) do
|
||||
local similarities = doclassify.similarities(v, centroids)
|
||||
--echo(JSON.encode(similarities))
|
||||
local cluster, maxvalue = doclassify.argmax(similarities)
|
||||
--echo("doc #"..id.." is in clusters #"..cluster.." max value is "..maxvalue)
|
||||
clusters[id] = cluster
|
||||
end
|
||||
-- storing the old centroids
|
||||
old_centroids = centroids
|
||||
-- calculate new centroids
|
||||
local new_centroids = {}
|
||||
for class in pairs(centroids) do
|
||||
local cnt = 0
|
||||
local cvectors = {}
|
||||
for id,v in pairs(vectors) do
|
||||
if clusters[id] == class then
|
||||
cnt = cnt + 1
|
||||
cvectors[cnt] = v
|
||||
end
|
||||
end
|
||||
new_centroids[class] = doclassify.mean_vector(cvectors, size)
|
||||
end
|
||||
centroids = new_centroids
|
||||
--echo(JSON.encode(centroids))
|
||||
--echo(JSON.encode(old_centroids))
|
||||
similarity = doclassify.mean_similarity(centroids, old_centroids)
|
||||
echo("step #"..step..", similarity "..similarity)
|
||||
step = step - 1
|
||||
end
|
||||
local results = {}
|
||||
for i = 1,nclass do
|
||||
local list = {}
|
||||
local cnt = 0
|
||||
for id,c in pairs(clusters) do
|
||||
if c == i then
|
||||
cnt = cnt + 1
|
||||
list[cnt] = id
|
||||
end
|
||||
end
|
||||
results[i] = list
|
||||
end
|
||||
return results, clusters, centroids
|
||||
end
|
||||
|
||||
doclassify.zeros = function(n)
|
||||
local vector = {}
|
||||
for i = 1,n do vector[i] = 0.0 end
|
||||
return vector
|
||||
end
|
||||
|
||||
doclassify.random = function(n,maxv)
|
||||
local vector = {}
|
||||
for i=1,n do
|
||||
vector[i] = math.random() + math.random(0, maxv)
|
||||
end
|
||||
return vector
|
||||
end
|
||||
|
||||
doclassify.sum = function(v)
|
||||
local sum = 0.0
|
||||
for i=1,#v do sum = sum + v[i] end
|
||||
return sum
|
||||
end
|
||||
|
||||
doclassify.mean = function(v)
|
||||
return doclassify.sum(v)/#v
|
||||
|
||||
end
|
||||
|
||||
doclassify.mean_vector = function(vectors, size)
|
||||
local means = doclassify.zeros(size)
|
||||
if not vectors or #vectors == 0 then return means end
|
||||
--local size = #(vectors[1])
|
||||
local times = 0
|
||||
for k,v in pairs(vectors) do
|
||||
for i=1,#v do means[i] = means[i] + v[i] end
|
||||
times = times + 1
|
||||
end
|
||||
for i = 1,size do means[i] = means[i]/times end
|
||||
return means
|
||||
end
|
||||
|
||||
doclassify.argmin = function(v)
|
||||
local minv = 0.0
|
||||
local mini = 0.0
|
||||
for i = 1,#v do
|
||||
if v[i] <= minv then
|
||||
mini = i
|
||||
minv = v[i]
|
||||
end
|
||||
end
|
||||
--echo("min index"..mini.." val "..minv)
|
||||
return mini, minv
|
||||
end
|
||||
|
||||
doclassify.argmax = function(v)
|
||||
local maxv = 0.0
|
||||
local maxi = 0.0
|
||||
for i = 1,#v do
|
||||
if v[i] >= maxv then
|
||||
maxi = i
|
||||
maxv = v[i]
|
||||
end
|
||||
end
|
||||
return maxi,maxv
|
||||
end
|
||||
|
||||
return doclassify
|
151
Blogger/build/debug/api/ai/stopwords.txt
Normal file
151
Blogger/build/debug/api/ai/stopwords.txt
Normal file
@ -0,0 +1,151 @@
|
||||
i
|
||||
me
|
||||
my
|
||||
myself
|
||||
we
|
||||
our
|
||||
ours
|
||||
ourselves
|
||||
you
|
||||
your
|
||||
yours
|
||||
yourself
|
||||
yourselves
|
||||
he
|
||||
him
|
||||
his
|
||||
himself
|
||||
she
|
||||
her
|
||||
hers
|
||||
herself
|
||||
it
|
||||
its
|
||||
itself
|
||||
they
|
||||
them
|
||||
their
|
||||
theirs
|
||||
themselves
|
||||
what
|
||||
which
|
||||
who
|
||||
whom
|
||||
this
|
||||
that
|
||||
these
|
||||
those
|
||||
am
|
||||
is
|
||||
are
|
||||
was
|
||||
were
|
||||
be
|
||||
been
|
||||
being
|
||||
have
|
||||
has
|
||||
had
|
||||
having
|
||||
do
|
||||
does
|
||||
did
|
||||
doing
|
||||
a
|
||||
an
|
||||
the
|
||||
and
|
||||
but
|
||||
if
|
||||
or
|
||||
because
|
||||
as
|
||||
until
|
||||
while
|
||||
of
|
||||
at
|
||||
by
|
||||
for
|
||||
with
|
||||
about
|
||||
against
|
||||
between
|
||||
into
|
||||
through
|
||||
during
|
||||
before
|
||||
after
|
||||
above
|
||||
below
|
||||
to
|
||||
from
|
||||
up
|
||||
down
|
||||
in
|
||||
out
|
||||
on
|
||||
off
|
||||
over
|
||||
under
|
||||
again
|
||||
further
|
||||
then
|
||||
once
|
||||
here
|
||||
there
|
||||
when
|
||||
where
|
||||
why
|
||||
how
|
||||
all
|
||||
any
|
||||
both
|
||||
each
|
||||
few
|
||||
more
|
||||
most
|
||||
other
|
||||
some
|
||||
such
|
||||
no
|
||||
nor
|
||||
not
|
||||
only
|
||||
own
|
||||
same
|
||||
so
|
||||
than
|
||||
too
|
||||
very
|
||||
s
|
||||
t
|
||||
can
|
||||
will
|
||||
just
|
||||
don
|
||||
should
|
||||
now
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
i
|
||||
j
|
||||
k
|
||||
l
|
||||
m
|
||||
n
|
||||
o
|
||||
p
|
||||
q
|
||||
w
|
||||
r
|
||||
s
|
||||
t
|
||||
x
|
||||
y
|
||||
z
|
50
Blogger/build/debug/api/ai/test.lua
Normal file
50
Blogger/build/debug/api/ai/test.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local path = require("fs/vfs").ospath("home://aiws/blog-clustering")
|
||||
local gettext = loadfile(path.."/gettext.lua")()
|
||||
local cluster = loadfile(path.."/cluster.lua")()
|
||||
|
||||
local refresh = false
|
||||
|
||||
local file = "/home/mrsang/test.csv"
|
||||
if refresh then
|
||||
local data = gettext.get({publish=1})
|
||||
local documents = {}
|
||||
if data then
|
||||
local sw = gettext.stopwords("home://aiws/blog-clustering/stopwords.txt")
|
||||
for k,v in pairs(data) do
|
||||
local bag = cluster.bow(data[k].content, sw)
|
||||
documents[data[k].id] = bag
|
||||
end
|
||||
cluster.tfidf(documents)
|
||||
--local v = cluster.search("arm", documents)
|
||||
--echo(JSON.encode(v))
|
||||
local vectors, maxv, size = cluster.get_vectors(documents)
|
||||
local s = cluster.save_topchart(vectors,file, 3)
|
||||
if s then echo("file saved") else echo("error save file") end
|
||||
--echo(JSON.encode(r))
|
||||
--r = cluster.similarity(vectors["14"],vectors["16"])
|
||||
--echo("Similarity "..r)
|
||||
|
||||
--local c,l = cluster.kmean(3, documents, 10)
|
||||
--echo(JSON.encode(c))
|
||||
--echo(JSON.encode(l))
|
||||
else
|
||||
echo("Data missing")
|
||||
end
|
||||
else
|
||||
local f = io.open(file,"r")
|
||||
local result = {}
|
||||
for line in f:lines() do
|
||||
local arr = {}
|
||||
local cnt = 0
|
||||
for i in line:gmatch( "%S+") do
|
||||
cnt = cnt + 1
|
||||
arr[cnt] = i
|
||||
end
|
||||
if not result[arr[1]] then result[arr[1]] = {} end
|
||||
result[arr[1]][arr[2]] = tonumber(arr[3])
|
||||
end
|
||||
f:close()
|
||||
echo(JSON.encode(result))
|
||||
--local r = cluster.top_similarity("2",vectors, 3)
|
||||
--echo(JSON.encode(r))
|
||||
end
|
72
Blogger/build/debug/api/sendmail.lua
Normal file
72
Blogger/build/debug/api/sendmail.lua
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
local data = ...
|
||||
|
||||
|
||||
-- Michal Kottman, 2011, public domain
|
||||
local socket = require 'socket'
|
||||
local smtp = require 'socket.smtp'
|
||||
local ssl = require 'ssl'
|
||||
local https = require 'ssl.https'
|
||||
local ltn12 = require 'ltn12'
|
||||
|
||||
function sslCreate()
|
||||
local sock = socket.tcp()
|
||||
return setmetatable({
|
||||
connect = function(_, host, port)
|
||||
local r, e = sock:connect(host, port)
|
||||
if not r then return r, e end
|
||||
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1_2'})
|
||||
return sock:dohandshake()
|
||||
end
|
||||
}, {
|
||||
__index = function(t,n)
|
||||
return function(_, ...)
|
||||
return sock[n](sock, ...)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function sendMail(user, password, to,subject, body)
|
||||
local msg = {
|
||||
headers = {
|
||||
from = string.format("%s <%s@iohub.dev>", user, user),
|
||||
to = string.format("%s <%s>",to.text, to.email),
|
||||
subject = subject
|
||||
},
|
||||
body = body
|
||||
}
|
||||
|
||||
local ok, err = smtp.send {
|
||||
from = string.format('<%s@iohub.dev>', user),
|
||||
rcpt = string.format('<%s>', to.email),
|
||||
source = smtp.message(msg),
|
||||
user = string.format('%s@iohub.dev', user),
|
||||
password = password,
|
||||
server = 'iohub.dev',
|
||||
port = 465,
|
||||
create = sslCreate
|
||||
}
|
||||
if not ok then
|
||||
return false, error
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local error_msg = {}
|
||||
local iserror = false
|
||||
|
||||
for k,v in pairs(data.to) do
|
||||
LOG_DEBUG("Send email to:"..v.email)
|
||||
local r,e = sendMail(data.user, data.password, v, data.title, data.content)
|
||||
if not r then
|
||||
iserror = true
|
||||
table.insert(error_msg, v.email)
|
||||
LOG_ERROR(string.format("Unable to send mail to %s: %s",v.email, e))
|
||||
end
|
||||
end
|
||||
local result = {}
|
||||
result.error = iserror
|
||||
result.result = error_msg
|
||||
return result
|
78
Blogger/build/debug/main.css
Normal file
78
Blogger/build/debug/main.css
Normal file
@ -0,0 +1,78 @@
|
||||
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="user-container"] afx-label i.label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
afx-app-window .lbl-header i.label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="cv-container"] .cat-header{
|
||||
border-bottom: 1px solid #cbcbcb;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] .cv-side-bar-btn
|
||||
{
|
||||
text-align: right;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > .list-container > ul .afx-cv-sec-title .label-text{
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item afx-label {
|
||||
display: block;
|
||||
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item p {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item .afx-cv-sec-period,
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item .afx-cv-sec-loc {
|
||||
text-align: right;
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item afx-cv-sec-content{
|
||||
text-align: justify;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul li.selected {
|
||||
border: 1px solid #116cd6;
|
||||
background-color: transparent;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .closable::before{
|
||||
content: "\f014";
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .period-end::before{
|
||||
content: "-";
|
||||
}
|
||||
|
||||
afx-app-window[data-id ='blogger-win'] .editor-toolbar{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul li afx-label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul .afx-blogpost-title .label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul .blog-dates .label-text{
|
||||
font-size: 10px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul li.selected {
|
||||
background-color: #116cd6;
|
||||
color:white;
|
||||
}
|
1
Blogger/build/debug/main.js
Normal file
1
Blogger/build/debug/main.js
Normal file
File diff suppressed because one or more lines are too long
98
Blogger/build/debug/package.json
Normal file
98
Blogger/build/debug/package.json
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"app": "Blogger",
|
||||
"name": "Blogging application",
|
||||
"description": "Backend manager for blogging",
|
||||
"info": {
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version": "0.2.13-a",
|
||||
"category": "Internet",
|
||||
"iconclass": "fa fa-book",
|
||||
"dependencies": [
|
||||
"SimpleMDE@2.18.0-r",
|
||||
"Katex@0.11.1-r",
|
||||
"SQLiteDB@0.1.0-a"
|
||||
],
|
||||
"mimes": [
|
||||
"none"
|
||||
],
|
||||
"locales": {
|
||||
"en_GB": {
|
||||
"Pick a parent": "Pick a parent",
|
||||
"Category name": "Category name",
|
||||
"Ok": "Ok",
|
||||
"Cancel": "Cancel",
|
||||
"Title": "Title",
|
||||
"Subtitle": "Subtitle",
|
||||
"Location": "Location",
|
||||
"From": "From",
|
||||
"Save": "Save",
|
||||
"Content": "Content",
|
||||
"IO Hub mail username/password": "IO Hub mail username/password",
|
||||
"Send": "Send",
|
||||
"Please select a parent category": "Please select a parent category",
|
||||
"Please enter category name": "Please enter category name",
|
||||
"Parent can not be the category itself": "Parent can not be the category itself",
|
||||
"Title or content must not be blank": "Title or content must not be blank",
|
||||
"No email selected": "No email selected",
|
||||
"Unable to send mail to: {0}": "Unable to send mail to: {0}",
|
||||
"Error sending mail: {0}": "Error sending mail: {0}",
|
||||
"Open/Create database": "Open/Create database",
|
||||
"Open/create new database": "Open/create new database",
|
||||
"Unable to init database file: {0}": "Unable to init database file: {0}",
|
||||
"Select image file": "Select image file",
|
||||
"Unable to get file": "Unable to get file",
|
||||
"Add category": "Add category",
|
||||
"cv-cat-add: {0}": "cv-cat-add: {0}",
|
||||
"Edit category": "Edit category",
|
||||
"cv-cat-edit: {0}": "cv-cat-edit: {0}",
|
||||
"Delete category": "Delete category",
|
||||
"Do you really want to delete: {0}?": "Do you really want to delete: {0}?",
|
||||
"cv-cat-del: {0}": "cv-cat-del: {0}",
|
||||
"Please select a category": "Please select a category",
|
||||
"New section entry for {0}": "New section entry for {0}",
|
||||
"cv-sec-add: {0}": "cv-sec-add: {0}",
|
||||
"Please select a section to move": "Please select a section to move",
|
||||
"Move to": "Move to",
|
||||
"cv-sec-move: {0}": "cv-sec-move: {0}",
|
||||
"Please select a section to edit": "Please select a section to edit",
|
||||
"Modify section entry": "Modify section entry",
|
||||
"cv-sec-edit: {0}": "cv-sec-edit: {0}",
|
||||
"Cannot delete the section: {0}": "Cannot delete the section: {0}",
|
||||
"New": "New",
|
||||
"Cannot export file for embedding to text": "Cannot export file for embedding to text",
|
||||
"Preview": "Preview",
|
||||
"Send mail": "Send mail",
|
||||
"No post selected": "No post selected",
|
||||
"Emails sent": "Emails sent",
|
||||
"Error sending mails: {0}": "Error sending mails: {0}",
|
||||
"No record found for ID {}": "No record found for ID {}",
|
||||
"Cannot fetch the entry content": "Cannot fetch the entry content",
|
||||
"Delete a post": "Delete a post",
|
||||
"Do you really want to delete this post ?": "Do you really want to delete this post ?",
|
||||
"Cannot fetch user data": "Cannot fetch user data",
|
||||
"Full name must be entered": "Full name must be entered",
|
||||
"User data updated": "User data updated",
|
||||
"Cannot save user data: {0}": "Cannot save user data: {0}",
|
||||
"Unable to load categories": "Unable to load categories",
|
||||
"Found {0} sections": "Found {0} sections",
|
||||
"Please insert a title in the text: beginning with heading": "Please insert a title in the text: beginning with heading",
|
||||
"Please enter tags": "Please enter tags",
|
||||
"Cannot save blog: {0}": "Cannot save blog: {0}",
|
||||
"No more record to load": "No more record to load",
|
||||
"Full name": "Full name",
|
||||
"Address": "Address",
|
||||
"Phone": "Phone",
|
||||
"Email": "Email",
|
||||
"Url": "Url",
|
||||
"Photo": "Photo",
|
||||
"Short biblio": "Short biblio",
|
||||
"Categories": "Categories",
|
||||
"Load more": "Load more",
|
||||
"Tags": "Tags",
|
||||
"Created: {0}": "Created: {0}",
|
||||
"Updated: {0}": "Updated: {0}"
|
||||
}
|
||||
}
|
||||
}
|
91
Blogger/build/debug/scheme.html
Normal file
91
Blogger/build/debug/scheme.html
Normal file
@ -0,0 +1,91 @@
|
||||
<afx-app-window data-id = "blogger-win" apptitle="Blogger" width="650" height="500">
|
||||
<afx-hbox padding="5">
|
||||
<afx-tab-container data-id = "tabcontainer" dir = "row" tabbarwidth= "40">
|
||||
|
||||
<afx-hbox data-id="user-container" data-height="100%" iconclass="fa fa-user-circle">
|
||||
<afx-vbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label data-width= "70" text = "__(Full name)"></afx-label>
|
||||
<input type = "text" name="fullname" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Address)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="address" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Phone)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="Phone" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Email)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="email" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Url)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="url" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Photo)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="photo" data-id="photo" readonly="readonly" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-label data-height = "30" text = "__(Short biblio)"></afx-label>
|
||||
<textarea name="shortbiblio" input-class = "user-input"></textarea>
|
||||
<afx-hbox data-height = "35" style="text-align: right;">
|
||||
<afx-button iconclass = "fa fa-save" data-id = "bt-user-save" text = "__(Save)"></afx-button>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-hbox>
|
||||
|
||||
<afx-hbox data-id="cv-container" data-height="100%" iconclass="fa fa-info-circle">
|
||||
<div data-width="5"></div>
|
||||
<afx-vbox data-width="150" min-width="100">
|
||||
<afx-label class="lbl-header" data-height = "23" text = "__(Categories)" iconclass = "fa fa-bars"></afx-label>
|
||||
<afx-tree-view data-id = "cv-list" ></afx-tree-view>
|
||||
<div data-height="35" class = "cv-side-bar-btn">
|
||||
<afx-button data-id = "cv-cat-add" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-del" text = "" iconclass = "fa fa-minus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-edit" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
</div>
|
||||
</afx-vbox>
|
||||
<afx-resizer data-width = "2"></afx-resizer>
|
||||
<afx-vbox>
|
||||
<afx-list-view data-id = "cv-sec-list" ></afx-list-view>
|
||||
<afx-hbox data-height="35" >
|
||||
<afx-label data-id = "cv-sec-status"></afx-label>
|
||||
<div class = "cv-side-bar-btn">
|
||||
<afx-button data-id = "cv-sec-add" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-sec-edit" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
<afx-button data-id = "cv-sec-move" text = "" iconclass = "fa fa-exchange"></afx-button>
|
||||
</div>
|
||||
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
|
||||
|
||||
<afx-hbox data-id = "blog-container" data-height="100%" iconclass="fa fa-book">
|
||||
<afx-vbox>
|
||||
<afx-list-view data-id = "blog-list" min-width="100" data-width="200"></afx-list-view>
|
||||
<afx-button data-id = "blog-load-more" text = "__(Load more)" iconclass_end = "bi bi-chevron-double-right" data-height="content"></afx-button>
|
||||
</afx-vbox>
|
||||
<afx-resizer data-width = "3"></afx-resizer>
|
||||
<afx-vbox>
|
||||
<div data-id = "editor-container">
|
||||
<textarea data-id="markarea" ></textarea>
|
||||
</div>
|
||||
<afx-label text = "__(Tags)" style="font-weight:bold;" data-height="25" ></afx-label>
|
||||
<afx-hbox data-height="25">
|
||||
<input type = "text" data-id = "input-tags" ></input>
|
||||
<div data-width="5"></div>
|
||||
<afx-switch data data-id = "blog-publish" data-width="30"></afx-switch>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
|
||||
<div data-height="5"></div>
|
||||
</afx-vbox>
|
||||
</afx-hbox>
|
||||
|
||||
</afx-tab-container>
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
BIN
Blogger/build/release/Blogger.zip
Normal file
BIN
Blogger/build/release/Blogger.zip
Normal file
Binary file not shown.
282
Blogger/dialogs.ts
Normal file
282
Blogger/dialogs.ts
Normal file
@ -0,0 +1,282 @@
|
||||
// Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
|
||||
|
||||
// AnTOS Web desktop is is licensed under the GNU General Public
|
||||
// License v3.0, see the LICENCE file for more information
|
||||
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
//along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
namespace OS {
|
||||
export namespace application {
|
||||
export namespace blogger {
|
||||
declare var EasyMDE;
|
||||
export class BloggerCategoryDialog extends OS.GUI.BasicDialog {
|
||||
private tree: OS.GUI.tag.TreeViewTag;
|
||||
private txtinput: HTMLInputElement;
|
||||
constructor() {
|
||||
super("BloggerCategoryDialog", BloggerCategoryDialog.scheme);
|
||||
}
|
||||
|
||||
main() {
|
||||
super.main();
|
||||
this.tree = this.find("tree") as OS.GUI.tag.TreeViewTag;
|
||||
this.txtinput = this.find("txtinput") as HTMLInputElement;
|
||||
|
||||
(this.find("bt-ok") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => {
|
||||
const sel = this.tree.selectedItem;
|
||||
if (!sel) { return this.notify(__("Please select a parent category")); }
|
||||
const seldata = sel.data;
|
||||
const val = this.txtinput.value;
|
||||
if ((val === "") && !this.data.selonly) { return this.notify(__("Please enter category name")); }
|
||||
if (this.data.cat && (this.data.cat.id === seldata.id)) { return this.notify(__("Parent can not be the category itself")); }
|
||||
if (this.handle) { this.handle({ p: seldata, value: val }); }
|
||||
return this.quit();
|
||||
};
|
||||
|
||||
(this.find("bt-cancel") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => {
|
||||
return this.quit();
|
||||
};
|
||||
if (this.data && this.data.tree) {
|
||||
if (this.data && this.data.cat) {
|
||||
let seldata: GenericObject<any>;
|
||||
this.txtinput.value = this.data.cat.name;
|
||||
if (this.data.cat.pid === "0") {
|
||||
seldata = this.data.tree;
|
||||
} else {
|
||||
seldata = this.findDataByID(this.data.cat.pid, this.data.tree.nodes);
|
||||
}
|
||||
if (seldata) { seldata.selected = true; }
|
||||
}
|
||||
this.tree.data = this.data.tree;
|
||||
return this.tree.expandAll();
|
||||
}
|
||||
}
|
||||
// TODO set selected category name
|
||||
|
||||
findDataByID(id: number, list: GenericObject<any>[]) {
|
||||
for (let data of list) {
|
||||
if (data.id === id) { return data; }
|
||||
if (data.nodes) {
|
||||
this.findDataByID(id, data.nodes);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
BloggerCategoryDialog.scheme = `\
|
||||
<afx-app-window width='300' height='400'>
|
||||
<afx-vbox padding="5">
|
||||
<afx-label text="__(Pick a parent)" data-height="25" class="lbl-header" ></afx-label>
|
||||
<afx-tree-view data-id="tree" ></afx-tree-view>
|
||||
<afx-label text="__(Category name)" data-height="25" class="lbl-header" ></afx-label>
|
||||
<input type="text" data-height="25" data-id = "txtinput"/ >
|
||||
<afx-hbox data-height = '35'>
|
||||
<div style=' text-align:right;'>
|
||||
<afx-button data-id = "bt-ok" text = "__(Ok)"></afx-button>
|
||||
<afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>
|
||||
</div>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-app-window>\
|
||||
`;
|
||||
|
||||
// This dialog is use for cv section editing
|
||||
|
||||
export class BloggerCVSectionDiaglog extends OS.GUI.BasicDialog {
|
||||
private editor: GenericObject<any>;
|
||||
constructor() {
|
||||
super("BloggerCVSectionDiaglog");
|
||||
}
|
||||
|
||||
main() {
|
||||
super.main();
|
||||
this.editor = new EasyMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
element: this.find("contentarea"),
|
||||
status: false,
|
||||
toolbar: false
|
||||
});
|
||||
($((this.select('[class = "CodeMirror-scroll"]'))[0])).css("min-height", "50px");
|
||||
($((this.select('[class="CodeMirror cm-s-paper CodeMirror-wrap"]'))[0])).css("min-height", "50px");
|
||||
const inputs = this.select("[input-class='user-input']");
|
||||
if (this.data && this.data.section) { for (let v of inputs) { ($(v)).val(this.data.section[(v as HTMLInputElement).name]); } }
|
||||
if (this.data && this.data.section) { this.editor.value(this.data.section.content); }
|
||||
(this.find("section-publish") as OS.GUI.tag.SwitchTag).swon = (this.data && this.data.section && Number(this.data.section.publish) ? true : false);
|
||||
(this.find("bt-cv-sec-save") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => {
|
||||
const data: GenericObject<any> = {};
|
||||
for (let v of inputs) { data[(v as HTMLInputElement).name] = ($(v)).val(); }
|
||||
data.content = this.editor.value();
|
||||
if ((data.title === "") && (data.content === "")) { return this.notify(__("Title or content must not be blank")); }
|
||||
//return @notify "Content must not be blank" if data.content is ""
|
||||
if (this.data && this.data.section) { data.id = this.data.section.id; }
|
||||
const val = (this.find("section-publish") as OS.GUI.tag.SwitchTag).swon;
|
||||
if (val === true) {
|
||||
data.publish = 1;
|
||||
} else {
|
||||
data.publish = 0;
|
||||
}
|
||||
if (this.handle) { this.handle(data); }
|
||||
return this.quit();
|
||||
};
|
||||
|
||||
this.on("resize", () => this.resizeContent());
|
||||
return this.resizeContent();
|
||||
}
|
||||
|
||||
resizeContent() {
|
||||
const container = this.find("editor-container");
|
||||
const children = ($(".EasyMDEContainer", container)).children();
|
||||
const cheight = ($(container)).height() - 30;
|
||||
return ($(children[0])).css("height", cheight + "px");
|
||||
}
|
||||
}
|
||||
BloggerCVSectionDiaglog.scheme = `\
|
||||
<afx-app-window data-id = "blogger-cv-sec-win" apptitle="Porforlio section" width="450" height="400">
|
||||
<afx-vbox padding="5">
|
||||
<afx-hbox data-height = "30" >
|
||||
<afx-label data-width= "70" text = "__(Title)"></afx-label>
|
||||
<input type = "text" name="title" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30" >
|
||||
<afx-label text = "__(Subtitle)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="subtitle" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30" >
|
||||
<afx-label text = "__(Location)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="location" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30" >
|
||||
<afx-label text = "__(From)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="start" input-class = "user-input"></input>
|
||||
<afx-label text = "To:" style="text-align:center;" data-width= "70"></afx-label>
|
||||
<input type = "text" name="end" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-label data-height = "30" text = "Content" style = "margin-left:5px;"></afx-label>
|
||||
<div data-id="editor-container">
|
||||
<textarea name="content" data-id = "contentarea" ></textarea>
|
||||
</div>
|
||||
<div data-height = "35" style="text-align: right;">
|
||||
<afx-switch data-id = "section-publish" data-width="30"></afx-switch>
|
||||
<afx-button iconclass = "fa fa-save" data-id = "bt-cv-sec-save" text = "__(Save)"></afx-button>
|
||||
</div>
|
||||
</afx-vbox>
|
||||
</afx-app-window>`;
|
||||
|
||||
// this dialog is for send mail
|
||||
export class BloggerSendmailDiaglog extends OS.GUI.BasicDialog {
|
||||
static template: string;
|
||||
private maillinglist: OS.GUI.tag.StackMenuTag;
|
||||
// TODO: convert to SQLite handle
|
||||
private subdb: API.VFS.BaseFileHandle;
|
||||
constructor() {
|
||||
super("BloggerSendmailDiaglog");
|
||||
}
|
||||
|
||||
main() {
|
||||
super.main();
|
||||
this.maillinglist = this.find("email-list") as OS.GUI.tag.StackMenuTag;
|
||||
const title = (new RegExp("^#+(.*)\n", "g")).exec(this.data.content);
|
||||
(this.find("mail-title") as HTMLInputElement).value = title[1];
|
||||
const content = (this.data.content.substring(0, 500)) + "...";
|
||||
(this.find("contentarea") as HTMLTextAreaElement).value = BloggerSendmailDiaglog.template.format(this.data.id, content);
|
||||
const mlist = this.data.mails.map((el)=> {
|
||||
return {
|
||||
text: el.name,
|
||||
email: el.email,
|
||||
switch: true,
|
||||
checked: true
|
||||
}
|
||||
});
|
||||
console.log(mlist);
|
||||
this.maillinglist.items = mlist;
|
||||
|
||||
return (this.find("bt-sendmail") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => {
|
||||
const items = this.maillinglist.items;
|
||||
const emails = [];
|
||||
for (let v of items) {
|
||||
if (v.checked === true) {
|
||||
emails.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
if (emails.length === 0) { return this.notify(__("No email selected")); }
|
||||
// send the email
|
||||
const data = {
|
||||
path: `${this.meta().path}/api/sendmail.lua`,
|
||||
parameters: {
|
||||
to: emails,
|
||||
title: (this.find("mail-title") as HTMLInputElement).value,
|
||||
content: (this.find("contentarea") as HTMLTextAreaElement).value,
|
||||
user: (this.find("mail-user") as HTMLInputElement).value,
|
||||
password: (this.find("mail-password") as HTMLInputElement).value,
|
||||
}
|
||||
};
|
||||
return this._api.apigateway(data, false)
|
||||
.then((d) => {
|
||||
if (d.error) {
|
||||
const str = d.result.join(',');
|
||||
return this.notify(__("Unable to send mail to: {0}", str)); }
|
||||
return this.quit();
|
||||
}).catch((e) => {
|
||||
return this.error(__("Error sending mail: {0}", e.toString()), e);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
BloggerSendmailDiaglog.scheme = `\
|
||||
<afx-app-window data-id = "blogger-send-mail-win" apptitle="Send mail" width="600" height="400" resizable = "false">
|
||||
<afx-hbox padding="5">
|
||||
<afx-stack-menu data-width="200" data-id="email-list"></afx-stack-menu>
|
||||
<afx-resizer data-width="3"></afx-resizer>
|
||||
<afx-vbox >
|
||||
<afx-label data-height="20" text = "__(Title)"></afx-label>
|
||||
<input type = "text" data-height="25" name="title" data-id = "mail-title"></input>
|
||||
<afx-label data-height = "20" text = "__(Content)" ></afx-label>
|
||||
<textarea name="content" data-id = "contentarea" ></textarea>
|
||||
<afx-label data-height="20" text = "__(IO Hub mail username/password)"></afx-label>
|
||||
<afx-hbox data-height="25">
|
||||
<input type = "text" name="username" data-id = "mail-user"></input>
|
||||
<input type = "password" name="password" data-id = "mail-password"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<div></div>
|
||||
<afx-button iconclass = "fa fa-paper-plane" data-id = "bt-sendmail" data-width="content" text = "__(Send)"></afx-button>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-hbox>
|
||||
</afx-app-window>`;
|
||||
|
||||
|
||||
BloggerSendmailDiaglog.template = `\
|
||||
Hello,
|
||||
|
||||
Dany LE has just published a new post on his blog: https://blog.iohub.dev/post/id/{0}
|
||||
|
||||
==========
|
||||
{1}
|
||||
==========
|
||||
|
||||
|
||||
Read the full article via:
|
||||
https://blog.iohub.dev/post/id/{0}
|
||||
|
||||
You receive this email because you have been subscribed to his blog.
|
||||
|
||||
Have a nice day,
|
||||
|
||||
Sent from Blogger, an AntOS application\
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
78
Blogger/main.css
Normal file
78
Blogger/main.css
Normal file
@ -0,0 +1,78 @@
|
||||
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="user-container"] afx-label i.label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
afx-app-window .lbl-header i.label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="cv-container"] .cat-header{
|
||||
border-bottom: 1px solid #cbcbcb;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] .cv-side-bar-btn
|
||||
{
|
||||
text-align: right;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > .list-container > ul .afx-cv-sec-title .label-text{
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item afx-label {
|
||||
display: block;
|
||||
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item p {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item .afx-cv-sec-period,
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item .afx-cv-sec-loc {
|
||||
text-align: right;
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] afx-blogger-cvsection-item afx-cv-sec-content{
|
||||
text-align: justify;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul li.selected {
|
||||
border: 1px solid #116cd6;
|
||||
background-color: transparent;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .closable::before{
|
||||
content: "\f014";
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .period-end::before{
|
||||
content: "-";
|
||||
}
|
||||
|
||||
afx-app-window[data-id ='blogger-win'] .editor-toolbar{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul li afx-label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul .afx-blogpost-title .label-text{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul .blog-dates .label-text{
|
||||
font-size: 10px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "blog-list"] > div.list-container > ul li.selected {
|
||||
background-color: #116cd6;
|
||||
color:white;
|
||||
}
|
925
Blogger/main.ts
Normal file
925
Blogger/main.ts
Normal file
@ -0,0 +1,925 @@
|
||||
// Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
|
||||
|
||||
// AnTOS Web desktop is is licensed under the GNU General Public
|
||||
// License v3.0, see the LICENCE file for more information
|
||||
|
||||
// This program is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
//along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
namespace OS {
|
||||
export namespace application {
|
||||
declare function renderMathInElement(el: HTMLElement):void;
|
||||
declare var EasyMDE;
|
||||
export class Blogger extends BaseApplication {
|
||||
|
||||
private user: GenericObject<any>;
|
||||
private cvlist: GUI.tag.TreeViewTag;
|
||||
private inputtags: HTMLInputElement;
|
||||
private bloglist: GUI.tag.ListViewTag;
|
||||
private seclist: GUI.tag.ListViewTag;
|
||||
private tabcontainer: GUI.tag.TabContainerTag;
|
||||
private editor: GenericObject<any>;
|
||||
private previewOn: boolean;
|
||||
// datatbase objects
|
||||
private dbhandle: API.VFS.BaseFileHandle;
|
||||
// database handles
|
||||
private userdb: API.VFS.BaseFileHandle;
|
||||
private cvcatdb: API.VFS.BaseFileHandle;
|
||||
private cvsecdb: API.VFS.BaseFileHandle;
|
||||
private blogdb: API.VFS.BaseFileHandle;
|
||||
private subdb: API.VFS.BaseFileHandle;
|
||||
|
||||
private last_ctime: number;
|
||||
|
||||
constructor(args: any) {
|
||||
super("Blogger", args);
|
||||
this.previewOn = false;
|
||||
}
|
||||
|
||||
private async init_db() {
|
||||
try {
|
||||
const f = await this.openDialog("FileDialog",{
|
||||
title: __("Open/create new database"),
|
||||
file: "Untitled.db"
|
||||
});
|
||||
var d_1 = f.file.path.asFileHandle();
|
||||
if(f.file.type==="file") {
|
||||
d_1=d_1.parent();
|
||||
}
|
||||
const target=`${d_1.path}/${f.name}`.asFileHandle();
|
||||
this.dbhandle=`sqlite://${target.genealogy.join("/")}`.asFileHandle();
|
||||
const tables = await this.dbhandle.read();
|
||||
/**
|
||||
* Init following tables if not exist:
|
||||
* - user
|
||||
* - cvcat
|
||||
* - cvsec
|
||||
* - blogdb
|
||||
*/
|
||||
if(!tables.user)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
address: "TEXT",
|
||||
Phone: "TEXT",
|
||||
shortbiblio: "TEXT",
|
||||
fullname: "TEXT",
|
||||
email: "TEXT",url: "TEXT",
|
||||
photo: "TEXT"
|
||||
}
|
||||
const r = await this.dbhandle.write("user");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
if(!tables.cv_cat)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
publish: "NUMERIC",
|
||||
name: "TEXT",
|
||||
pid: "NUMERIC"
|
||||
}
|
||||
const r = await this.dbhandle.write("cv_cat");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
if(!tables.cv_sections)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
title: "TEXT",
|
||||
start: "NUMERIC",
|
||||
location: "TEXT",
|
||||
end: "NUMERIC",
|
||||
content: "TEXT",
|
||||
subtitle: "TEXT",
|
||||
publish: "NUMERIC",
|
||||
cid: "NUMERIC"
|
||||
}
|
||||
const r = await this.dbhandle.write("cv_sections");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
if(!tables.blogs)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
tags: "TEXT",
|
||||
content: "TEXT",
|
||||
utime: "NUMERIC",
|
||||
rendered: "TEXT",
|
||||
title: "TEXT",
|
||||
utimestr: "TEXT",
|
||||
ctime: "NUMERIC",
|
||||
ctimestr: "TEXT",
|
||||
publish: "INTEGER DEFAULT 0",
|
||||
}
|
||||
const r = await this.dbhandle.write("blogs");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
if(!tables.st_similarity)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
pid: "NUMERIC",
|
||||
sid: "NUMERIC",
|
||||
score: "NUMERIC"
|
||||
}
|
||||
const r = await this.dbhandle.write("st_similarity");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
if(!tables.subscribers)
|
||||
{
|
||||
this.dbhandle.cache = {
|
||||
name: "TEXT",
|
||||
email: "TEXT"
|
||||
}
|
||||
const r = await this.dbhandle.write("subscribers");
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
}
|
||||
this.userdb = `${this.dbhandle.path}@user`.asFileHandle();
|
||||
this.cvcatdb = `${this.dbhandle.path}@cv_cat`.asFileHandle();
|
||||
this.cvsecdb = `${this.dbhandle.path}@cv_sections`.asFileHandle();
|
||||
this.blogdb = `${this.dbhandle.path}@blogs`.asFileHandle();
|
||||
this.subdb = `${this.dbhandle.path}@subscribers`.asFileHandle();
|
||||
|
||||
this.last_ctime = 0;
|
||||
this.bloglist.data = [];
|
||||
this.loadBlogs();
|
||||
}
|
||||
catch(e) {
|
||||
this.error(__("Unable to init database file: {0}",e.toString()),e);
|
||||
this.dbhandle = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
menu() {
|
||||
return [
|
||||
{
|
||||
text: "__(Open/Create database)",
|
||||
onmenuselect: (e) => {
|
||||
this.init_db();
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
main() {
|
||||
this.user = {};
|
||||
this.cvlist = this.find("cv-list") as GUI.tag.TreeViewTag;
|
||||
this.cvlist.ontreeselect = (d) => {
|
||||
if (!d) { return; }
|
||||
const {
|
||||
data
|
||||
} = d.data.item;
|
||||
return this.CVSectionByCID(Number(data.id));
|
||||
};
|
||||
|
||||
this.inputtags = this.find("input-tags") as HTMLInputElement;
|
||||
this.bloglist = this.find("blog-list") as GUI.tag.ListViewTag;
|
||||
this.seclist = this.find("cv-sec-list") as GUI.tag.ListViewTag;
|
||||
|
||||
let el = this.find("photo") as HTMLInputElement;
|
||||
$(el)
|
||||
.on("click", async (e: any) => {
|
||||
try {
|
||||
const ret = await this.openDialog("FileDialog", {
|
||||
title: __("Select image file"),
|
||||
mimes: ["image/.*"]
|
||||
});
|
||||
return el.value = ret.file.path;
|
||||
} catch (e) {
|
||||
return this.error(__("Unable to get file"), e);
|
||||
}
|
||||
});
|
||||
|
||||
this.tabcontainer = this.find("tabcontainer") as GUI.tag.TabContainerTag;
|
||||
this.tabcontainer.ontabselect = (e) => {
|
||||
return this.fetchData((e.data.container as GUI.tag.TileLayoutTag).aid);
|
||||
};
|
||||
|
||||
(this.find("bt-user-save") as GUI.tag.ButtonTag).onbtclick = (e: any) => {
|
||||
return this.saveUser();
|
||||
};
|
||||
|
||||
(this.find("blog-load-more") as GUI.tag.ButtonTag).onbtclick = (e) => {
|
||||
this.loadBlogs();
|
||||
}
|
||||
|
||||
(this.find("cv-cat-add") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try {
|
||||
const tree = await this.fetchCVCat();
|
||||
const d = await this.openDialog(new blogger.BloggerCategoryDialog(), {
|
||||
title: __("Add category"),
|
||||
tree
|
||||
});
|
||||
this.cvcatdb.cache = {
|
||||
name: d.value,
|
||||
pid: d.p.id,
|
||||
publish: 1
|
||||
};
|
||||
const r = await this.cvcatdb.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.refreshCVCat();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-cat-add: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
(this.find("cv-cat-edit") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try {
|
||||
const sel = this.cvlist.selectedItem;
|
||||
if (!sel) { return; }
|
||||
const cat = sel.data;
|
||||
if (!cat) { return; }
|
||||
const tree = await this.fetchCVCat();
|
||||
const d = await this.openDialog(new blogger.BloggerCategoryDialog(), {
|
||||
title: __("Edit category"),
|
||||
tree, cat
|
||||
});
|
||||
const handle = cat.$vfs;
|
||||
handle.cache = {
|
||||
id: cat.id,
|
||||
publish: cat.publish,
|
||||
pid: d.p.id,
|
||||
name: d.value
|
||||
};
|
||||
|
||||
const r = await handle.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.refreshCVCat();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-cat-edit: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
(this.find("cv-cat-del") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try {
|
||||
const sel = this.cvlist.selectedItem;
|
||||
if (!sel) { return; }
|
||||
const cat = sel.data;
|
||||
if (!cat) { return; }
|
||||
const d = await this.openDialog("YesNoDialog", {
|
||||
title: __("Delete category"),
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete: {0}?", cat.name)
|
||||
});
|
||||
if (!d) { return; }
|
||||
await this.deleteCVCat(cat);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-cat-del: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
(this.find("cv-sec-add") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try
|
||||
{
|
||||
const sel = this.cvlist.selectedItem;
|
||||
if (!sel) { return; }
|
||||
const cat = sel.data;
|
||||
if (!cat || (cat.id === "0")) { return this.toast(__("Please select a category")); }
|
||||
const d = await this.openDialog(new blogger.BloggerCVSectionDiaglog(), {
|
||||
title: __("New section entry for {0}", cat.name)
|
||||
});
|
||||
d.cid = Number(cat.id);
|
||||
d.start = Number(d.start);
|
||||
d.end = Number(d.end);
|
||||
this.cvsecdb.cache = d;
|
||||
// d.publish = 1
|
||||
const r = await this.cvsecdb.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.CVSectionByCID(Number(cat.id));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-sec-add: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
(this.find("cv-sec-move") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try {
|
||||
const sel = this.seclist.selectedItem;
|
||||
if (!sel) { return this.toast(__("Please select a section to move")); }
|
||||
const sec = sel.data;
|
||||
const handle = sec.$vfs;
|
||||
console.log(handle);
|
||||
const tree = await this.fetchCVCat();
|
||||
const d = await this.openDialog(new blogger.BloggerCategoryDialog(), {
|
||||
title: __("Move to"),
|
||||
tree,
|
||||
selonly: true
|
||||
});
|
||||
handle.cache = {
|
||||
id: sec.id,
|
||||
cid: d.p.id
|
||||
};
|
||||
const r = await handle.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.CVSectionByCID(sec.cid);
|
||||
this.seclist.unselect();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-sec-move: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
(this.find("cv-sec-edit") as GUI.tag.ButtonTag).onbtclick = async (e: any) => {
|
||||
try {
|
||||
const sel = this.seclist.selectedItem;
|
||||
if (!sel) { return this.toast(__("Please select a section to edit")); }
|
||||
const sec = sel.data;
|
||||
const d = await this.openDialog(new blogger.BloggerCVSectionDiaglog(), {
|
||||
title: __("Modify section entry"),
|
||||
section: sec
|
||||
});
|
||||
d.cid = Number(sec.cid);
|
||||
d.start = Number(d.start);
|
||||
d.end = Number(d.end);
|
||||
|
||||
const handle = sec.$vfs;
|
||||
handle.cache = d;
|
||||
//d.publish = Number sec.publish
|
||||
const r = await handle.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.CVSectionByCID(Number(sec.cid));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("cv-sec-edit: {0}", e.toString()), e);
|
||||
}
|
||||
};
|
||||
|
||||
this.seclist.onitemclose = (evt) => {
|
||||
if (!evt) { return; }
|
||||
const data = evt.data.item.data;
|
||||
this.openDialog("YesNoDialog", {
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete: {0}?", data.title)
|
||||
}).then(async (b: any) => {
|
||||
if (!b) { return; }
|
||||
try {
|
||||
const r = await this.cvsecdb.remove({
|
||||
where: {
|
||||
id: data.id
|
||||
}
|
||||
});
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
return this.seclist.delete(evt.data.item);
|
||||
} catch(e) {
|
||||
return this.error(__("Cannot delete the section: {0}",e.toString()),e);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
this.editor = new EasyMDE({
|
||||
element: this.find("markarea"),
|
||||
autoDownloadFontAwesome: false,
|
||||
autofocus: true,
|
||||
tabSize: 4,
|
||||
indentWithTabs: true,
|
||||
toolbar: [
|
||||
{
|
||||
name: __("New"),
|
||||
className: "fa fa-file",
|
||||
action: (e: any) => {
|
||||
this.bloglist.unselect();
|
||||
return this.clearEditor();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: __("Save"),
|
||||
className: "fa fa-save",
|
||||
action: (e: any) => {
|
||||
return this.saveBlog();
|
||||
}
|
||||
}
|
||||
, "|", "bold", "italic", "heading", "|", "quote", "code",
|
||||
"unordered-list", "ordered-list", "|", "link",
|
||||
"image", "table", "horizontal-rule",
|
||||
{
|
||||
name: "image",
|
||||
className: "fa fa-file-image-o",
|
||||
action: (_) => {
|
||||
return this.openDialog("FileDialog", {
|
||||
title: __("Select image file"),
|
||||
mimes: ["image/.*"]
|
||||
}).then((d) => {
|
||||
return d.file.path.asFileHandle().publish()
|
||||
.then((r: { result: any; }) => {
|
||||
const doc = this.editor.codemirror.getDoc();
|
||||
return doc.replaceSelection(``);
|
||||
}).catch((e: any) => this.error(__("Cannot export file for embedding to text"), e));
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "Youtube",
|
||||
className: "fa fa-youtube",
|
||||
action: (e: any) => {
|
||||
const doc = this.editor.codemirror.getDoc();
|
||||
return doc.replaceSelection("[[youtube:]]");
|
||||
}
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: __("Preview"),
|
||||
className: "fa fa-eye no-disable",
|
||||
action: (e: any) => {
|
||||
this.previewOn = !this.previewOn;
|
||||
EasyMDE.togglePreview(e);
|
||||
///console.log @select ".editor-preview editor-preview-active"
|
||||
renderMathInElement(this.find("editor-container"));
|
||||
}
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: __("Send mail"),
|
||||
className: "fa fa-paper-plane",
|
||||
action: async (e: any) => {
|
||||
try {
|
||||
const d = await this.subdb.read();
|
||||
const sel = this.bloglist.selectedItem;
|
||||
if (!sel) { return this.error(__("No post selected")); }
|
||||
const data = sel.data;
|
||||
await this.openDialog(new blogger.BloggerSendmailDiaglog(), {
|
||||
title: __("Send mail"),
|
||||
content: this.editor.value(),
|
||||
mails: d,
|
||||
id: data.id
|
||||
});
|
||||
this.toast(__("Emails sent"));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("Error sending mails: {0}", e.toString()), e);
|
||||
}
|
||||
}
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: __("TFIDF analyse"),
|
||||
className: "fa fa-area-chart",
|
||||
action: async (e: any) => {
|
||||
try {
|
||||
const q = await this.openDialog("PromptDialog",{
|
||||
title: __("TFIDF Analyse"),
|
||||
text: __("Max number of related posts to keep per post?"),
|
||||
value: "5"
|
||||
});
|
||||
const data = {
|
||||
path: `${this.meta().path}/api/ai/analyse.lua`,
|
||||
parameters: {
|
||||
dbpath: this.dbhandle.info.file.path,
|
||||
top: parseInt(q)
|
||||
}
|
||||
};
|
||||
const d = await this._api.apigateway(data, false);
|
||||
if (d.error) {
|
||||
throw new Error(d.error);
|
||||
}
|
||||
this.toast(d.result);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("Error analysing posts: {0}", e.toString()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.bloglist.onlistselect = async (e: any) => {
|
||||
const el = this.bloglist.selectedItem;
|
||||
if (!el) { return; }
|
||||
const sel = el.data;
|
||||
if (!sel) { return; }
|
||||
try {
|
||||
const result=await this.blogdb.read({
|
||||
where: {
|
||||
id: Number(sel.id)
|
||||
}
|
||||
});
|
||||
if(!result || result.length == 0)
|
||||
{
|
||||
throw new Error(__("No record found for ID {}", sel.id).__());
|
||||
}
|
||||
const r = result[0];
|
||||
this.editor.value(r.content);
|
||||
this.inputtags.value=r.tags;
|
||||
return (this.find("blog-publish") as GUI.tag.SwitchTag).swon=Number(r.publish)? true:false;
|
||||
}
|
||||
catch(e_1) {
|
||||
return this.error(__("Cannot fetch the entry content"),e_1);
|
||||
}
|
||||
};
|
||||
|
||||
this.bloglist.onitemclose = (e) => {
|
||||
if (!e) { return; }
|
||||
const el = e.data.item;
|
||||
const data = el.data;
|
||||
this.openDialog("YesNoDialog", {
|
||||
title: __("Delete a post"),
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete this post ?")
|
||||
}).then(async (b: any) => {
|
||||
if (!b) { return; }
|
||||
const r = await this.blogdb.remove({
|
||||
where: {
|
||||
id: Number(data.id)
|
||||
}
|
||||
});
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
this.bloglist.delete(el);
|
||||
this.bloglist.unselect();
|
||||
return this.clearEditor();
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
this.bindKey("CTRL-S", () => {
|
||||
const sel = this.tabcontainer.selectedTab;
|
||||
if (!sel || ((sel.container as GUI.tag.TileLayoutTag).aid !== "blog-container")) { return; }
|
||||
return this.saveBlog();
|
||||
});
|
||||
this.on("resize", () => {
|
||||
return this.resizeContent();
|
||||
});
|
||||
|
||||
this.resizeContent();
|
||||
return this.init_db();
|
||||
}
|
||||
// @fetchData 0
|
||||
// USER TAB
|
||||
private fetchData(idx: any) {
|
||||
switch (idx) {
|
||||
case "user-container": //user info
|
||||
return this.userdb.read()
|
||||
.then((d) => {
|
||||
if(!d || d.length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.user = d[0];
|
||||
const inputs = this.select("[input-class='user-input']");
|
||||
return inputs.map((i,v) => ($(v)).val(this.user[(v as HTMLInputElement).name]));
|
||||
}).catch((e: any) => this.error(__("Cannot fetch user data"), e));
|
||||
case "cv-container": // category
|
||||
return this.refreshCVCat();
|
||||
default:
|
||||
this.last_ctime = 0;
|
||||
this.bloglist.data = [];
|
||||
return this.loadBlogs();
|
||||
}
|
||||
}
|
||||
|
||||
private async saveUser() {
|
||||
try {
|
||||
const inputs = this.select("[input-class='user-input']");
|
||||
for (let v of inputs) { this.user[(v as HTMLInputElement).name] = ($(v)).val(); }
|
||||
if (!this.user.fullname || (this.user.fullname === "")) { return this.toast(__("Full name must be entered")); }
|
||||
//console.log @user
|
||||
let fp = this.userdb;
|
||||
if(this.user && this.user.id)
|
||||
{
|
||||
fp = `${this.userdb.path}@${this.user.id}`.asFileHandle();
|
||||
}
|
||||
fp.cache = this.user
|
||||
const r = await fp.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
if(!this.user.id)
|
||||
{
|
||||
this.user.id = r.result;
|
||||
}
|
||||
this.toast(__("User data updated"));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("Cannot save user data: {0}", e.toString()), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PORFOLIO TAB
|
||||
private refreshCVCat() {
|
||||
return this.fetchCVCat().then((data: any) => {
|
||||
this.cvlist.data = data;
|
||||
return this.cvlist.expandAll();
|
||||
}).catch((e: any) => this.error(__("Unable to load categories"), e));
|
||||
}
|
||||
|
||||
private fetchCVCat() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const data = {
|
||||
text: "Porfolio",
|
||||
id: 0,
|
||||
nodes: []
|
||||
};
|
||||
const filter = {
|
||||
order: ["name$asc"]
|
||||
};
|
||||
const d = await this.cvcatdb.read(filter);
|
||||
this.catListToTree(d, data, 0);
|
||||
resolve(data);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
reject(__e(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
//it = (@cvlist.find "pid", "2")[0]
|
||||
//@cvlist.set "selectedItem", it
|
||||
|
||||
private catListToTree(table: GenericObject<any>[], data: GenericObject<any>, id: number) {
|
||||
const result = table.filter((e) => {
|
||||
return e.pid == id
|
||||
});
|
||||
if (result.length === 0) {
|
||||
return data.nodes = null;
|
||||
}
|
||||
for(let v of result)
|
||||
{
|
||||
v.nodes = [];
|
||||
v.text = v.name;
|
||||
this.catListToTree(table, v, v.id);
|
||||
data.nodes.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
private deleteCVCat(cat: GenericObject<any>): Promise<any> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let v: any;
|
||||
const ids = [];
|
||||
var func = function (c: GenericObject<any>) {
|
||||
ids.push(c.id);
|
||||
if (c.nodes) {
|
||||
c.nodes.map((v) => func(v));
|
||||
}
|
||||
};
|
||||
func(cat);
|
||||
// delete all content
|
||||
let r = await this.cvsecdb.remove({
|
||||
where: {
|
||||
$or: {
|
||||
cid: ids
|
||||
}
|
||||
}
|
||||
});
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
r = await this.cvcatdb.remove({
|
||||
where: {
|
||||
$or: {
|
||||
id: ids
|
||||
}
|
||||
}
|
||||
});
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
await this.refreshCVCat();
|
||||
this.seclist.data = [];
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
reject(__e(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private CVSectionByCID(cid: number): Promise<any> {
|
||||
return new Promise( async (resolve, reject)=> {
|
||||
try {
|
||||
const d = await this.cvsecdb.read({
|
||||
where: {cid},
|
||||
order: [ "start$desc" ]
|
||||
});
|
||||
const items = [];
|
||||
(this.find("cv-sec-status") as GUI.tag.LabelTag).text = __("Found {0} sections", d.length);
|
||||
for (let v of d) {
|
||||
v.closable = true;
|
||||
v.tag = "afx-blogger-cvsection-item";
|
||||
v.start = Number(v.start);
|
||||
v.end = Number(v.end);
|
||||
if (v.start < 1000) { v.start = undefined; }
|
||||
if (v.end < 1000) { v.end = undefined; }
|
||||
items.push(v);
|
||||
}
|
||||
this.seclist.data = items;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
reject(__e(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// blog
|
||||
private async saveBlog() {
|
||||
try {
|
||||
let sel = undefined;
|
||||
const selel = this.bloglist.selectedItem;
|
||||
if (selel) { sel = selel.data; }
|
||||
const tags = this.inputtags.value;
|
||||
const content = this.editor.value();
|
||||
const title = (new RegExp("^#+(.*)\n", "g")).exec(content);
|
||||
if (!title || (title.length !== 2)) { return this.toast(__("Please insert a title in the text: beginning with heading")); }
|
||||
if (tags === "") { return this.toast(__("Please enter tags")); }
|
||||
const d = new Date();
|
||||
const data: GenericObject<any> = {
|
||||
content,
|
||||
title: title[1].trim(),
|
||||
tags,
|
||||
ctime: sel ? sel.ctime : d.timestamp(),
|
||||
ctimestr: sel ? sel.ctimestr : d.toString(),
|
||||
utime: d.timestamp(),
|
||||
utimestr: d.toString(),
|
||||
rendered: this.process(this.editor.options.previewRender(content)),
|
||||
publish: (this.find("blog-publish") as GUI.tag.SwitchTag).swon ? 1 : 0
|
||||
};
|
||||
let handle = this.blogdb;
|
||||
if (sel) {
|
||||
data.id = sel.id;
|
||||
handle = sel.$vfs;
|
||||
}
|
||||
//save the data
|
||||
handle.cache = data;
|
||||
const r = await handle.write(undefined);
|
||||
if(r.error)
|
||||
{
|
||||
throw new Error(r.error as string);
|
||||
}
|
||||
if(!sel)
|
||||
{
|
||||
this.last_ctime = 0;
|
||||
this.bloglist.data = [];
|
||||
await this.loadBlogs();
|
||||
}
|
||||
else
|
||||
{
|
||||
//data.text = data.title;
|
||||
selel.data.utime = data.utime;
|
||||
selel.data.utimestr = data.utimestr;
|
||||
selel.data = selel.data;
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
this.error(__("Cannot save blog: {0}", e.toString()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private process(text: string) {
|
||||
// find video tag and rendered it
|
||||
let found: any;
|
||||
const embed = (id: any) => `\
|
||||
<iframe
|
||||
class = "embeded-video"
|
||||
width="560" height="315"
|
||||
src="https://www.youtube.com/embed/${id}"
|
||||
frameborder="0" allow="encrypted-media" allowfullscreen
|
||||
></iframe>\
|
||||
`;
|
||||
const re = /\[\[youtube:([^\]]*)\]\]/g;
|
||||
const replace = [];
|
||||
while ((found = re.exec(text)) !== null) {
|
||||
replace.push(found);
|
||||
}
|
||||
if (!(replace.length > 0)) { return text; }
|
||||
let ret = "";
|
||||
let begin = 0;
|
||||
for (let it of replace) {
|
||||
ret += text.substring(begin, it.index);
|
||||
ret += embed(it[1]);
|
||||
begin = it.index + it[0].length;
|
||||
}
|
||||
ret += text.substring(begin, text.length);
|
||||
//console.log ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
private clearEditor() {
|
||||
this.editor.value("");
|
||||
this.inputtags.value = "";
|
||||
return (this.find("blog-publish") as GUI.tag.SwitchTag).swon = false;
|
||||
}
|
||||
// load blog
|
||||
private loadBlogs(): Promise<any> {
|
||||
return new Promise( async (ok, reject)=> {
|
||||
try {
|
||||
const filter: GenericObject<any> = {
|
||||
order: ["ctime$desc"],
|
||||
fields: [
|
||||
"id",
|
||||
"title",
|
||||
"ctimestr",
|
||||
"ctime",
|
||||
"utime",
|
||||
"utimestr"
|
||||
],
|
||||
limit: 10,
|
||||
};
|
||||
if(this.last_ctime)
|
||||
{
|
||||
filter.where = { ctime$lt: this.last_ctime};
|
||||
}
|
||||
const r = await this.blogdb.read(filter);
|
||||
if(r.length == 0)
|
||||
{
|
||||
this.toast(__("No more record to load"));
|
||||
return;
|
||||
}
|
||||
this.last_ctime = r[r.length - 1].ctime;
|
||||
for (let v of r) {
|
||||
v.tag = "afx-blogger-post-item";
|
||||
this.bloglist.push(v);
|
||||
}
|
||||
this.clearEditor();
|
||||
return this.bloglist.selected = -1;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
reject(__e(e));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private resizeContent() {
|
||||
const container = this.find("editor-container");
|
||||
const children = ($(".EasyMDEContainer", container)).children();
|
||||
const titlebar = (($(this.scheme)).find(".afx-window-top"))[0];
|
||||
const toolbar = children[0];
|
||||
const statusbar = children[3];
|
||||
const cheight = ($(this.scheme)).height() - ($(titlebar)).height() - ($(toolbar)).height() - ($(statusbar)).height() - 90;
|
||||
return ($(children[1])).css("height", cheight + "px");
|
||||
}
|
||||
}
|
||||
|
||||
Blogger.singleton = true;
|
||||
Blogger.dependencies = [
|
||||
"pkg://SimpleMDE/main.js",
|
||||
"pkg://SimpleMDE/main.css",
|
||||
"pkg://Katex/main.js",
|
||||
"pkg://Katex/main.css",
|
||||
"pkg://SQLiteDB/libsqlite.js",
|
||||
];
|
||||
}
|
||||
}
|
98
Blogger/package.json
Normal file
98
Blogger/package.json
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"app": "Blogger",
|
||||
"name": "Blogging application",
|
||||
"description": "Backend manager for blogging",
|
||||
"info": {
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version": "0.2.13-a",
|
||||
"category": "Internet",
|
||||
"iconclass": "fa fa-book",
|
||||
"dependencies": [
|
||||
"SimpleMDE@2.18.0-r",
|
||||
"Katex@0.11.1-r",
|
||||
"SQLiteDB@0.1.0-a"
|
||||
],
|
||||
"mimes": [
|
||||
"none"
|
||||
],
|
||||
"locales": {
|
||||
"en_GB": {
|
||||
"Pick a parent": "Pick a parent",
|
||||
"Category name": "Category name",
|
||||
"Ok": "Ok",
|
||||
"Cancel": "Cancel",
|
||||
"Title": "Title",
|
||||
"Subtitle": "Subtitle",
|
||||
"Location": "Location",
|
||||
"From": "From",
|
||||
"Save": "Save",
|
||||
"Content": "Content",
|
||||
"IO Hub mail username/password": "IO Hub mail username/password",
|
||||
"Send": "Send",
|
||||
"Please select a parent category": "Please select a parent category",
|
||||
"Please enter category name": "Please enter category name",
|
||||
"Parent can not be the category itself": "Parent can not be the category itself",
|
||||
"Title or content must not be blank": "Title or content must not be blank",
|
||||
"No email selected": "No email selected",
|
||||
"Unable to send mail to: {0}": "Unable to send mail to: {0}",
|
||||
"Error sending mail: {0}": "Error sending mail: {0}",
|
||||
"Open/Create database": "Open/Create database",
|
||||
"Open/create new database": "Open/create new database",
|
||||
"Unable to init database file: {0}": "Unable to init database file: {0}",
|
||||
"Select image file": "Select image file",
|
||||
"Unable to get file": "Unable to get file",
|
||||
"Add category": "Add category",
|
||||
"cv-cat-add: {0}": "cv-cat-add: {0}",
|
||||
"Edit category": "Edit category",
|
||||
"cv-cat-edit: {0}": "cv-cat-edit: {0}",
|
||||
"Delete category": "Delete category",
|
||||
"Do you really want to delete: {0}?": "Do you really want to delete: {0}?",
|
||||
"cv-cat-del: {0}": "cv-cat-del: {0}",
|
||||
"Please select a category": "Please select a category",
|
||||
"New section entry for {0}": "New section entry for {0}",
|
||||
"cv-sec-add: {0}": "cv-sec-add: {0}",
|
||||
"Please select a section to move": "Please select a section to move",
|
||||
"Move to": "Move to",
|
||||
"cv-sec-move: {0}": "cv-sec-move: {0}",
|
||||
"Please select a section to edit": "Please select a section to edit",
|
||||
"Modify section entry": "Modify section entry",
|
||||
"cv-sec-edit: {0}": "cv-sec-edit: {0}",
|
||||
"Cannot delete the section: {0}": "Cannot delete the section: {0}",
|
||||
"New": "New",
|
||||
"Cannot export file for embedding to text": "Cannot export file for embedding to text",
|
||||
"Preview": "Preview",
|
||||
"Send mail": "Send mail",
|
||||
"No post selected": "No post selected",
|
||||
"Emails sent": "Emails sent",
|
||||
"Error sending mails: {0}": "Error sending mails: {0}",
|
||||
"No record found for ID {}": "No record found for ID {}",
|
||||
"Cannot fetch the entry content": "Cannot fetch the entry content",
|
||||
"Delete a post": "Delete a post",
|
||||
"Do you really want to delete this post ?": "Do you really want to delete this post ?",
|
||||
"Cannot fetch user data": "Cannot fetch user data",
|
||||
"Full name must be entered": "Full name must be entered",
|
||||
"User data updated": "User data updated",
|
||||
"Cannot save user data: {0}": "Cannot save user data: {0}",
|
||||
"Unable to load categories": "Unable to load categories",
|
||||
"Found {0} sections": "Found {0} sections",
|
||||
"Please insert a title in the text: beginning with heading": "Please insert a title in the text: beginning with heading",
|
||||
"Please enter tags": "Please enter tags",
|
||||
"Cannot save blog: {0}": "Cannot save blog: {0}",
|
||||
"No more record to load": "No more record to load",
|
||||
"Full name": "Full name",
|
||||
"Address": "Address",
|
||||
"Phone": "Phone",
|
||||
"Email": "Email",
|
||||
"Url": "Url",
|
||||
"Photo": "Photo",
|
||||
"Short biblio": "Short biblio",
|
||||
"Categories": "Categories",
|
||||
"Load more": "Load more",
|
||||
"Tags": "Tags",
|
||||
"Created: {0}": "Created: {0}",
|
||||
"Updated: {0}": "Updated: {0}"
|
||||
}
|
||||
}
|
||||
}
|
91
Blogger/scheme.html
Normal file
91
Blogger/scheme.html
Normal file
@ -0,0 +1,91 @@
|
||||
<afx-app-window data-id = "blogger-win" apptitle="Blogger" width="650" height="500">
|
||||
<afx-hbox padding="5">
|
||||
<afx-tab-container data-id = "tabcontainer" dir = "row" tabbarwidth= "40">
|
||||
|
||||
<afx-hbox data-id="user-container" data-height="100%" iconclass="fa fa-user-circle">
|
||||
<afx-vbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label data-width= "70" text = "__(Full name)"></afx-label>
|
||||
<input type = "text" name="fullname" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Address)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="address" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Phone)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="Phone" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Email)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="email" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Url)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="url" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height = "30">
|
||||
<afx-label text = "__(Photo)" data-width= "70"></afx-label>
|
||||
<input type = "text" name="photo" data-id="photo" readonly="readonly" input-class = "user-input"></input>
|
||||
</afx-hbox>
|
||||
<afx-label data-height = "30" text = "__(Short biblio)"></afx-label>
|
||||
<textarea name="shortbiblio" input-class = "user-input"></textarea>
|
||||
<afx-hbox data-height = "35" style="text-align: right;">
|
||||
<afx-button iconclass = "fa fa-save" data-id = "bt-user-save" text = "__(Save)"></afx-button>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-hbox>
|
||||
|
||||
<afx-hbox data-id="cv-container" data-height="100%" iconclass="fa fa-info-circle">
|
||||
<div data-width="5"></div>
|
||||
<afx-vbox data-width="150" min-width="100">
|
||||
<afx-label class="lbl-header" data-height = "23" text = "__(Categories)" iconclass = "fa fa-bars"></afx-label>
|
||||
<afx-tree-view data-id = "cv-list" ></afx-tree-view>
|
||||
<div data-height="35" class = "cv-side-bar-btn">
|
||||
<afx-button data-id = "cv-cat-add" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-del" text = "" iconclass = "fa fa-minus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-edit" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
</div>
|
||||
</afx-vbox>
|
||||
<afx-resizer data-width = "2"></afx-resizer>
|
||||
<afx-vbox>
|
||||
<afx-list-view data-id = "cv-sec-list" ></afx-list-view>
|
||||
<afx-hbox data-height="35" >
|
||||
<afx-label data-id = "cv-sec-status"></afx-label>
|
||||
<div class = "cv-side-bar-btn">
|
||||
<afx-button data-id = "cv-sec-add" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-sec-edit" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
<afx-button data-id = "cv-sec-move" text = "" iconclass = "fa fa-exchange"></afx-button>
|
||||
</div>
|
||||
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
|
||||
|
||||
<afx-hbox data-id = "blog-container" data-height="100%" iconclass="fa fa-book">
|
||||
<afx-vbox>
|
||||
<afx-list-view data-id = "blog-list" min-width="100" data-width="200"></afx-list-view>
|
||||
<afx-button data-id = "blog-load-more" text = "__(Load more)" iconclass_end = "bi bi-chevron-double-right" data-height="content"></afx-button>
|
||||
</afx-vbox>
|
||||
<afx-resizer data-width = "3"></afx-resizer>
|
||||
<afx-vbox>
|
||||
<div data-id = "editor-container">
|
||||
<textarea data-id="markarea" ></textarea>
|
||||
</div>
|
||||
<afx-label text = "__(Tags)" style="font-weight:bold;" data-height="25" ></afx-label>
|
||||
<afx-hbox data-height="25">
|
||||
<input type = "text" data-id = "input-tags" ></input>
|
||||
<div data-width="5"></div>
|
||||
<afx-switch data data-id = "blog-publish" data-width="30"></afx-switch>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
|
||||
<div data-height="5"></div>
|
||||
</afx-vbox>
|
||||
</afx-hbox>
|
||||
|
||||
</afx-tab-container>
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
104
Blogger/tags.ts
Normal file
104
Blogger/tags.ts
Normal file
@ -0,0 +1,104 @@
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Check if the array includes an element
|
||||
*
|
||||
* @param {T} element to check
|
||||
* @returns {boolean}
|
||||
* @memberof Array
|
||||
*/
|
||||
includes(el: T): boolean;
|
||||
}
|
||||
|
||||
namespace OS {
|
||||
export namespace application {
|
||||
export namespace blogger {
|
||||
|
||||
class CVSectionListItemTag extends OS.GUI.tag.ListViewItemTag {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
ondatachange() {
|
||||
if (!this.data) { return; }
|
||||
const v = this.data;
|
||||
const nativel = ["content", "start", "end"];
|
||||
this.closable = v.closable;
|
||||
return (() => {
|
||||
const result = [];
|
||||
for (let k in this.refs) {
|
||||
const el = this.refs[k];
|
||||
if (v[k] && (v[k] !== "")) {
|
||||
if (nativel.includes(k)) {
|
||||
result.push($(el).text(v[k]));
|
||||
} else {
|
||||
result.push((el as OS.GUI.tag.LabelTag).text = v[k]);
|
||||
}
|
||||
} else {
|
||||
result.push(undefined);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
}
|
||||
|
||||
reload() { }
|
||||
|
||||
init() { }
|
||||
|
||||
|
||||
itemlayout() {
|
||||
return {
|
||||
el: "div", children: [
|
||||
{ el: "afx-label", ref: "title", class: "afx-cv-sec-title" },
|
||||
{ el: "afx-label", ref: "subtitle", class: "afx-cv-sec-subtitle" },
|
||||
{ el: "p", ref: "content", class: "afx-cv-sec-content" },
|
||||
{
|
||||
el: "p", class: "afx-cv-sec-period", children: [
|
||||
{ el: "i", ref: "start" },
|
||||
{ el: "i", ref: "end", class: "period-end" }
|
||||
]
|
||||
},
|
||||
{ el: "afx-label", ref: "location", class: "afx-cv-sec-loc" }
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
OS.GUI.tag.define("afx-blogger-cvsection-item", CVSectionListItemTag);
|
||||
|
||||
|
||||
class BlogPostListItemTag extends OS.GUI.tag.ListViewItemTag {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
ondatachange() {
|
||||
if (!this.data) { return; }
|
||||
const v = this.data;
|
||||
v.closable = true;
|
||||
this.closable = v.closable;
|
||||
(this.refs.title as OS.GUI.tag.LabelTag).text = v.title;
|
||||
(this.refs.ctimestr as OS.GUI.tag.LabelTag).text = __("Created: {0}", v.ctimestr);
|
||||
(this.refs.utimestr as OS.GUI.tag.LabelTag).text = __("Updated: {0}", v.utimestr);
|
||||
}
|
||||
|
||||
reload() { }
|
||||
|
||||
init() { }
|
||||
|
||||
itemlayout() {
|
||||
return {
|
||||
el: "div", children: [
|
||||
{ el: "afx-label", ref: "title", class: "afx-blogpost-title" },
|
||||
{ el: "afx-label", ref: "ctimestr", class: "blog-dates" },
|
||||
{ el: "afx-label", ref: "utimestr", class: "blog-dates" },
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
OS.GUI.tag.define("afx-blogger-post-item", BlogPostListItemTag);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user