Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45aa257

Browse files
committed
convert to collection-table (wip)
1 parent c78642a commit 45aa257

File tree

4 files changed

+85
-39
lines changed

4 files changed

+85
-39
lines changed

app/client/templates/admin.html

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,23 @@
2525
<a class="ui button" id="flushdb" href="#">FlushDB</a>
2626
</div>
2727
</template>
28+
29+
<template name="admin_error_button">
30+
<button id="errorButton" class="button item" value={{orgLog._id}}>Show Error</button>
31+
</template>
32+
33+
<template name="admin_success_status">
34+
{{#if isSuccess orgLog.statusCode}}
35+
<div class="ui label">
36+
<i class="big green checkmark icon"></i> {{orgLog.statusCode}}
37+
</div>
38+
{{else}}
39+
<div class="ui label">
40+
<i class="big red minus icon"></i> {{orgLog.statusCode}}
41+
</div>
42+
{{/if}}
43+
</template>
44+
2845
<template name="admin_organisations">
29-
<div class="ui raised segment">
30-
<table class="ui fixed celled padded table">
31-
<thead>
32-
<tr>
33-
<th class="fixed">Success</th>
34-
<th>Url</th>
35-
<th>Last Success</th>
36-
<th>Error</th>
37-
</tr>
38-
</thead>
39-
<tbody>
40-
{{#each orgLog in orgLogs}}
41-
<tr class="{{#unless isSucces orgLog.statusCode}} warning {{/unless}}">
42-
<td>
43-
{{#if isSucces orgLog.statusCode}}
44-
<div class="ui label">
45-
<i class="big green checkmark icon"></i> {{orgLog.statusCode}}
46-
</div>
47-
{{else}}
48-
<div class="ui label">
49-
<i class="big red minus icon"></i> {{orgLog.statusCode}}
50-
</div>
51-
{{/if}}
52-
</td>
53-
<td> {{orgLog.url}} </td>
54-
<td> {{orgLog.lastSuccess}} </td>
55-
<td>
56-
{{#unless isSucces orgLog.statusCode}}
57-
<button id="errorButton" class="button item" value={{orgLog._id}}>Show Error</button>
58-
{{/unless}}
59-
</td>
60-
</tr>
61-
{{/each}}
62-
</tbody>
63-
</table>
64-
</div>
46+
{{> collectionTable collection=orgLogs class="table table-bordered table-hover" settings=settings }}
6547
</template>

app/client/templates/admin.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ Template.admin_users.helpers({
5656
});
5757

5858
Template.admin_organisations.helpers({
59+
isSuccess: function(statusCode) {
60+
return 200 == statusCode;
61+
},
62+
63+
settings: function() {
64+
return {
65+
onDelete: function(params) {
66+
Meteor.call('users.remove', params.ids);
67+
},
68+
collection: App.Collections.orgLogs,
69+
rowsPerPage: 10,
70+
showFilter: true,
71+
fields: [
72+
{ key: 'orgLog.statusCode', label: 'Success', tmpl: Template.admin_success_status },
73+
{ key: 'orgLog.lastSuccess', label: 'Last success' },
74+
{ key: 'orgLog.url', label: 'URL' },
75+
{ key: 'orgLog.statusCode', label: 'status code' },
76+
{ key: 'orgLog.error', label: 'Error', tmpl: Template.error_view },
77+
]
78+
};
79+
},
5980
orgLogs: function() {
6081
return App.Collections.OrgLogs.find({}).fetch();
6182
}

app/lib/collections/OrgLogs.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
App.Collections.OrgLogs = new Mongo.Collection('orgLogs');
1+
var OrgLogsSchema = new SimpleSchema({
2+
statusCode: {
3+
type: Number,
4+
optional: true
5+
},
6+
url: {
7+
type: String,
8+
optional: true
9+
},
10+
error: {
11+
type: Object,
12+
optional: true
13+
},
14+
lastSuccess: {
15+
type: Date,
16+
optional: true
17+
},
18+
data: {
19+
type: Object,
20+
optional: true
21+
},
22+
errorMessage: {
23+
type: Object,
24+
optional: true,
25+
defaultValue: {}
26+
}
27+
});
28+
29+
App.Collections.OrgLogs = new Mongo.Collection('orgLogs');
30+
31+
App.Collections.OrgLogs.attachSchema(OrgLogsSchema);

app/server/init.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ function initOrgs() {
2222
// Meteor.defer = Meteor.setTimeout(x, 0)
2323
var url = directory.data[k];
2424

25-
var newLog = { 'statusCode': 200, 'url': url, 'data': {}, 'errorMessage': undefined, 'lastSuccess': undefined };
25+
var newLog = {
26+
'statusCode': 200,
27+
'url': url,
28+
'data': null,
29+
'errorMessage': {},
30+
'lastSuccess': null
31+
};
32+
2633
try {
2734
var result = Meteor.http.call("GET", url);
2835
newLog.data = JSON.parse(result.content);
@@ -41,7 +48,13 @@ function initOrgs() {
4148
if (!oldLog) {
4249
App.Collections.OrgLogs.insert(newLog);
4350
} else {
44-
var toUpdate = { 'statusCode': newLog.statusCode, 'errorMessage': newLog.errorMessage };
51+
var toUpdate = {
52+
'statusCode': newLog.statusCode,
53+
'errorMessage': newLog.errorMessage
54+
};
55+
if(newLog.data instanceof Object) {
56+
toUpdate.data = newLog.data;
57+
}
4558
if(newLog.statusCode == 200){
4659
toUpdate.lastSuccess = new Date();
4760
}

0 commit comments

Comments
 (0)