mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-19 23:39:46 +02:00
update to latest backend changes
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
# Blogger
|
||||
|
||||
Blackend for my blog at https://blog.iohub.dev
|
||||
|
||||
|
||||
## Change logs
|
||||
|
||||
### v0.2.x-a
|
||||
* 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
|
@ -1,32 +0,0 @@
|
||||
|
||||
local data = ...
|
||||
-- print(data.content)
|
||||
local error_msg = {}
|
||||
local iserror = false
|
||||
local tmp_name = "/tmp/"..os.time(os.date("!*t"))
|
||||
local file = io.open (tmp_name , "w")
|
||||
if file then
|
||||
file:write("From: mrsang@lxsang.me\n")
|
||||
file:write("Subject: " .. data.title .. "\n")
|
||||
file:write( data.content.."\n")
|
||||
file:close()
|
||||
for k,v in pairs(data.to) do
|
||||
print("sent to:"..v)
|
||||
local to = v
|
||||
local cmd = 'cat ' ..tmp_name .. '| sendmail ' .. to
|
||||
--print(cmd)
|
||||
local r = os.execute(cmd)
|
||||
if not r then
|
||||
iserror = true
|
||||
table.insert(error_msg, v)
|
||||
print("Unable to send mail to: "..v)
|
||||
end
|
||||
end
|
||||
else
|
||||
iserror = true
|
||||
table.insert(error_msg, "Cannot create mail file")
|
||||
end
|
||||
local result = {}
|
||||
result.error = iserror
|
||||
result.result = error_msg
|
||||
return result
|
Binary file not shown.
@ -1,32 +0,0 @@
|
||||
<afx-app-window data-id = "blogger-cv-sec-win" apptitle="Porforlio section" width="450" height="400">
|
||||
<afx-vbox >
|
||||
<div data-height="5"></div>
|
||||
<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>
|
||||
<afx-hbox data-height = "35">
|
||||
<div></div>
|
||||
<afx-switch data-id = "section-publish" data-width="30"></afx-switch>
|
||||
<afx-button iconclass = "fa fa-save" data-id = "bt-cv-sec-save" data-width="60" text = "__(Save)"></afx-button>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-app-window>
|
@ -1,190 +0,0 @@
|
||||
# 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/.
|
||||
class BloggerCategoryDialog extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "BloggerCategoryDialog", BloggerCategoryDialog.scheme
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
@tree = @find "tree"
|
||||
@txtinput = @find "txtinput"
|
||||
|
||||
(@find "bt-ok").onbtclick = (e) =>
|
||||
sel = @tree.selectedItem
|
||||
return @notify __("Please select a parent category") unless sel
|
||||
seldata = sel.data
|
||||
val = @txtinput.value
|
||||
return @notify __("Please enter category name") if val is "" and not @data.selonly
|
||||
return @notify __("Parent can not be the category itself") if @data.cat and @data.cat.id is seldata.id
|
||||
@handle { p: seldata, value: val } if @handle
|
||||
@quit()
|
||||
|
||||
(@find "bt-cancel").onbtclick = (e) =>
|
||||
@quit()
|
||||
if @data and @data.tree
|
||||
if @data and @data.cat
|
||||
@txtinput.value = @data.cat.name
|
||||
if @data.cat.pid is "0"
|
||||
seldata = @data.tree
|
||||
else
|
||||
seldata = @findDataByID @data.cat.pid, @data.tree.nodes
|
||||
seldata.selected = true if seldata
|
||||
@tree.data = @data.tree
|
||||
@tree.expandAll()
|
||||
# TODO set selected category name
|
||||
|
||||
findDataByID: (id, list) ->
|
||||
for data in list
|
||||
return data if data.id is id
|
||||
if data.nodes
|
||||
@findDataByID id, data.nodes
|
||||
return undefined
|
||||
|
||||
BloggerCategoryDialog.scheme = """
|
||||
<afx-app-window width='300' height='400'>
|
||||
<afx-vbox>
|
||||
<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 = '30'>
|
||||
<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>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-app-window>
|
||||
"""
|
||||
|
||||
# This dialog is use for cv section editing
|
||||
|
||||
class BloggerCVSectionDiaglog extends this.OS.GUI.BasicDialog
|
||||
constructor: (parent) ->
|
||||
file = "#{parent.meta().path}/cvsection.html".asFileHandle()
|
||||
super "BloggerCVSectionDiaglog", file
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
@editor = new SimpleMDE
|
||||
autoDownloadFontAwesome: false
|
||||
element: @find "contentarea"
|
||||
status: false
|
||||
toolbar: false
|
||||
($ (@select '[class = "CodeMirror-scroll"]')[0]).css "min-height", "50px"
|
||||
($ (@select '[class="CodeMirror cm-s-paper CodeMirror-wrap"]')[0]).css "min-height", "50px"
|
||||
inputs = @select "[input-class='user-input']"
|
||||
(($ v).val @data.section[v.name] for v in inputs ) if @data and @data.section
|
||||
@editor.value @data.section.content if @data and @data.section
|
||||
(@find "section-publish").swon = (if @data and @data.section and Number(@data.section.publish) then true else false)
|
||||
(@find "bt-cv-sec-save").onbtclick = (e) =>
|
||||
data = {}
|
||||
data[v.name] = ($ v).val() for v in inputs
|
||||
data.content = @editor.value()
|
||||
return @notify __("Title or content must not be blank") if data.title is "" and data.content is ""
|
||||
#return @notify "Content must not be blank" if data.content is ""
|
||||
data.id = @data.section.id if @data and @data.section
|
||||
val = (@find "section-publish").swon
|
||||
if val is true
|
||||
data.publish = 1
|
||||
else
|
||||
data.publish = 0
|
||||
@handle data if @handle
|
||||
@quit()
|
||||
|
||||
@on "vboxchange", () => @resizeContent()
|
||||
@resizeContent()
|
||||
|
||||
resizeContent: () ->
|
||||
container = @find "editor-container"
|
||||
children = ($ container).children()
|
||||
cheight = ($ container).height() - 30
|
||||
($ children[1]).css("height", cheight + "px")
|
||||
|
||||
|
||||
# this dialog is for send mail
|
||||
class BloggerSendmailDiaglog extends this.OS.GUI.BasicDialog
|
||||
constructor: (parent) ->
|
||||
file = "#{parent.meta().path}/sendmail.html".asFileHandle()
|
||||
super "BloggerSendmailDiaglog", file
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
@subdb = new @.parent._api.DB("subscribers")
|
||||
@maillinglist = @find "email-list"
|
||||
title = (new RegExp "^#+(.*)\n", "g").exec @data.content
|
||||
(@find "mail-title").value = title[1]
|
||||
content = (@data.content.substring 0, 500) + "..."
|
||||
(@find "contentarea").value = BloggerSendmailDiaglog.template.format @data.id, content
|
||||
|
||||
@subdb.find {}
|
||||
.then (d) =>
|
||||
for v in d
|
||||
v.text = v.name
|
||||
v.switch = true
|
||||
v.checked = true
|
||||
@maillinglist. items = d
|
||||
.catch (e) =>
|
||||
@error __("Cannot fetch subscribers data: {0}", e.toString()), e
|
||||
|
||||
(@find "bt-sendmail").onbtclick = (e) =>
|
||||
items = @maillinglist.items
|
||||
emails = []
|
||||
for v in items
|
||||
if v.checked is true
|
||||
console.log v.email
|
||||
emails.push v.email
|
||||
|
||||
return @notify __("No email selected") if emails.length is 0
|
||||
# send the email
|
||||
data =
|
||||
path: "#{@parent.path()}/sendmail.lua",
|
||||
parameters:
|
||||
to: emails,
|
||||
title: (@find "mail-title").value,
|
||||
content: (@find "contentarea").value
|
||||
@_api.apigateway data, false
|
||||
.then (d) =>
|
||||
return @notify __("Unable to send mail to: {0}", d.result.join(", ")) if d.error
|
||||
@quit()
|
||||
.catch (e) =>
|
||||
console.log e
|
||||
@error __("Error sending mail: {0}", e.toString()), e
|
||||
|
||||
|
||||
|
||||
BloggerSendmailDiaglog.template = """
|
||||
Hello,
|
||||
|
||||
Xuan Sang LE has just published a new post on his blog: https://blog.lxsang.me/post/id/{0}
|
||||
|
||||
==========
|
||||
{1}
|
||||
==========
|
||||
|
||||
|
||||
Read the full article via:
|
||||
https://blog.lxsang.me/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
|
||||
"""
|
@ -1,506 +0,0 @@
|
||||
# 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/.
|
||||
class Blogger extends this.OS.application.BaseApplication
|
||||
constructor: (args) ->
|
||||
super "Blogger", args
|
||||
|
||||
|
||||
main: () ->
|
||||
@user = {}
|
||||
@cvlist = @find "cv-list"
|
||||
@cvlist.ontreeselect = (d) =>
|
||||
return unless d
|
||||
data = d.data.item.data
|
||||
@CVSectionByCID Number(data.id)
|
||||
|
||||
@inputtags = @.find "input-tags"
|
||||
@bloglist = @find "blog-list"
|
||||
@seclist = @find "cv-sec-list"
|
||||
|
||||
el = @find("photo")
|
||||
$(el)
|
||||
.click (e) =>
|
||||
@openDialog("FileDialog", {
|
||||
title: __("Select image file"),
|
||||
mimes: ["image/.*"]
|
||||
})
|
||||
.then (d) =>
|
||||
el.value = d.file.path
|
||||
.catch (e) => @error __("Unable to get file"), e
|
||||
|
||||
@userdb = new @_api.DB("user")
|
||||
@cvcatdb = new @_api.DB("cv_cat")
|
||||
@cvsecdb = new @_api.DB("cv_sections")
|
||||
@blogdb = new @_api.DB("blogs")
|
||||
|
||||
|
||||
@tabcontainer = @find "tabcontainer"
|
||||
@tabcontainer.ontabselect = (e) =>
|
||||
@fetchData e.data.container.aid
|
||||
|
||||
(@find "bt-user-save").onbtclick = (e) =>
|
||||
@saveUser()
|
||||
|
||||
(@find "cv-cat-add").onbtclick = (e) =>
|
||||
fn = (tree) =>
|
||||
@openDialog(new BloggerCategoryDialog(), {
|
||||
title: __("Add category"),
|
||||
tree: tree
|
||||
}).then (d) =>
|
||||
c =
|
||||
name: d.value,
|
||||
pid: d.p.id,
|
||||
publish: 1
|
||||
@cvcatdb.save c
|
||||
.then (r) =>
|
||||
@refreshCVCat()
|
||||
.catch (e) => @error __("Cannot add new category"), e
|
||||
.catch (e) => @error e.toString(), e
|
||||
@fetchCVCat()
|
||||
.then (tree) => fn(tree)
|
||||
.catch (e) =>
|
||||
data =
|
||||
text: "Porfolio",
|
||||
id:"0",
|
||||
nodes: []
|
||||
fn(data)
|
||||
@error __("Unable to fetch categories"), e
|
||||
|
||||
(@find "cv-cat-edit").onbtclick = (e) =>
|
||||
sel = @cvlist.selectedItem
|
||||
return unless sel
|
||||
cat = sel.data
|
||||
return unless cat
|
||||
@fetchCVCat().then (tree) =>
|
||||
@openDialog(new BloggerCategoryDialog(), {
|
||||
title: __("Edit category"),
|
||||
tree: tree, cat: cat
|
||||
}).then (d) =>
|
||||
c =
|
||||
id: cat.id,
|
||||
publish: cat.publish,
|
||||
pid: d.p.id,
|
||||
name: d.value
|
||||
|
||||
@cvcatdb.save c
|
||||
.then (r) =>
|
||||
@refreshCVCat()
|
||||
.catch (e) =>
|
||||
@error __("Cannot Edit category"), e
|
||||
.catch (e) => @error __("Unable to fetch categories"), e
|
||||
|
||||
(@find "cv-cat-del").onbtclick = (e) =>
|
||||
sel = @cvlist.selectedItem
|
||||
return unless sel
|
||||
cat = sel.data
|
||||
return unless cat
|
||||
@openDialog("YesNoDialog", {
|
||||
title: __("Delete category") ,
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete: {0}?", cat.name)
|
||||
}).then (d) =>
|
||||
return unless d
|
||||
@deleteCVCat cat
|
||||
.catch (e) => @error e.toString(), e
|
||||
|
||||
(@find "cv-sec-add").onbtclick = (e) =>
|
||||
sel = @cvlist.selectedItem
|
||||
return unless sel
|
||||
cat = sel.data
|
||||
return @notify __("Please select a category") unless cat and cat.id isnt "0"
|
||||
@openDialog(new BloggerCVSectionDiaglog(@), {
|
||||
title: __("New section entry for {0}", cat.name)
|
||||
}).then (d) =>
|
||||
d.cid = Number cat.id
|
||||
d.start = Number d.start
|
||||
d.end = Number d.end
|
||||
# d.publish = 1
|
||||
@cvsecdb.save d
|
||||
.then (r) =>
|
||||
@CVSectionByCID Number(cat.id)
|
||||
.catch (e) => @error __("Cannot save section: {0}", e.toString()), e
|
||||
|
||||
(@find "cv-sec-move").onbtclick = (e) =>
|
||||
sel = (@find "cv-sec-list").selectedItem
|
||||
return @notify __("Please select a section to move") unless sel
|
||||
sec = sel.data
|
||||
|
||||
@fetchCVCat().then (tree) =>
|
||||
@openDialog(new BloggerCategoryDialog(),{
|
||||
title: __("Move to"),
|
||||
tree: tree,
|
||||
selonly: true
|
||||
}).then (d) =>
|
||||
c =
|
||||
id: sec.id,
|
||||
cid: d.p.id
|
||||
|
||||
@cvsecdb.save c
|
||||
.then (r) =>
|
||||
@CVSectionByCID(sec.cid)
|
||||
(@find "cv-sec-list").unselect()
|
||||
.catch (e) => @error __("Cannot move section"), e
|
||||
|
||||
(@find "cv-sec-edit").onbtclick = (e) =>
|
||||
sel = (@find "cv-sec-list").selectedItem
|
||||
return @notify __("Please select a section to edit") unless sel
|
||||
sec = sel.data
|
||||
@openDialog(new BloggerCVSectionDiaglog(@), {
|
||||
title: __("Modify section entry"),
|
||||
section: sec
|
||||
}).then (d) =>
|
||||
d.cid = Number sec.cid
|
||||
d.start = Number d.start
|
||||
d.end = Number d.end
|
||||
#d.publish = Number sec.publish
|
||||
@cvsecdb.save d
|
||||
.then (r) =>
|
||||
@CVSectionByCID Number(sec.cid)
|
||||
.catch (e) => return @error __("Cannot save section: {0}", e.toString()), e
|
||||
|
||||
@seclist.onitemclose = (e) =>
|
||||
return unless e
|
||||
data = e.data.item.data
|
||||
@openDialog("YesNoDialog", {
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete: {0}?", data.title)
|
||||
}).then (b) =>
|
||||
return unless b
|
||||
@cvsecdb.delete data.id
|
||||
.then (r) =>
|
||||
@seclist.delete e.data.item
|
||||
.catch (e) => @error __("Cannot delete the section: {0}", e.toString()), e
|
||||
return false
|
||||
|
||||
@editor = new SimpleMDE
|
||||
element: @find "markarea"
|
||||
autoDownloadFontAwesome: false
|
||||
autofocus: true
|
||||
tabSize: 4
|
||||
indentWithTabs: true
|
||||
toolbar: [
|
||||
{
|
||||
name: __("New"),
|
||||
className: "fa fa-file",
|
||||
action: (e) =>
|
||||
@bloglist.unselect()
|
||||
@clearEditor()
|
||||
},
|
||||
{
|
||||
name: __("Save"),
|
||||
className: "fa fa-save",
|
||||
action: (e) =>
|
||||
@saveBlog()
|
||||
}
|
||||
, "|", "bold", "italic", "heading", "|", "quote", "code",
|
||||
"unordered-list", "ordered-list", "|", "link",
|
||||
"image", "table", "horizontal-rule",
|
||||
{
|
||||
name: "image",
|
||||
className: "fa fa-file-image-o",
|
||||
action: (e) =>
|
||||
@openDialog("FileDialog", {
|
||||
title: __("Select image file"),
|
||||
mimes: ["image/.*"]
|
||||
}).then (d) =>
|
||||
d.file.path.asFileHandle().publish()
|
||||
.then (r) =>
|
||||
doc = @editor.codemirror.getDoc()
|
||||
doc.replaceSelection ""
|
||||
.catch (e) => @error __("Cannot export file for embedding to text"), e
|
||||
},
|
||||
{
|
||||
name:"Youtube",
|
||||
className: "fa fa-youtube",
|
||||
action: (e) =>
|
||||
doc = @editor.codemirror.getDoc()
|
||||
doc.replaceSelection "[[youtube:]]"
|
||||
}
|
||||
"|",
|
||||
{
|
||||
name: __("Preview"),
|
||||
className: "fa fa-eye no-disable",
|
||||
action: (e) =>
|
||||
@previewOn = !@previewOn
|
||||
SimpleMDE.togglePreview e
|
||||
#/console.log @select ".editor-preview editor-preview-active"
|
||||
renderMathInElement @find "editor-container"
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: __("Send mail"),
|
||||
className: "fa fa-paper-plane",
|
||||
action: (e) =>
|
||||
sel = @bloglist.selectedItem
|
||||
return @error __("No post selected") unless sel
|
||||
data = sel.data
|
||||
@openDialog(new BloggerSendmailDiaglog(@), {
|
||||
title: __("Send mail"),
|
||||
content: @editor.value(),
|
||||
id: data.id
|
||||
})
|
||||
.then (d) ->
|
||||
console.log "Email sent"
|
||||
}
|
||||
],
|
||||
|
||||
@bloglist.onlistselect = (e) =>
|
||||
el = @bloglist.selectedItem
|
||||
return unless el
|
||||
sel = el.data
|
||||
return unless sel
|
||||
@blogdb.get Number(sel.id)
|
||||
.then (r) =>
|
||||
@editor.value r.content
|
||||
@inputtags.value = r.tags
|
||||
(@find "blog-publish").swon = if Number(r.publish) then true else false
|
||||
.catch (e) =>
|
||||
@error __("Cannot fetch the entry content"), e
|
||||
|
||||
@bloglist.onitemclose = (e) =>
|
||||
return unless e
|
||||
el = e.data.item
|
||||
data = el.data
|
||||
@openDialog("YesNoDialog", {
|
||||
title: __("Delete a post"),
|
||||
iconclass: "fa fa-question-circle",
|
||||
text: __("Do you really want to delete this post ?")
|
||||
}).then (b) =>
|
||||
return unless b
|
||||
@blogdb.delete data.id
|
||||
.then (r) =>
|
||||
@bloglist.delete el
|
||||
@bloglist.unselect()
|
||||
@clearEditor()
|
||||
return false
|
||||
|
||||
|
||||
@bindKey "CTRL-S", () =>
|
||||
sel = @tabcontainer.selectedTab
|
||||
return unless sel and sel.container.aid is "blog-container"
|
||||
@saveBlog()
|
||||
@on "vboxchange", () =>
|
||||
@resizeContent()
|
||||
|
||||
@resizeContent()
|
||||
@loadBlogs()
|
||||
# @fetchData 0
|
||||
# USER TAB
|
||||
fetchData: (idx) ->
|
||||
switch idx
|
||||
when "user-container" #user info
|
||||
|
||||
@userdb.get null
|
||||
.then (d) =>
|
||||
@user = d[0]
|
||||
inputs = @select "[input-class='user-input']"
|
||||
($ v).val @user[v.name] for v in inputs
|
||||
.catch (e) => @error __("Cannot fetch user data"), e
|
||||
when "cv-container" # category
|
||||
@refreshCVCat()
|
||||
else
|
||||
@loadBlogs()
|
||||
|
||||
saveUser:() ->
|
||||
inputs = @select "[input-class='user-input']"
|
||||
@user[v.name] = ($ v).val() for v in inputs
|
||||
return @notify __("Full name must be entered") if not @user.fullname or @user.fullname is ""
|
||||
#console.log @user
|
||||
@userdb.save @user
|
||||
.then (r) =>
|
||||
return @notify __("User data updated")
|
||||
.catch (e) => return @error __("Cannot save user data"), e
|
||||
|
||||
|
||||
# PORFOLIO TAB
|
||||
refreshCVCat: () ->
|
||||
@fetchCVCat().then (data) =>
|
||||
@cvlist.data = data
|
||||
@cvlist.expandAll()
|
||||
.catch (e) => @error __("Unable to load categories"), e
|
||||
|
||||
fetchCVCat: () ->
|
||||
new Promise (resolve, reject) =>
|
||||
data =
|
||||
text: "Porfolio",
|
||||
id:"0",
|
||||
nodes: []
|
||||
cnd =
|
||||
order:
|
||||
name: "ASC"
|
||||
@cvcatdb.find cnd
|
||||
.then (d) =>
|
||||
@catListToTree d, data, "0"
|
||||
resolve data
|
||||
.catch (e) -> reject __e e
|
||||
#it = (@cvlist.find "pid", "2")[0]
|
||||
#@cvlist.set "selectedItem", it
|
||||
|
||||
catListToTree: (table, data, id) ->
|
||||
result = (v for v in table when v.pid is id)
|
||||
return data.nodes = null if result.length is 0
|
||||
for v in result
|
||||
v.nodes = []
|
||||
v.text = v.name
|
||||
@catListToTree table, v, v.id
|
||||
#v.nodes = null if v.nodes.length is 0
|
||||
data.nodes.push v
|
||||
|
||||
deleteCVCat: (cat) ->
|
||||
me = @
|
||||
ids = []
|
||||
func = (c) ->
|
||||
ids.push c.id
|
||||
func(v) for v in c.nodes if c.nodes
|
||||
func(cat)
|
||||
|
||||
cond = ({ "=": { cid: v } } for v in ids)
|
||||
# delete all content
|
||||
@cvsecdb.delete({ "or": cond }).then (r) =>
|
||||
cond = ({ "=": { id: v } } for v in ids)
|
||||
@cvcatdb.delete({ "or": cond }).then (re) =>
|
||||
@refreshCVCat()
|
||||
@seclist.data=[]
|
||||
.catch (e) =>
|
||||
@error __("Cannot delete the category: {0} [{1}]", cat.name, e.toString()), e
|
||||
.catch (e) =>
|
||||
@error __("Cannot delete all content of: {0} [{1}]", cat.name, e.toString()), e
|
||||
|
||||
CVSectionByCID: (cid) ->
|
||||
cond =
|
||||
exp:
|
||||
"=":
|
||||
cid: cid
|
||||
order:
|
||||
start: "DESC"
|
||||
@cvsecdb.find(cond).then (d) =>
|
||||
items = []
|
||||
(@find "cv-sec-status").text = __("Found {0} sections", d.length)
|
||||
for v in d
|
||||
v.closable = true
|
||||
v.tag = "afx-blogger-cvsection-item"
|
||||
v.start = Number(v.start)
|
||||
v.end = Number(v.end)
|
||||
v.start = undefined if v.start < 1000
|
||||
v.end = undefined if v.end < 1000
|
||||
items.push v
|
||||
@seclist.data = items
|
||||
.catch (e) => @error e.toString(), e
|
||||
|
||||
# blog
|
||||
saveBlog: () ->
|
||||
sel = undefined
|
||||
selel = @bloglist.selectedItem
|
||||
sel = selel.data if selel
|
||||
tags = @inputtags.value
|
||||
content = @editor.value()
|
||||
title = (new RegExp "^#+(.*)\n", "g").exec content
|
||||
return @notify __("Please insert a title in the text: beginning with heading") unless title and title.length is 2
|
||||
return @notify __("Please enter tags") if tags is ""
|
||||
d = new Date()
|
||||
data =
|
||||
content: content
|
||||
title: title[1].trim()
|
||||
tags: tags
|
||||
ctime: if sel then sel.ctime else d.timestamp()
|
||||
ctimestr: if sel then sel.ctimestr else d.toString()
|
||||
utime: d.timestamp()
|
||||
utimestr: d.toString()
|
||||
rendered: @process(@editor.options.previewRender(content))
|
||||
publish: if (@find "blog-publish").swon then 1 else 0
|
||||
data.id = sel.id if sel
|
||||
#save the data
|
||||
@blogdb.save data
|
||||
.then (r) =>
|
||||
@loadBlogs()
|
||||
.catch (e) => @error __("Cannot save blog: {0}", e.toString()), e
|
||||
|
||||
process: (text) ->
|
||||
# find video tag and rendered it
|
||||
embed = (id) ->
|
||||
return """
|
||||
<iframe
|
||||
class = "embeded-video"
|
||||
width="560" height="315"
|
||||
src="https://www.youtube.com/embed/#{id}"
|
||||
frameborder="0" allow="encrypted-media" allowfullscreen
|
||||
></iframe>
|
||||
"""
|
||||
re = /\[\[youtube:([^\]]*)\]\]/g
|
||||
replace = []
|
||||
while (found = re.exec text) isnt null
|
||||
replace.push found
|
||||
return text unless replace.length > 0
|
||||
ret = ""
|
||||
begin = 0
|
||||
for it in 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
|
||||
|
||||
clearEditor:() ->
|
||||
@.editor.value ""
|
||||
@.inputtags.value = ""
|
||||
(@.find "blog-publish").swon = false
|
||||
# load blog
|
||||
loadBlogs: () ->
|
||||
selidx = -1
|
||||
el = @bloglist.selectedItem
|
||||
selidx = $(el).index()
|
||||
cond =
|
||||
order:
|
||||
ctime: "DESC"
|
||||
fields: [
|
||||
"id",
|
||||
"title",
|
||||
"ctimestr",
|
||||
"ctime",
|
||||
"utime",
|
||||
"utimestr"
|
||||
]
|
||||
@blogdb.find cond
|
||||
.then (r) =>
|
||||
v.tag = "afx-blogger-post-item" for v in r
|
||||
@bloglist.data = r
|
||||
if selidx isnt -1
|
||||
@bloglist.selected = selidx
|
||||
else
|
||||
@clearEditor()
|
||||
@bloglist.selected = -1
|
||||
.catch (e) => @error __("No post found: {0}", e.toString()), e
|
||||
|
||||
resizeContent: () ->
|
||||
container = @find "editor-container"
|
||||
children = ($ container).children()
|
||||
titlebar = (($ @scheme).find ".afx-window-top")[0]
|
||||
toolbar = children[1]
|
||||
statusbar = children[4]
|
||||
cheight = ($ @scheme).height() - ($ titlebar).height() - ($ toolbar).height() - ($ statusbar).height() - 90
|
||||
($ children[2]).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",
|
||||
]
|
||||
this.OS.register "Blogger", Blogger
|
@ -1,92 +0,0 @@
|
||||
afx-app-window[data-id="blogger-win"] afx-tab-container[data-id="tabcontainer"] afx-tab-bar afx-list-view > div.list-container {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border-right: 1px solid #292929;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="blogger-win"] afx-tab-container[data-id="tabcontainer"] afx-tab-bar afx-list-view > div.list-container > ul li{
|
||||
font-size: 15px;
|
||||
padding:0;
|
||||
width: 100%;
|
||||
border-radius: 0;
|
||||
border:0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
afx-app-window[data-id="blogger-win"] afx-tab-container[data-id="tabcontainer"] afx-tab-bar afx-list-view > div.list-container > ul li.selected {
|
||||
background-color: #116cd6;
|
||||
color:white;
|
||||
}
|
||||
|
||||
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"] 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,14 +0,0 @@
|
||||
{
|
||||
"app":"Blogger",
|
||||
"name":"Blogging application",
|
||||
"description":"Backend manager for blogging",
|
||||
"info":{
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version":"0.2.7-a",
|
||||
"category":"Internet",
|
||||
"iconclass":"fa fa-book",
|
||||
"dependencies": ["SimpleMDE@1.11.2-r","Katex@0.11.1-r"],
|
||||
"mimes":["none"]
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "Blogger",
|
||||
"css": ["main.css"],
|
||||
"javascripts": [],
|
||||
"coffees": ["main.coffee", "dialogs.coffee", "tags.coffee"],
|
||||
"copies": [
|
||||
"scheme.html",
|
||||
"cvsection.html",
|
||||
"api/sendmail.lua",
|
||||
"sendmail.html",
|
||||
"package.json",
|
||||
"README.md"
|
||||
]
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<afx-app-window data-id = "blogger-win" apptitle="Blogger" width="600" height="500">
|
||||
<afx-hbox >
|
||||
<afx-tab-container data-id = "tabcontainer" dir = "row" tabbarwidth= "22">
|
||||
|
||||
<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">
|
||||
<div></div>
|
||||
<afx-button iconclass = "fa fa-save" data-id = "bt-user-save" data-width="60" 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>
|
||||
<afx-hbox data-height="30" class = "cv-side-bar-btn">
|
||||
<afx-button data-id = "cv-cat-add" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-del" data-width = "25" text = "" iconclass = "fa fa-minus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-cat-edit" data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
</afx-hbox>
|
||||
</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="30" class = "cv-side-bar-btn">
|
||||
<afx-label data-id = "cv-sec-status"></afx-label>
|
||||
<afx-button data-id = "cv-sec-add" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button>
|
||||
<afx-button data-id = "cv-sec-edit" data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
|
||||
<afx-button data-id = "cv-sec-move" data-width = "25" text = "" iconclass = "fa fa-exchange"></afx-button>
|
||||
</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-list-view data-id = "blog-list" min-width="100" data-width="200"></afx-list-view>
|
||||
<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>
|
@ -1,20 +0,0 @@
|
||||
<afx-app-window data-id = "blogger-send-mail-win" apptitle="Send mail" width="500" height="400" resizable = "false">
|
||||
<afx-hbox>
|
||||
<afx-menu data-width="150" data-id="email-list"></afx-menu>
|
||||
<afx-resizer data-width="3"></afx-resizer>
|
||||
<div data-width="5"></div>
|
||||
<afx-vbox >
|
||||
<div data-height="5"></div>
|
||||
<afx-label data-height="20" text = "__(Title)"></afx-label>
|
||||
<input type = "text" data-height="20" name="title" data-id = "mail-title"></input>
|
||||
<afx-label data-height = "20" text = "Content" ></afx-label>
|
||||
<textarea name="content" data-id = "contentarea" ></textarea>
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox data-height = "30">
|
||||
<div></div>
|
||||
<afx-button iconclass = "fa fa-paper-plane" data-id = "bt-sendmail" data-width="60" text = "__(Send)"></afx-button>
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
<div data-width="5"></div>
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
@ -1,63 +0,0 @@
|
||||
Ant = this
|
||||
|
||||
class CVSectionListItemTag extends this.OS.GUI.tag.ListViewItemTag
|
||||
constructor: () ->
|
||||
super()
|
||||
|
||||
ondatachange: () ->
|
||||
return unless @data
|
||||
v = @data
|
||||
nativel = ["content", "start", "end" ]
|
||||
@closable = v.closable
|
||||
for k, el of @refs
|
||||
if v[k] and v[k] isnt ""
|
||||
if nativel.includes k
|
||||
$(el).text v[k]
|
||||
else
|
||||
el.text = v[k]
|
||||
|
||||
reload: () ->
|
||||
|
||||
init:() ->
|
||||
|
||||
|
||||
itemlayout: () ->
|
||||
{ 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" }
|
||||
] }
|
||||
|
||||
this.OS.GUI.tag.define "afx-blogger-cvsection-item", CVSectionListItemTag
|
||||
|
||||
|
||||
class BlogPostListItemTag extends this.OS.GUI.tag.ListViewItemTag
|
||||
constructor: () ->
|
||||
super()
|
||||
|
||||
ondatachange: (v) ->
|
||||
return unless @data
|
||||
v = @data
|
||||
v.closable = true
|
||||
@closable = v.closable
|
||||
@refs.title.text = v.title
|
||||
@refs.ctimestr.text = __("Created: {0}", v.ctimestr)
|
||||
@refs.utimestr.text = __("Updated: {0}", v.utimestr)
|
||||
|
||||
reload: () ->
|
||||
|
||||
init:() ->
|
||||
|
||||
itemlayout: () ->
|
||||
{ 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" },
|
||||
] }
|
||||
|
||||
this.OS.GUI.tag.define "afx-blogger-post-item", BlogPostListItemTag
|
Reference in New Issue
Block a user