Project

General

Profile

1
var mdstoreInspectorControllers = angular.module('mdstoreInspectorControllers', ['LocalStorageModule']);
2

    
3
function common_init($scope, $http, $sce, $location) {
4
    initSpinner();
5
    $scope.showError = function (error) {
6
        show_notification("error", error);
7
    }
8
    $scope.showNotification = function (message) {
9
        show_notification("info", message);
10
    }
11
    $scope.showSpinner = function () {
12
        showSpinner();
13
    }
14
    $scope.hideSpinner = function () {
15
        hideSpinner();
16
    }
17
    $scope.to_trusted = function (html) {
18
        return $sce.trustAsHtml(html);
19
    }
20
    $scope.go = function (path) {
21
        $location.path(path);
22
    }
23
    $scope.encodeValue = function (val) {
24
        return val;
25
    }
26
}
27

    
28
function ngGridFlexibleHeightPlugin(opts) {
29
    var self = this;
30
    self.grid = null;
31
    self.scope = null;
32
    self.init = function (scope, grid, services) {
33
        self.domUtilityService = services.DomUtilityService;
34
        self.grid = grid;
35
        self.scope = scope;
36
        var recalcHeightForData = function () {
37
            setTimeout(innerRecalcForData, 1);
38
        };
39
        var innerRecalcForData = function () {
40
            var gridId = self.grid.gridId;
41
            var footerPanelSel = '.' + gridId + ' .ngFooterPanel';
42
            var extraHeight = self.grid.$topPanel.height() + $(footerPanelSel).height();
43
            var naturalHeight = self.grid.$canvas.height() + 1;
44
            if (opts != null) {
45
                if (opts.minHeight != null && (naturalHeight + extraHeight) < opts.minHeight) {
46
                    naturalHeight = opts.minHeight - extraHeight - 2;
47
                }
48
                if (opts.maxHeight != null && (naturalHeight + extraHeight) > opts.maxHeight) {
49
                    naturalHeight = opts.maxHeight;
50
                }
51
            }
52

    
53
            var newViewportHeight = naturalHeight + 3;
54
            if (!self.scope.baseViewportHeight || self.scope.baseViewportHeight !== newViewportHeight) {
55
                self.grid.$viewport.css('height', newViewportHeight + 'px');
56
                self.grid.$root.css('height', (newViewportHeight + extraHeight) + 'px');
57
                self.scope.baseViewportHeight = newViewportHeight;
58
                self.domUtilityService.RebuildGrid(self.scope, self.grid);
59
            }
60
        };
61
        self.scope.catHashKeys = function () {
62
            var hash = '',
63
                idx;
64
            for (idx in self.scope.renderedRows) {
65
                hash += self.scope.renderedRows[idx].$$hashKey;
66
            }
67
            return hash;
68
        };
69
        self.scope.$watch('catHashKeys()', innerRecalcForData);
70
        self.scope.$watch(self.grid.config.data, recalcHeightForData);
71
    };
72
}
73

    
74
mdstoreInspectorControllers.directive('compileTemplate', function ($compile, $parse) {
75
    return {
76
        link: function (scope, element, attr) {
77
            var parsed = $parse(attr.ngBindHtml);
78

    
79
            function getStringValue() {
80
                return (parsed(scope) || '').toString();
81
            }
82

    
83
            //Recompile if the template changes
84
            scope.$watch(getStringValue, function () {
85
                $compile(element, null, -9999)(scope);  //The -9999 makes it skip directives so that we do not recompile ourselves
86
            });
87
        }
88
    }
89
});
90

    
91
function hasOwnProperty(obj, prop) {
92
    var proto = obj.__proto__ || obj.constructor.prototype;
93
    return (prop in obj) &&
94
        (!(prop in proto) || proto[prop] !== obj[prop]);
95
}
96

    
97

    
98
mdstoreInspectorControllers.controller('inspectMdstoresController', [
99
    '$scope', '$http', '$sce', '$location', '$routeParams',
100
    function ($scope, $http, $sce, $location, $routeParams) {
101
        common_init($scope, $http, $sce, $location);
102

    
103
        $scope.mdId = $routeParams.id;
104
        $scope.from_page = 0;
105
        $scope.to_page = 0;
106
        $scope.queryValues = {}
107

    
108

    
109

    
110
        $scope.loadInfo = function () {
111
            $scope.showSpinner();
112
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
113
            $http.post('mdstore/getMdStoreInfo.do', $.param({
114
                'id': $routeParams.id
115
            })).success(function (data) {
116
                $scope.hideSpinner();
117
                $scope.mdStoreInfo = data;
118
                if (hasOwnProperty($scope, 'searchResult') == false) {
119
                    $scope.searchResult = {}
120
                }
121
                $scope.queryValues = {"body": "", "id": ""};
122
                if (hasOwnProperty(data, 'indexFields') != false) {
123
                    for (var i = 0; i < data['indexFields'].length; i++) {
124
                        $scope.queryValues[data['indexFields'][i]] = "";
125
                    }
126
                }
127
                $scope.searchResult.total = data.size;
128
            }).error(function () {
129
                $scope.showError('Error getting info from mdstore');
130
                $scope.hideSpinner();
131
            });
132
            $scope.hideSpinner();
133
        }
134

    
135
        $scope.findIndexFields = function (indexField) {
136
            $scope.showSpinner();
137
            if ($scope.query == null) {
138
                if ($scope.searchResult != null)
139
                    $scope.searchResult.total = $scope.mdStoreInfo.size
140
            }
141
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
142
            $http.post('mdstore/findByIndexField', $.param({
143
                'mdId': $routeParams.id, 'from': $scope.from_page, 'query': $scope.query,
144
                'indexField': indexField
145
            })).success(function (data) {
146
                $scope.hideSpinner();
147
                $scope.searchResult.records = data;
148
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
149
            }).error(function () {
150
                $scope.showError('Error getting info from mdstore');
151
                $scope.hideSpinner();
152
            });
153

    
154
        }
155

    
156
        $scope.getResults = function () {
157
            $scope.showSpinner();
158
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
159
            if ($scope.query == null) {
160
                if ($scope.searchResult != null)
161
                    $scope.searchResult.total = $scope.mdStoreInfo.size
162
            }
163
            $http.post('mdstore/mdStoreResults', $.param({
164
                'mdId': $routeParams.id, 'from': $scope.from_page
165
            })).success(function (data) {
166
                $scope.hideSpinner();
167
                $scope.searchResult.records = data.result;
168
                $scope.searchResult.total = data.count;
169
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
170
            }).error(function () {
171
                $scope.showError('Error getting info from mdstore');
172
                $scope.hideSpinner();
173
            });
174
        };
175

    
176

    
177
        $scope.startSearch = function () {
178
            $scope.from_page = 0;
179
            return $scope.searchByQuery()
180
        }
181

    
182
        $scope.searchByQuery = function () {
183
            $scope.showSpinner();
184
            if ($scope.query == null) {
185
                if ($scope.searchResult != null)
186
                    $scope.searchResult.total = $scope.mdStoreInfo.size
187
            }
188
            var query = {};
189
            var setValue;
190
            for (var key in $scope.queryValues) {
191
                if ($scope.queryValues[key].length > 0) {
192
                    query[key] = $scope.queryValues[key];
193
                    setValue = true;
194
                }
195
            }
196
            if (setValue == false)
197
                return $scope.getResults();
198
            query["mdId"] = $routeParams.id;
199
            query["page"] = $scope.from_page;
200
            $http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
201
            $http.post('mdstore/findRecords', query)
202
                .success(function (data) {
203
                    $scope.hideSpinner();
204
                    $scope.searchResult.records = data.result;
205
                    $scope.searchResult.total = data.count;
206
                    $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
207
                }).error(function () {
208
                $scope.showError('Error getting info from mdstore');
209
                $scope.hideSpinner();
210
            });
211
        };
212

    
213
        $scope.getRecordById = function () {
214

    
215
            if (($scope.record_id != null) && ($scope.record_id.length > 0)) {
216
                $scope.showSpinner();
217
            }
218

    
219
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
220
            $http.post('mdstore/mdStoreResults', $.param({
221
                'mdId': $routeParams.id, 'from': $scope.from_page, 'id_query': $scope.record_id
222
            })).success(function (data) {
223
                $scope.hideSpinner();
224
                $scope.searchResult.records = data.records.result;
225
                $scope.searchResult.total = data.records.total;
226
                $scope.to_page = 0
227
                if (data == null) {
228
                    $scope.to_page = 0
229
                    $scope.searchResult.total = 0
230
                }
231
                else {
232
                    $scope.to_page = data.length
233
                    $scope.searchResult.total = data.length
234
                }
235

    
236
            }).error(function () {
237
                $scope.showError('Error getting info from mdstore');
238
                $scope.hideSpinner();
239
            });
240
        };
241

    
242
        $scope.nextPage = function () {
243
            if ($scope.from_page < $scope.searchResult.total - 10) {
244
                $scope.from_page = $scope.from_page + 10;
245
                $scope.searchByQuery();
246
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
247
            }
248

    
249
        };
250

    
251
        $scope.prevPage = function () {
252
            if ($scope.from_page + 10 > 10) {
253
                $scope.from_page = $scope.from_page - 10;
254
                $scope.searchByQuery();
255
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
256
            }
257

    
258
        }
259

    
260
        $scope.loadInfo();
261

    
262
        $scope.getResults();
263
    }]);
