Skip to content

Commit 56207af

Browse files
committed
save jslog
1 parent a2f77b4 commit 56207af

8 files changed

Lines changed: 100 additions & 2 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ export class DatabaseConnection {
231231
await this.connect();
232232
item = this.ensureResource(item);
233233
this.traversejsonencode(item);
234+
if (jwt === null || jwt === undefined && collectionname === "jslog") {
235+
jwt = TokenUser.rootToken();
236+
}
234237
var user: TokenUser = Crypt.verityToken(jwt);
235238
if (!this.hasAuthorization(user, item, "create")) { throw new Error("Access denied"); }
236239
item._createdby = user.name;

OpenFlow/src/WebSocketClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ export class WebSocketClient {
165165
});
166166
ids.forEach(id => {
167167
var msgs: SocketMessage[] = this._receiveQueue.filter(function (msg: SocketMessage): boolean { return msg.id === id; });
168+
if (this._receiveQueue.length > 100) {
169+
this._logger.error("_receiveQueue containers more than 100 messages for id '" + id + "' so discarding all !!!!!!!");
170+
this._receiveQueue = this._receiveQueue.filter(function (msg: SocketMessage): boolean { return msg.id !== id; });
171+
}
168172
msgs.sort((a, b) => a.index - b.index);
169173
var first: SocketMessage = msgs[0];
170174
if (first.count === msgs.length) {

OpenFlow/src/public/CommonControllers.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,45 @@ module openflow {
1111
export type mapFunc = () => void;
1212
export type reduceFunc = (key: string, values: any[]) => any;
1313
export type finalizeFunc = (key: string, value: any) => any;
14-
14+
const getCircularReplacer = () => {
15+
const seen = new WeakSet();
16+
return (key, value) => {
17+
if (typeof value === "object" && value !== null) {
18+
if (seen.has(value)) {
19+
return;
20+
}
21+
seen.add(value);
22+
}
23+
return value;
24+
};
25+
};
1526
export class api {
1627
static $inject = ["$rootScope", "$location", "WebSocketClient"];
1728
public messageQueue: IHashTable<messagequeue> = {};
1829
constructor(public $rootScope: ng.IRootScopeService, public $location, public WebSocketClient: WebSocketClient) {
30+
var formerlog = console.log.bind(window.console);
31+
var formerwarn = console.warn.bind(window.console);
32+
var formerdebug = console.debug.bind(window.console);
33+
console.log = (msg) => {
34+
formerlog.apply(console, { arguments: arguments });
35+
var log = { message: msg, _type: "message" };
36+
this.Insert("jslog", log);
37+
}
38+
console.warn = (msg) => {
39+
formerwarn.apply(console, { arguments: arguments });
40+
var log = { message: msg, _type: "warning" };
41+
this.Insert("jslog", log);
42+
}
43+
console.debug = (msg) => {
44+
formerdebug.apply(console, { arguments: arguments });
45+
var log = { message: msg, _type: "debug" };
46+
this.Insert("jslog", log);
47+
}
48+
window.onerror = (message, url, linenumber) => {
49+
var log = { message: message, url: url, linenumber: linenumber, _type: "error" };
50+
this.Insert("jslog", log);
51+
}
52+
1953

2054
var cleanup = $rootScope.$on('queuemessage', (event, data: QueueMessage) => {
2155
if (event && data) { }

OpenFlow/src/public/Controllers.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,36 @@ module openflow {
752752
if (!this.$scope.$$phase) { this.$scope.$apply(); }
753753
}
754754
}
755+
756+
export class jslogCtrl extends entitiesCtrl<openflow.Base> {
757+
public loading: boolean = false;
758+
public message: string = "";
759+
public charts: chartset[] = [];
760+
constructor(
761+
public $scope: ng.IScope,
762+
public $location: ng.ILocationService,
763+
public $routeParams: ng.route.IRouteParamsService,
764+
public WebSocketClient: WebSocketClient,
765+
public api: api
766+
) {
767+
super($scope, $location, $routeParams, WebSocketClient, api);
768+
WebSocketClient.onSignedin((user: TokenUser) => {
769+
this.loadData();
770+
});
771+
}
772+
773+
async loadData(): Promise<void> {
774+
this.loading = true;
775+
this.charts = [];
776+
var chart: chartset = null;
777+
console.log("get log");
778+
this.models = await this.api.Query("jslog", {}, null, { _created: -1 });
779+
this.loading = false;
780+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
781+
}
782+
}
783+
784+
755785
export class EntityCtrl extends entityCtrl<openflow.Base> {
756786
public addthis: any = "";
757787
public users: any[] = null;

OpenFlow/src/public/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module openflow {
3636
.when('/Workflows', { templateUrl: 'Workflows.html', controller: WorkflowsCtrl, controllerAs: 'ctrl' })
3737

3838
.when('/Reports', { templateUrl: 'Reports.html', controller: ReportsCtrl, controllerAs: 'ctrl' })
39+
.when('/jslog', { templateUrl: 'jslog.html', controller: jslogCtrl, controllerAs: 'ctrl' })
40+
3941

4042
.when('/Entities/:collection', { templateUrl: 'Entities.html', controller: EntitiesCtrl, controllerAs: 'ctrl' })
4143
.when('/Entity/:collection', { templateUrl: 'Entity.html', controller: EntityCtrl, controllerAs: 'ctrl' })

OpenFlow/src/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<a class="dropdown-item" href="#/Users"><span translate lib="web">users</span></a>
4444
<a class="dropdown-item" href="#/Roles"><span translate lib="web">roles</span></a>
4545
<a class="dropdown-item" href="#/Providers"><span translate lib="web">providers</span></a>
46+
<a class="dropdown-item" href="#/jslog"><span translate lib="web">jslog</span></a>
4647
</div>
4748
</li>
4849
</ul>

OpenFlow/src/public/jslog.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="starter-template">
2+
<h1 translate lib="web">entities</h1>
3+
</div>
4+
<div class="row">
5+
<table id="table1" class="table table-striped" when-scrolled="ctrl.more()" style="width: 100%;">
6+
<thead class="thead-dark">
7+
<tr>
8+
<th ng-click="ctrl.ToggleOrder('_createdby')"><b translate lib="web">createdby</b></th>
9+
<th ng-click="ctrl.ToggleOrder('_created')"><b translate lib="web">created</b></th>
10+
<th></th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<tr ng-repeat="model in ctrl.models">
15+
<td>{{model._createdby}}</td>
16+
<td>
17+
<timesince ng-model="model._created" />
18+
</td>
19+
<td class="btn-cell">
20+
{{model.message}}
21+
</td>
22+
</tr>
23+
</tbody>
24+
</table>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.124
1+
0.0.125

0 commit comments

Comments
 (0)