2
2
3
3
exports . id = 'logger' ;
4
4
exports . name = 'Logger' ;
5
- exports . group = 'Total.js API ' ;
6
- exports . version = '2 ' ;
7
- exports . icon = 'ti ti-search ' ;
5
+ exports . group = 'Common ' ;
6
+ exports . version = '1 ' ;
7
+ exports . icon = 'ti ti-history ' ;
8
8
exports . author = 'Total.js' ;
9
- exports . config = { token : '' , type : 'info' , message : '' , reference : '' , url : ' ' } ;
9
+ exports . config = { id : 'id ' , name : '{{ data.name }}' , status : 'Step 1 ' } ;
10
10
exports . inputs = [ { id : 'input' , name : 'Input' } ] ;
11
+ exports . outputs = [ { id : 'output' , name : 'Output' } ] ;
11
12
12
13
exports . make = function ( instance , config ) {
13
14
15
+ var Tname ;
16
+
17
+ instance . configure = function ( ) {
18
+ Tname = Tangular . compile ( config . name ) ;
19
+ } ;
20
+
21
+ instance . call = function ( data , callback ) {
22
+ let db = 'nosql/logs' ;
23
+ switch ( data . TYPE ) {
24
+ case 'items' :
25
+ DATA . list ( db ) . autoquery ( data , 'id,name,messageid,status,dtcreated:Date' , 'dtcreated_desc' , 100 ) . callback ( ( err , response ) => callback ( response ) ) ;
26
+ break ;
27
+ case 'remove' :
28
+ DATA . remove ( db ) . id ( data . id ) . callback ( ( err , response ) => callback ( SUCCESS ( response ? true : false ) ) ) ;
29
+ break ;
30
+ case 'clear' :
31
+ DATA . remove ( db ) . callback ( ( ) => callback ( SUCCESS ( true ) ) ) ;
32
+ break ;
33
+ }
34
+ } ;
35
+
14
36
instance . message = function ( $ ) {
15
- var msg = { } ;
16
- msg . schema = instance . main . $schema . name ;
67E6
17
- msg . ip = $ . ip ;
18
- msg . data = JSON . stringify ( $ . data ) ;
19
- msg . url = config . url || instance . href ( ) || CONF . url ;
20
- msg . app = config . name || CONF . name ;
21
- msg . type = config . type ;
22
- msg . message = $ . variables ( config . message ) ;
23
- $ . destroy ( ) ;
24
- TotalAPI ( $ . variables ( config . token ) , 'logger' , msg , function ( err ) {
25
- instance . status ( { response : err ? err . toString ( ) : '' } ) ;
26
- } ) ;
37
+ let id = $ . data [ config . id ] ;
38
+ let name = Tname ( $ ) ;
39
+ DATA . insert ( 'nosql/logs' , { id : UID ( ) , messageid : id , instanceid : instance . id , name : name , status : config . status , dtcreated : new Date ( ) } ) ;
40
+ instance . status ( { date : new Date ( ) , id : id } ) ;
41
+ $ . send ( 'output' ) ;
27
42
} ;
28
43
44
+ instance . configure ( ) ;
29
45
} ;
30
46
31
47
</ script >
32
48
49
+ < readme >
50
+ The component logs information about incoming data.
51
+ </ readme >
52
+
33
53
< style >
34
- .CLASS . error { font-size : 12 px ; padding : 10 px ; color : red ; }
54
+ .CLASS { width : 250 px ; }
35
55
</ style >
36
56
37
- < readme >
38
- The component logs incoming messages into the Total.js Cloud Logger.
39
- </ readme >
57
+ < body >
58
+ < header >
59
+ < button class ="button "> History</ button >
60
+ < i class ="$ICON "> </ i > $NAME
61
+ </ header >
62
+ < footer style ="padding:10px " class ="fs12 ">
63
+ < ui-bind path ="CONFIG.status " config ="text " class ="block b " style ="font-size:16px "> </ ui-bind >
64
+ < hr style ="margin:10px 0 " />
65
+ < ui-bind path ="STATUS " config ="template " class ="block ">
66
+ < script type ="text/html ">
67
+ < div class = "hellip" > Message: { { if value && value . id } } < b > { { value . id } } </ b > { { else } } ---{ { fi } } </ div >
68
+ < div > Last status: { { if value && value . date } } { { value . date | format ( '[ts]' ) } } { { else } } -- - { { fi } } < / d i v >
69
+ </ script >
70
+ </ ui-bind >
71
+ </ footer >
72
+ </ body >
40
73
41
74
< settings >
42
- < div class ="padding bg-smoke ">
43
- < ui-component name ="input " path ="?.token " config ="required:1;camouflage:* "> Total API token</ ui-component >
44
- < div class ="help "> Supports dynamic arguments in the form < code > {key}</ code > </ div >
45
- </ div >
46
75
< div class ="padding ">
47
- < div class ="row ">
48
- < div class ="col-md-3 m ">
49
- < ui-component name ="input " path ="?.type " config ="dirsource:info|Info,error|Error,warning|Warning,success|Success;required :1 "> Type </ ui-component >
76
+ < div class ="grid-3 ">
77
+ < div class ="m ">
78
+ < ui-component name ="input " path ="?.id " config ="required:1;monospace :1 "> Message ID </ ui-component >
50
79
</ div >
51
- < div class ="col-md-3 m ">
52
- < ui-component name ="input " path ="?.app " > App name</ ui-component >
80
+ < div class ="m ">
81
+ < ui-component name ="input " path ="?.name " config =" required:1;monospace:1 " > Snapshot name</ ui-component >
53
82
</ div >
54
- < div class ="col-md-3 m ">
55
- < ui-component name ="input " path ="?.reference "> Reference</ ui-component >
56
- </ div >
57
- < div class ="col-md-3 m ">
58
- < ui-component name ="input " path ="?.url "> URL address</ ui-component >
83
+ < div class ="m ">
84
+ < ui-component name ="input " path ="?.status " config ="required:1 "> Snapshot status</ ui-component >
59
85
</ div >
60
86
</ div >
61
- < ui-component name ="input " path ="?.message " config ="required:1;maxlength:200 "> Message</ ui-component >
62
- < div class ="help "> Supports dynamic arguments in the form < code > {key}</ code > </ div >
63
87
</ div >
64
88
</ settings >
65
89
66
- < body >
67
- < header >
68
- < i class ="ICON "> </ i > NAME
69
- </ header >
70
- < footer >
71
- < ui-bind path ="!STATUS.response " config ="text;show " class ="error hidden "> </ ui-bind >
72
- </ footer >
73
- </ body >
90
+ < script >
91
+
92
+ TOUCH ( function ( exports , reinit ) {
93
+
94
+ var services = [ ] ;
95
+ var Path = 'loggerbox' ;
96
+
97
+ if ( ! PLUGINS [ Path ] ) {
98
+
99
+ PLUGIN ( Path , function ( exports ) {
100
+
101
+ exports . reload = function ( com ) {
102
+ if ( exports . model . data )
103
+ exports . refresh ( ) ;
104
+ } ;
105
+
106
+ exports . refresh = function ( ) {
107
+ exports . nul ( 'data' ) ;
108
+ } ;
109
+
110
+ exports . filter = function ( type , filter , sort , page ) {
111
+ var model = GET ( Path ) ;
112
+ if ( ! filter )
113
+ filter = { } ;
114
+ filter . TYPE = 'items' ;
115
+ filter . page = page ;
116
+ filter . sort = sort ;
117
+ model . instance . call ( filter , response => SET ( Path + '.data' , response ) ) ;
118
+ } ;
119
+
120
+ exports . button = function ( name , row ) {
121
+ SETTER ( 'approve/show' , 'Are you sure you want to remove selected log?' , ':remove: Remove' , function ( ) {
122
+ var model = GET ( Path ) ;
123
+ model . instance . call ( { TYPE : 'remove' , id : ATTRD ( row ) } , function ( response ) {
124
+ if ( response . success ) {
125
+ SETTER ( 'notify/success' , 'Removed.' ) ;
126
+ exports . refresh ( ) ;
127
+ } else
128
+ SETTER ( 'notify/warning' , 'Log not found in database.' ) ;
129
+ } ) ;
130
+ } ) ;
131
+ } ;
132
+
133
+ exports . clear = function ( ) {
134
+ SETTER ( 'approve/show' , 'Are you sure you want to clear all logs?' , ':remove: Clear' , function ( ) {
135
+ var model = GET ( Path ) ;
136
+ model . instance . call ( { TYPE : 'clear' } , function ( response ) {
137
+ SETTER ( 'notify/success' , 'Cleared.' ) ;
138
+ exports . refresh ( ) ;
139
+ } ) ;
140
+ } ) ;
141
+ } ;
142
+ } ) ;
143
+
144
+ $ ( 'body' ) . append ( ( '<ui-component name="box" path="*form" config="if:{0};width:940;scrollbar:0;title:Snapshots;icon:ti ti-save;reload:?/reload" plugin="{0}"><nav><button class="exec" data-exec="?/clear"><i class="ti ti-clean red"></i>Clear</button></nav><div><ui-component name="datagrid" path="?.data" config="height:.ui-box-body;margin:1;checkbox:0;click:?/click;exec:?/filter;noborder:1;button:?/button"><scri' + 'pt type="text/plain">[{ name: "messageid", text: "Message", width: 150, monospace: 1 },{ name: "status", text: "Status", width: 200 },{ name: "name", text: "Name", width: 300 },{ name: "dtcreated", text: "Created", type: "date", format: "[ts]" }, { type: "controls", template: "<button name=\\\"remove\\\"><i class=\\\"ti ti-trash red\\\"></i></button>" }]</scr' + 'ipt></ui-component></div><nav><button name="cancel" style="width:100%">Close</button></nav></ui-component>' ) . format ( Path ) ) ;
145
+ }
146
+
147
+ exports . element . on ( 'click' , 'button' , function ( ) {
148
+ SET ( Path , { id : exports . id , config : exports . config , instance : exports } ) ;
149
+ SET ( '*form' , Path ) ;
150
+ } ) ;
151
+
152
+ } ) ;
153
+
154
+ </ script >
0 commit comments