core services renamed to syslog

This commit is contained in:
Xuan Sang LE
2020-05-20 23:11:58 +02:00
parent 33eab1d30a
commit 9008396ac9
28 changed files with 436 additions and 226 deletions

View File

@ -0,0 +1,41 @@
# 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 Calendar extends this.OS.GUI.BaseService
constructor: (args) ->
super "Calendar", args
#@iconclass = "fa fa-commenting"
@text = ""
@iconclass = "fa fa-calendar"
init: ->
#update time each second
@watch 1000, () =>
now = new Date
@text = now.toString()
@domel.set "text", @text
awake: (e) ->
@.openDialog("CalendarDialog" )
.then (d) ->
console.log d
# do nothing
cleanup: (evt) ->
console.log "cleanup for quit"
# do nothing
this.OS.register "Calendar", Calendar

View File

@ -0,0 +1,11 @@
coffee_files = Calendar.coffee PushNotification.coffee Syslog.coffee
jsfiles =
cssfiles = main.css
copyfiles = package.json scheme.html
PKG_NAME=Syslog
include ../pkg.mk

View File

@ -0,0 +1,147 @@
# 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 PushNotification extends this.OS.GUI.BaseService
constructor: (args) ->
super "PushNotification", args
@iconclass = "fa fa-bars"
@cb = undefined
@pending = []
@logs = []
@logmon = undefined
init: ->
@view = false
@_gui.htmlToScheme PushNotification.scheme, @, @host
spin: (b) ->
if b and @iconclass is "fa fa-bars"
@iconclass = "fa fa-spinner fa-spin"
@update()
else if not b and @iconclass is "fa fa-spinner fa-spin"
@iconclass = "fa fa-bars"
@update()
main: ->
@mlist = @find "notifylist"
@mfeed = @find "notifeed"
@nzone = @find "notifyzone"
@fzone = @find "feedzone"
(@find "btclear").set "onbtclick", (e) => @mlist.set "data", []
(@find "bterrlog").set "onbtclick", (e) => @showLogReport()
@subscribe "notification", (o) => @pushout 'INFO', o
@subscribe "fail", (o) => @pushout 'FAIL', o
@subscribe "error", (o) => @pushout 'ERROR', o
@subscribe "info", (o) => @pushout 'INFO', o
@subscribe "loading", (o) =>
@pending.push o.id
@spin true
@subscribe "loaded", (o) =>
i = @pending.indexOf o.id
@pending.splice i, 1 if i >= 0
@spin false if @pending.length is 0
@nzone.set "height", "100%"
@fzone.set "height", "100%"
($ @nzone).css "right", 0
.css "top", "0"
.css "bottom", "0"
.hide()
($ @fzone)
#.css("z-index", 99999)
.css("bottom", "0")
.css "bottom", "0"
.hide()
showLogReport: () ->
@_gui.launch "Syslog"
addLog: (s, o) ->
logtime = new Date()
log = {
type: s,
name: o.name,
text: "#{o.data.m}",
id: o.id,
icon: o.data.icon,
iconclass: o.data.iconclass,
error: o.data.e,
time: logtime,
closable: true,
tag: "afx-bug-list-item"
}
if @logmon
@logmon.addLog log
else
@logs.push log
pushout: (s, o) ->
d = {
text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m}",
icon: o.data.icon,
iconclass: o.data.iconclass,
closable: true
}
@addLog s, o unless s is "INFO"
@mlist.unshift d
@notifeed d
notifeed: (d) ->
@mfeed.unshift d, true
($ @fzone).show()
timer = setTimeout () =>
@mfeed.remove d.domel
($ @fzone).hide() if @mfeed.get("data").length is 0
clearTimeout timer
, 3000
awake: (evt) ->
if @view then ($ @nzone).hide() else ($ @nzone).show()
@view = not @view
if not @cb
@cb = (e) =>
if not ($ e.target).closest($ @nzone).length and not ($ e.target).closest(evt.data.item).length
($ @nzone).hide()
$(document).unbind "click", @cb
@view = not @view
if @view
$(document).on "click", @cb
else
$(document).unbind "click", @cb
cleanup: (evt) ->
# do nothing
PushNotification.scheme = """
<div>
<afx-overlay data-id = "notifyzone" width = "250px">
<afx-hbox data-height="30">
<afx-button text = "__(Clear all)" data-id = "btclear" ></afx-button>
<afx-button iconclass = "fa fa-bug" data-id = "bterrlog" data-width = "25"></afx-button>
</afx-hbox>
<afx-list-view data-id="notifylist"></afx-list-view>
</afx-overlay>
<afx-overlay data-id = "feedzone" width = "250">
<afx-list-view data-id = "notifeed">
</afx-list-view>
</afx-overlay>
</div>
"""
this.OS.register "PushNotification", PushNotification

View File

