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
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
104
        $scope.mdId = $routeParams.id;
105
        $scope.from_page = 0;
106
        $scope.to_page = 0;
107
        $scope.loadInfo = function () {
108
            $scope.showSpinner();
109
            $http.post('mdstore/getMdStoreInfo.do', $.param({
110
                'id': $routeParams.id
111
            })).success(function (data) {
112
                $scope.hideSpinner();
113
                $scope.mdStoreInfo = data;
114
                if (hasOwnProperty($scope, 'searchResult') == false) {
115
                    $scope.searchResult = {}
116
                }
117

    
118
                $scope.searchResult.total = data.size;
119
            }).error(function () {
120
                $scope.showError('Error getting info from mdstore');
121
                $scope.hideSpinner();
122
            });
123
            $scope.hideSpinner();
124
        }
125

    
126

    
127
        $scope.findIndexFields = function (indexField) {
128
            $scope.showSpinner();
129
            if ($scope.query == null) {
130
                if ($scope.searchResult != null)
131
                    $scope.searchResult.total = $scope.mdStoreInfo.size
132
            }
133
            $http.post('mdstore/findByIndexField', $.param({
134
                'mdId': $routeParams.id, 'from': $scope.from_page, 'query': $scope.query,
135
                'indexField': indexField
136
            })).success(function (data) {
137
                $scope.hideSpinner();
138
                $scope.searchResult.records = data;
139
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
140
            }).error(function () {
141
                $scope.showError('Error getting info from mdstore');
142
                $scope.hideSpinner();
143
            });
144

    
145
        }
146

    
147
        $scope.getResults = function () {
148
            $scope.showSpinner();
149
            if ($scope.query == null) {
150
                if ($scope.searchResult != null)
151
                    $scope.searchResult.total = $scope.mdStoreInfo.size
152
            }
153
            $http.post('mdstore/mdStoreResults', $.param({
154
                'mdId': $routeParams.id, 'from': $scope.from_page
155
            })).success(function (data) {
156
                $scope.hideSpinner();
157
                $scope.searchResult.records = data;
158
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
159
            }).error(function () {
160
                $scope.showError('Error getting info from mdstore');
161
                $scope.hideSpinner();
162
            });
163
        };
164

    
165

    
166
        $scope.getRecordById = function () {
167

    
168
            if (($scope.record_id != null) && ($scope.record_id.length > 0)) {
169
                $scope.showSpinner();
170
            }
171
            $http.post('mdstore/mdStoreResults', $.param({
172
                'mdId': $routeParams.id, 'from': $scope.from_page, 'id_query': $scope.record_id
173
            })).success(function (data) {
174
                $scope.hideSpinner();
175
                $scope.searchResult.records = data;
176
                $scope.to_page = 0
177
                if (data == null) {
178
                    $scope.to_page = 0
179
                    $scope.searchResult.total = 0
180
                }
181
                else {
182
                    $scope.to_page = data.length
183
                    $scope.searchResult.total = data.length
184
                }
185

    
186
            }).error(function () {
187
                $scope.showError('Error getting info from mdstore');
188
                $scope.hideSpinner();
189
            });
190
        };
191

    
192

    
193
        $scope.nextPage = function () {
194
            if ($scope.from_page < $scope.searchResult.total - 10) {
195
                $scope.from_page = $scope.from_page + 10;
196
                $scope.getResults();
197
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
198
            }
199

    
200
        };
201

    
202
        $scope.prevPage = function () {
203
            if ($scope.from_page + 10 > 10) {
204
                $scope.from_page = $scope.from_page - 10;
205
                $scope.getResults();
206
                $scope.to_page = Math.min($scope.from_page + 10, $scope.searchResult.total);
207
            }
208

    
209
        }
210

    
211
        $scope.loadInfo();
212
        $scope.getResults();
213

    
214

    
215
    }]);
216

    
217

    
218
mdstoreInspectorControllers.controller('mdstoresController', [
219
    '$scope', '$http', '$sce', '$location',
220
    function ($scope, $http, $sce, $location) {
221
        common_init($scope, $http, $sce, $location);
222
        $scope.showSpinner();
223
        $http.get('mdstore/listMDStores.do').success(function (data) {
224
            $scope.hideSpinner();
225
            $scope.mdTable = data;
226
        }).error(function () {
227
            $scope.showError('Error listing xmldb collections');
228
            $scope.hideSpinner();
229
        });
230

    
231

    
232
        $scope.refreshInfo = function () {
233

    
234
            $scope.showSpinner();
235
            $http.get('mdstore/reloadInfo').success(function (data) {
236
                $scope.hideSpinner();
237
                $scope.mdTable = data;
238
            }).error(function () {
239
                $scope.showError('Error listing xmldb collections');
240
                $scope.hideSpinner();
241
            });
242

    
243
        }
244

    
245

    
246
        $scope.gridOptions = {
247
            data: 'mdTable',
248
            enableRowSelection: false,
249
            enableCellEditOnFocus: false,
250
            enableHighlighting: true,
251
            plugins: [new ngGridFlexibleHeightPlugin()],
252

    
253
            columnDefs: [
254
                {field: 'format', displayName: 'Format', width: '55px'},
255
                {field: 'layout', displayName: 'Layout', width: '55px'},
256
                {field: 'interpretation', displayName: 'Interpretation', width: '100px'},
257
                {field: 'lastStorageDate', displayName: 'Last Storage', width: '120px'},
258
                {field: 'size', displayName: 'Size', width: '90px'},
259
                {field: 'serviceURI', displayName: 'Service URI', width: '350px'},
260
                {
261
                    field: 'id',
262
                    displayName: 'profile',
263
                    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>',
264
                    width: '80px',
265
                    headerClass: 'text-center'
266
                },
267
                {
268
                    field: 'id',
269
                    displayName: 'View',
270
                    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>',
271
                    width: '80px',
272
                    headerClass: 'text-center'
273
                },
274
                {
275
                    field: 'datasourcesInvolved',
276
                    displayName: 'Datasource',
277
                    cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><b>{{row.getProperty(col.field).datasourceName}}</b> </div>',
278
                    headerClass: 'text-center'
279
                }
280

    
281
            ]
282
        };
283

    
284

    
285
    }]);
286

    
287
window.onresize = function () {
288

    
289
    var elem = document.getElementById('gridMdstores');
290
    var height = 0;
291
    var body = window.document.body;
292
    if (window.innerHeight) {
293
        height = window.innerHeight;
294
    } else if (body.parentElement.clientHeight) {
295
        height = body.parentElement.clientHeight;
296
    } else if (body && body.clientHeight) {
297
        height = body.clientHeight;
298
    }
299
    elem.style.height = ((height - elem.offsetTop - 280) + "px");
300

    
301
};
302

    
303

    
(2-2/2)