264

    
265

    
266
mdstoreInspectorControllers.controller('mdstoresController', [
267
    '$scope', '$http', '$sce', '$location',
268
    function ($scope, $http, $sce, $location) {
269
        common_init($scope, $http, $sce, $location);
270
        $scope.showSpinner();
271
        $http.get('mdstore/listMDStores.do').success(function (data) {
272
            $scope.hideSpinner();
273
            $scope.mdTable = data;
274
        }).error(function () {
275
            $scope.showError('Error listing xmldb collections');
276
            $scope.hideSpinner();
277
        });
278

    
279
        $scope.refreshInfo = function () {
280

    
281
            $scope.showSpinner();
282
            $http.get('mdstore/reloadInfo').success(function (data) {
283
                $scope.hideSpinner();
284
                $scope.mdTable = data;
285
            }).error(function () {
286
                $scope.showError('Error listing xmldb collections');
287
                $scope.hideSpinner();
288
            });
289

    
290
        }
291

    
292
        $scope.gridOptions = {
293
            data: 'mdTable',
294
            enableRowSelection: false,
295
            enableCellEditOnFocus: false,
296
            enableHighlighting: true,
297
            plugins: [new ngGridFlexibleHeightPlugin()],
298

    
299
            columnDefs: [
300
                {field: 'format', displayName: 'Format', width: '55px'},
301
                {field: 'layout', displayName: 'Layout', width: '55px'},
302
                {field: 'interpretation', displayName: 'Interpretation', width: '100px'},
303
                {field: 'lastStorageDate', displayName: 'Last Storage', width: '120px'},
304
                {field: 'size', displayName: 'Size', width: '90px'},
305
                {field: 'serviceURI', displayName: 'Service URI', width: '350px'},
306
                {
307
                    field: 'id',
308
                    displayName: 'profile',
309
                    cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><a href="isManager.do#/profile/{{row.getProperty(col.field)}}" class="btn btn-primary btn-xs" data-placement="top" ><span class="glyphicon glyphicon-zoom-in"></span> profile</button></div>',
310
                    width: '80px',
311
                    headerClass: 'text-center'
312
                },
313
                {
314
                    field: 'id',
315
                    displayName: 'View',
316
                    cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><a href="mdstoreInspector.do#/inspect.do/{{row.getProperty(col.field)}}" class="btn btn-primary btn-xs" data-placement="top" title="{{row.getProperty(col.field)}}"><span class="glyphicon glyphicon-zoom-in"></span> inspect</button></div>',
317
                    width: '80px',
318
                    headerClass: 'text-center'
319
                },
320
                {
321
                    field: 'datasourcesInvolved',
322
                    displayName: 'Datasource',
323
                    cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><b>{{row.getProperty(col.field).datasourceName}}</b> </div>',
324
                    headerClass: 'text-center'
325
                }
326

    
327
            ]
328
        };
329

    
330
    }]);
331

    
332
window.onresize = function () {
333

    
334
    var elem = document.getElementById('gridMdstores');
335
    var height = 0;
336
    var body = window.document.body;
337
    if (window.innerHeight) {
338
        height = window.innerHeight;
339
    } else if (body.parentElement.clientHeight) {
340
        height = body.parentElement.clientHeight;
341
    } else if (body && body.clientHeight) {
342
        height = body.clientHeight;
343
    }
344
    elem.style.height = ((height - elem.offsetTop - 280) + "px");
345

    
346
};
347

    
348

    
(2-2/2)