@ -0,0 +1,105 @@
Ant = this
class BugListItemTag extends Ant.OS.GUI.tag["afx-list-item-proto"]
constructor: (r, o) ->
super r, o
__data__: (v) ->
return unless v
@refs.error.set "text", v.text
@refs.time.set "text", v.time
@refs.error.set "icon", v.icon if v.icon
if not v.icon
@refs.error.set "iconclass", if v.iconclass then v.iconclass else "fa fa-bug"
@set "closable", v.closable
__selected: (v) ->
@get("data").selected = v
itemlayout: () ->
{ el: "div", children: [
{ el: "afx-label", ref: "error", class: "afx-bug-list-item-error" },
{ el: "afx-label", ref: "time", class: "afx-bug-list-item-time" }
] }
Ant.OS.GUI.define "afx-bug-list-item", BugListItemTag
class Syslog extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "Syslog", args
main: () ->
@loglist = @find "loglist"
@logdetail = @find "logdetail"
@_gui.pushService "Syslog/PushNotification"
.then (srv) =>
@srv = srv
@loglist.set "data", @srv.logs if @srv and @srv.logs
@srv.logmon = @
.catch (e) =>
@error __("Unable to load push notification service"), e
@quit()
$(@find("txturi")).val Ant.OS.setting.system.error_report
@loglist.set "onlistselect", (e) =>
data = e.data.item.get("data") if e and e.data
return unless data
stacktrace = "None"
stacktrace = data.error.stack if data.error
$(@logdetail).text Syslog.template.format(
data.text,
data.type,
data.time,
data.name,
data.id,
stacktrace
)
@loglist.set "onitemclose", (e) =>
el = e.data.item if e and e.data
return true unless el
data = el.get "data"
console.log data
return true unless data.selected
$(@logdetail).text("")
return true
@find("btnreport").set "onbtclick", (e) =>
uri = $(@find("txturi")).val()
return if uri is ""
el = @loglist.get "selectedItem"
return unless el
data = el.get("data")
return unless data
Ant.OS.API.post uri, data
.then (d) =>
@notify __("Error reported")
.catch (e) =>
@notify __("Unable to report error: {0}", e.toString())
@find("btclean").set "onbtclick", (e) =>
return unless @srv
@srv.logs = []
@loglist.set "data", @srv.logs
$(@logdetail).text("")
addLog: (log) ->
@loglist.push log
cleanup: () ->
@srv.logmon = undefined if @srv
Syslog.template = """
{0}
Log type: {1}
Log time: {2}
Process: {3} ({4})
detail:
{5}
"""
Syslog.singleton = true
this.OS.register "Syslog", Syslog

View File

@ -0,0 +1,86 @@
afx-overlay[data-id = "notifyzone"]{
/*opacity: 0.85;*/
overflow-y: auto;
overflow-x: hidden;
padding:3px;
margin: 0;
}
afx-overlay[data-id = "notifyzone"] afx-button button{
width: 100%;
border-radius: 0;
}
afx-list-view[data-id = "notifylist"]
{
padding:0;
}
afx-list-view[data-id = "notifylist"] > div.list-container > ul li{
border:1px solid #464646;
border-radius: 3px;
margin-bottom: 5px;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
padding-top: 5px;
padding-bottom: 5px;
}
afx-overlay[data-id = "feedzone"]{
overflow: hidden;
background-color:transparent;
right:5px;
margin: 0;
padding:0;
top:0;
}
afx-list-view[data-id = "notifeed"]
{
padding:0;
margin:0;
}
afx-list-view[data-id = "notifeed"] li{
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.65);
border:1px solid #262626;
border-radius: 6px;
margin-bottom: 2px;
z-index: 99999;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
}
afx-app-window[data-id ='Syslog'] div[data-id ='container']{
overflow: auto;
}
afx-app-window[data-id ='Syslog'] .afx-bug-list-item-error {
display: block;
}
afx-app-window[data-id ='Syslog'] .afx-bug-list-item-error i::before {
color: chocolate;
}
afx-app-window[data-id ='Syslog'] .afx-bug-list-item-time{
display: block;
padding-left: 10px;
}
afx-app-window[data-id ='Syslog'] .afx-bug-list-item-time i.label-text{
font-size: 10px;
font-style: italic;
}
afx-app-window[data-id ='Syslog'] afx-bug-list-item li.selected {
background-color: #116cd6;
color: white;
}
afx-app-window[data-id ='Syslog'] pre {
padding: 10px;
margin:0;
user-select: text;
cursor: text;
}
afx-app-window[data-id ='Syslog'] input{
height: 100%;
}

View File

@ -0,0 +1,17 @@
{
"app":"Syslog",
"pkgname": "Syslog",
"services": [ "Calendar", "PushNotification" ],
"name": "System log",
"description":"Core services and system log",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com",
"credit": "dedicated to some one here",
"licences": "GPLv3"
},
"version":"0.0.1-a",
"category":"System",
"iconclass": "fa fa-bug",
"mimes":[]
}

View File

@ -0,0 +1,21 @@
<afx-app-window data-id="Syslog" width='500' height='350' apptitle = "__(System error log)" >
<afx-hbox>
<afx-list-view data-id = "loglist" data-width="200"> </afx-list-view>
<afx-resizer data-width = "2" />
<afx-vbox>
<div data-id = "container">
<pre><code data-id="logdetail"></code></pre>
</div>
<div data-height="10" />
<afx-hbox style="text-align:right;" data-height = "27">
<afx-button data-width ="20"
tooltip = "ct:__(Clear all logs)" iconclass = "fa fa-trash-o" data-id = "btclean" />
<input type = "text" data-id = "txturi" />
<afx-button data-width ="80" text = "__(Report)"
iconclass = "fa fa-bug" data-id = "btnreport" />
<div data-width="10" />
</afx-hbox>
<div data-height="10" />
</afx-vbox>
</afx-hbox>
</afx-app-window>