-
-
Notifications
You must be signed in to change notification settings - Fork 487
/
CatController.js
824 lines (759 loc) · 27.3 KB
/
CatController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/
(function() {
goog.provide('gn_cat_controller');
goog.require('gn_admin_menu');
goog.require('gn_external_viewer');
goog.require('gn_history');
goog.require('gn_saved_selections');
goog.require('gn_search_manager');
goog.require('gn_session_service');
goog.require('gn_alert');
var module = angular.module('gn_cat_controller',
['gn_search_manager', 'gn_session_service',
'gn_admin_menu', 'gn_saved_selections',
'gn_external_viewer', 'gn_history', 'gn_alert']);
module.constant('gnSearchSettings', {});
module.constant('gnViewerSettings', {});
module.constant('gnGlobalSettings', function() {
var defaultConfig = {
'langDetector': {
'fromHtmlTag': false,
'regexp': '^(?:\/.+)?/.+\/([a-z]{2,3})\/.+',
'default': 'eng'
},
'nodeDetector': {
'regexp': '^(?:\/.+)?\/(.+)\/[a-z]{2,3}\/.+',
'default': 'srv'
},
'serviceDetector': {
'regexp': '^(?:\/.+)?\/.+\/[a-z]{2,3}\/(.+)',
'default': 'catalog.search'
},
'baseURLDetector': {
'regexp': '^((?:\/.+)?)+\/.+\/[a-z]{2,3}\/.+',
'default': '/geonetwork'
},
'mods': {
'global': {
'humanizeDates': true
},
'footer':{
'enabled': true,
'showSocialBarInFooter': true
},
'header': {
'enabled': true,
'languages': {
'eng': 'en',
'dut': 'nl',
'fre': 'fr',
'ger': 'de',
'kor': 'ko',
'spa': 'es',
'cze': 'cs',
'cat': 'ca',
'fin': 'fi',
'ice': 'is',
'ita': 'it',
'por': 'pt',
'rus': 'ru',
'chi': 'zh',
'slo': 'sk'
},
'isLogoInHeader': false,
'logoInHeaderPosition': 'left',
'fluidHeaderLayout': true,
'showGNName': true,
'isHeaderFixed': false
},
'cookieWarning': {
'enabled': true,
'cookieWarningMoreInfoLink': '',
'cookieWarningRejectLink': ''
},
'home': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.search#/home',
'fluidLayout': true
},
'search': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.search#/search',
'hitsperpageValues': [10, 50, 100],
'paginationInfo': {
'hitsPerPage': 20
},
'facetsSummaryType': 'details',
'defaultSearchString': '',
'facetTabField': '',
'facetConfig': [
// {
// key: 'createDateYear',
// labels: {
// eng: 'Published',
// fre: 'Publication'
// }}
],
'filters': {},
'sortbyValues': [{
'sortBy': 'relevance',
'sortOrder': ''
}, {
'sortBy': 'changeDate',
'sortOrder': ''
}, {
'sortBy': 'title',
'sortOrder': 'reverse'
}, {
'sortBy': 'rating',
'sortOrder': ''
}, {
'sortBy': 'popularity',
'sortOrder': ''
}, {
'sortBy': 'denominatorDesc',
'sortOrder': ''
}, {
'sortBy': 'denominatorAsc',
'sortOrder': 'reverse'
}],
'sortBy': 'relevance',
'resultViewTpls': [{
'tplUrl': '../../catalog/components/' +
'search/resultsview/partials/viewtemplates/grid.html',
'tooltip': 'Grid',
'icon': 'fa-th'
},{
'tplUrl': '../../catalog/components/' +
'search/resultsview/partials/viewtemplates/list.html',
'tooltip': 'List',
'icon': 'fa-bars'
}],
'resultTemplate': '../../catalog/components/' +
'search/resultsview/partials/viewtemplates/grid.html',
'formatter': {
'list': [{
'label': 'defaultView',
'url' : ''
}, {
'label': 'full',
'url' : '/formatters/xsl-view?root=div&view=advanced'
}],
defaultUrl: ''
},
'downloadFormatter': [{
'label': 'exportMEF',
'url': '/formatters/zip?withRelated=false',
'class': 'fa-file-zip-o'
}, {
'label': 'exportPDF',
'url' : '/formatters/xsl-view?output=pdf&language=${lang}',
'class': 'fa-file-pdf-o'
}, {
'label': 'exportXML',
// 'url' : '/formatters/xml?attachment=false',
'url' : '/formatters/xml',
'class': 'fa-file-code-o'
}],
'grid': {
'related': ['parent', 'children', 'services', 'datasets']
},
'linkTypes': {
'links': ['LINK', 'kml'],
'downloads': ['DOWNLOAD'],
'layers': ['OGC', 'ESRI:REST'],
'maps': ['ows']
},
'isFilterTagsDisplayedInSearch': false,
'usersearches': {
'enabled': false,
'displayFeaturedSearchesPanel': false
},
'savedSelection': {
'enabled': true
}
},
'map': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.search#/map',
'externalViewer': {
'enabled': false,
'enabledViewAction': false,
'baseUrl': 'http://www.example.com/viewer',
'urlTemplate': 'http://www.example.com/viewer?url=${service.url}&type=${service.type}&layer=${service.title}&lang=${iso2lang}&title=${md.defaultTitle}',
'openNewWindow': false,
'valuesSeparator': ','
},
'is3DModeAllowed': false,
'isSaveMapInCatalogAllowed': true,
'isExportMapAsImageEnabled': false,
'storage': 'sessionStorage',
'bingKey': '',
'listOfServices': {
'wms': [],
'wmts': []
},
'projection': 'EPSG:3857',
'projectionList': [{
'code': 'urn:ogc:def:crs:EPSG:6.6:4326',
'label': 'WGS84 (EPSG:4326)'
}, {
'code': 'EPSG:3857',
'label': 'Google mercator (EPSG:3857)'
}],
'switcherProjectionList': [{
'code': 'EPSG:3857',
'label': 'Google mercator (EPSG:3857)'
}],
'disabledTools': {
'processes': false,
'addLayers': false,
'projectionSwitcher': false,
'layers': false,
'legend': false,
'filter': false,
'contexts': false,
'print': false,
'mInteraction': false,
'graticule': false,
'syncAllLayers': false,
'drawVector': false
},
'graticuleOgcService': {},
'map-viewer': {
'context': '../../map/config-viewer.xml',
'extent': [0, 0, 0, 0],
'layers': []
},
'map-search': {
'context': '../../map/config-viewer.xml',
'extent': [0, 0, 0, 0],
'layers': []
},
'map-editor': {
'context': '',
'extent': [0, 0, 0, 0],
'layers': [{'type': 'osm'}]
},
'autoFitOnLayer': false
},
'geocoder': {
'enabled': true,
'appUrl': 'https://secure.geonames.org/searchJSON'
},
'recordview': {
'enabled': true,
'isSocialbarEnabled': true
},
'editor': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.edit',
'isUserRecordsOnly': false,
'minUserProfileToCreateTemplate': '',
'isFilterTagsDisplayed': false,
'fluidEditorLayout': true,
'createPageTpl':
'../../catalog/templates/editor/new-metadata-horizontal.html',
'editorIndentType': ''
},
'admin': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/admin.console'
},
'signin': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.signin'
},
'signout': {
'appUrl': '../../signout'
},
'page': {
'enabled': true,
'appUrl': '../../{{node}}/{{lang}}/catalog.search#/page'
}
}
};
return {
proxyUrl: '',
locale: {},
isMapViewerEnabled: false,
requireProxy: [],
gnCfg: angular.copy(defaultConfig),
gnUrl: '',
docUrl: 'https://geonetwork-opensource.org/manuals/3.8.x/',
//docUrl: '../../doc/',
modelOptions: {
updateOn: 'default blur',
debounce: {
default: 300,
blur: 0
}
},
current: null,
isDisableLoginForm: false,
isShowLoginAsLink: false,
init: function(config, gnUrl, gnViewerSettings, gnSearchSettings) {
// start from the default config to make sure every field is present
// and override with config arg if required
angular.merge(this.gnCfg, config, {});
// special case: languages (replace with object from config if available)
if (config && config.mods) {
this.gnCfg.mods.header.languages = angular.extend({
mods: {
header: {
languages: {}
}
}
}, config).mods.header.languages;
}
this.gnUrl = gnUrl || '../';
this.proxyUrl = this.gnUrl + '../proxy?url=';
gnViewerSettings.mapConfig = this.gnCfg.mods.map;
angular.extend(gnSearchSettings, this.gnCfg.mods.search);
this.isMapViewerEnabled = this.gnCfg.mods.map.enabled;
gnViewerSettings.bingKey = this.gnCfg.mods.map.bingKey;
gnViewerSettings.defaultContext =
gnViewerSettings.mapConfig['map-viewer'].context;
gnViewerSettings.geocoder = this.gnCfg.mods.geocoder.appUrl || defaultConfig.mods.geocoder.appUrl;
},
getDefaultConfig: function() {
return angular.copy(defaultConfig);
},
// this returns a copy of the default config without the languages object
// this way, the object can be used as reference for a complete ui
// settings page
getMergeableDefaultConfig: function() {
var copy = angular.copy(defaultConfig);
copy.mods.header.languages = {};
copy.mods.search.grid.related = [];
copy.mods.map["map-editor"].layers = [];
return copy;
},
getProxyUrl: function() {
return this.proxyUrl;
},
// Removes the proxy path and decodes the layer url,
// so the layer can be printed with MapFish.
// Otherwise Mapfish rejects it, due to relative url.
getNonProxifiedUrl: function(url) {
if (url.indexOf(this.proxyUrl) > -1) {
return decodeURIComponent(
url.replace(this.proxyUrl, ''));
} else {
return url;
}
}
};
}());
module.constant('gnLangs', {
langs: {},
current: null,
detectLang: function(detector, gnGlobalSettings) {
// If already detected
if (gnGlobalSettings.iso3lang) {
return gnGlobalSettings.iso3lang;
}
var iso2lang, iso3lang;
// Init language list
this.langs =
gnGlobalSettings.gnCfg.mods.header.languages;
// Detect language from HTML lang tag, regex on URL
if (detector) {
if (detector.fromHtmlTag) {
iso2lang = $('html').attr('lang').substr(0, 2);
} else if (detector.regexp) {
var res = new RegExp(detector.regexp).exec(location.pathname);
if (angular.isArray(res)) {
var urlLang = res[1];
if (this.isValidIso2Lang(urlLang)) {
iso2lang = urlLang;
} else if (this.isValidIso3Lang(urlLang)) {
iso2lang = this.getIso2Lang(urlLang);
} else {
console.warn('URL lang \'' + urlLang +
'\' is not a valid language code.');
}
}
} else if (detector.default) {
iso2lang = detector.default;
}
iso3lang = this.getIso3Lang(iso2lang || detector.default);
}
this.current = iso3lang || 'eng';
// Set locale to global settings. This is
// used by locale loader.
gnGlobalSettings.iso3lang = this.current;
gnGlobalSettings.lang = this.getIso2Lang(this.current);
gnGlobalSettings.locale = {
iso3lang: this.current
};
return this.current;
},
getCurrent: function() {
return this.current;
},
isValidIso3Lang: function(lang) {
return angular.isDefined(this.langs[lang]);
},
isValidIso2Lang: function(lang) {
for (p in this.langs) {
if (this.langs[p] === lang) {
return true;
}
}
return false;
},
getIso2Lang: function(iso3lang) {
return this.langs[iso3lang] || 'en';
},
getIso3Lang: function(iso2lang) {
for (p in this.langs) {
if (this.langs[p] === iso2lang) {
return p;
}
}
return 'eng';
}
});
/**
* The catalogue controller takes care of
* loading site information, check user login state
* and a facet search to get main site information.
*
* A body-level scope makes sense for example:
*
* <body ng-controller="GnCatController">
*/
module.controller('GnCatController', [
'$scope', '$http', '$q', '$rootScope', '$translate',
'gnSearchManagerService', 'gnConfigService', 'gnConfig',
'gnGlobalSettings', '$location', 'gnUtilityService',
'gnSessionService', 'gnLangs', 'gnAdminMenu',
'gnViewerSettings', 'gnSearchSettings', '$cookies',
'gnExternalViewer', 'gnAlertService',
function($scope, $http, $q, $rootScope, $translate,
gnSearchManagerService, gnConfigService, gnConfig,
gnGlobalSettings, $location, gnUtilityService,
gnSessionService, gnLangs, gnAdminMenu,
gnViewerSettings, gnSearchSettings, $cookies,
gnExternalViewer, gnAlertService) {
$scope.version = '0.0.1';
var defaultNode = 'srv';
// Links for social media
$scope.socialMediaLink = $location.absUrl();
$scope.getPermalink = gnUtilityService.getPermalink;
$scope.fluidEditorLayout = gnGlobalSettings.gnCfg.mods.editor.fluidEditorLayout;
$scope.fluidHeaderLayout = gnGlobalSettings.gnCfg.mods.header.fluidHeaderLayout;
$scope.showGNName = gnGlobalSettings.gnCfg.mods.header.showGNName;
$scope.isHeaderFixed = gnGlobalSettings.gnCfg.mods.header.isHeaderFixed;
$scope.isLogoInHeader = gnGlobalSettings.gnCfg.mods.header.isLogoInHeader;
// If gnLangs current already set by config, do not use URL
$scope.langs = gnGlobalSettings.gnCfg.mods.header.languages;
$scope.lang = gnLangs.detectLang(null, gnGlobalSettings);
$scope.iso2lang = gnLangs.getIso2Lang($scope.lang);
$scope.getSocialLinksVisible = function() {
var onMdView = $location.absUrl().indexOf('/metadata/') > -1;
return !onMdView && gnGlobalSettings.gnCfg.mods.footer.showSocialBarInFooter;
};
function detectNode(detector) {
if (detector.regexp) {
var res = new RegExp(detector.regexp).exec(location.pathname);
if (angular.isArray(res)) {
return res[1];
}
}
return detector.default || defaultNode;
}
function detectService(detector) {
if (detector.regexp) {
var res = new RegExp(detector.regexp).exec(location.pathname);
if (angular.isArray(res)) {
return res[1];
}
}
return detector.default;
}
function detectBaseURL(detector) {
if (detector.regexp) {
var res = new RegExp(detector.regexp).exec(location.pathname);
if (angular.isArray(res)) {
return res[1];
}
}
return detector.default || 'geonetwork';
}
$scope.nodeId = detectNode(gnGlobalSettings.gnCfg.nodeDetector);
$scope.isDefaultNode = $scope.nodeId === defaultNode;
$scope.service = detectService(gnGlobalSettings.gnCfg.serviceDetector);
$scope.redirectUrlAfterSign = window.location.href;
gnGlobalSettings.nodeId = $scope.nodeId;
gnConfig.env = gnConfig.env || {};
gnConfig.env.node = $scope.nodeId;
gnConfig.env.defaultNode = defaultNode;
gnConfig.env.baseURL = detectBaseURL(gnGlobalSettings.gnCfg.baseURLDetector);
$scope.signoutUrl = gnGlobalSettings.gnCfg.mods.signout.appUrl
+ '?redirectUrl='
+ window.location.href.slice(
0,
window.location.href.indexOf(gnConfig.env.node) + gnConfig.env.node.length);
// Lang names to be displayed in language selector
$scope.langLabels = {'eng': 'English', 'dut': 'Nederlands',
'fre': 'Français', 'ger': 'Deutsch', 'kor': '한국의',
'spa': 'Español', 'por': 'Portuguesa', 'cat': 'Català', 'cze': 'Czech',
'ita': 'Italiano', 'fin': 'Suomeksi', 'ice': 'Íslenska',
'rus': 'русский', 'chi': '中文', 'slo': 'Slovenčina'};
$scope.url = '';
$scope.gnUrl = gnGlobalSettings.gnUrl;
$scope.gnCfg = gnGlobalSettings.gnCfg;
$scope.proxyUrl = gnGlobalSettings.proxyUrl;
$scope.logoPath = gnGlobalSettings.gnUrl + '../images/harvesting/';
$scope.isMapViewerEnabled = gnGlobalSettings.isMapViewerEnabled;
$scope.isDebug = window.location.search.indexOf('debug') !== -1;
$scope.isDisableLoginForm = gnGlobalSettings.isDisableLoginForm;
$scope.isShowLoginAsLink = gnGlobalSettings.isShowLoginAsLink;
$scope.isExternalViewerEnabled = gnExternalViewer.isEnabled();
$scope.externalViewerUrl = gnExternalViewer.getBaseUrl();
$scope.layout = {
hideTopToolBar: false
};
/**
* CSRF support
*/
//Comment the following lines if you want to remove csrf support
$http.defaults.xsrfHeaderName = 'X-XSRF-TOKEN';
$http.defaults.xsrfCookieName = 'XSRF-TOKEN';
$scope.$watch(function() {
return $cookies.get($http.defaults.xsrfCookieName);
},
function(value) {
$rootScope.csrf = value;
});
//If no csrf, ask for one:
if (!$rootScope.csrf) {
$http.post('info?type=me');
}
//Comment the upper lines if you want to remove csrf support
/**
* Number of selected metadata records.
* Only one selection per session is allowed.
*/
$scope.selectedRecordsCount = 0;
/**
* An ordered list of profiles
*/
$scope.profiles = ['RegisteredUser', 'Editor',
'Reviewer', 'UserAdmin',
'Administrator'];
$scope.info = {};
$scope.user = {};
$rootScope.user = $scope.user;
$scope.authenticated = false;
$scope.initialized = false;
/**
* Keep a reference on main cat scope
* @return {*}
*/
$scope.getCatScope = function() {return $scope};
gnConfigService.load().then(function(c) {
// Config loaded
if (proj4 && angular.isArray(gnConfig['map.proj4js'])) {
angular.forEach(gnConfig['map.proj4js'], function(item) {
proj4.defs(item.code, item.value);
});
ol.proj.proj4.register(proj4);
}
});
// login url for inline signin form in top toolbar
$scope.signInFormAction = '../../signin#' + $location.path();
// when the login input have focus, do not close the dropdown/popup
$scope.focusLoginPopup = function() {
$('.signin-dropdown #inputUsername, .signin-dropdown #inputPassword')
.one('focus', function() {
$(this).parents('.dropdown-menu').addClass('show');
});
$('.signin-dropdown #inputUsername, .signin-dropdown #inputPassword')
.one('blur', function() {
$(this).parents('.dropdown-menu').removeClass('show');
});
};
/**
* Catalog facet summary providing
* a global overview of the catalog content.
*/
$scope.searchInfo = {};
var defaultStatus = {
title: '',
link: '',
msg: '',
error: '',
type: 'info',
timeout: -1
};
$scope.loadCatalogInfo = function() {
var promiseStart = $q.when('start');
// Retrieve site information
// TODO: Add INSPIRE, harvester, ... information
var catInfo = promiseStart.then(function(value) {
return $http.get('../api/site').
success(function(data, status) {
$scope.info = data;
// Add the last time catalog info where updated.
// That could be useful to append to catalog image URL
// in order to trigger a reload of the logo when info are
// reloaded.
$scope.info['system/site/lastUpdate'] = new Date().getTime();
$scope.initialized = true;
}).
error(function(data, status, headers, config) {
$rootScope.$broadcast('StatusUpdated',
{
title: $translate.instant('somethingWrong'),
msg: $translate.instant('msgNoCatalogInfo'),
type: 'danger'});
});
});
// Utility functions for user
var userFn = {
isAnonymous: function() {
return angular.isUndefined(this);
},
isConnected: function() {
return !this.isAnonymous();
},
canCreateTemplate: function() {
var profile = gnGlobalSettings.gnCfg.mods.editor.minUserProfileToCreateTemplate
|| '',
fnName = (profile !== '' ?
('is' + profile[0].toUpperCase() + profile.substring(1) + 'OrMore') :
'');
return angular.isFunction(this[fnName]) ? this[fnName]() : this.isConnected();
},
canEditRecord: function(md) {
if (!md || this.isAnonymous()) {
return false;
}
// The md provide the information about
// if the current user can edit records or not.
var editable = angular.isDefined(md) &&
angular.isDefined(md['geonet:info']) &&
angular.isDefined(md['geonet:info'].edit) &&
md['geonet:info'].edit == 'true';
// A second filter is for harvested record
// if the catalogue admin defined that those
// records could be harvested.
if (md.isHarvested === 'y') {
return gnConfig['system.harvester.enableEditing'] === true &&
editable;
}
return editable;
}
};
// Build is<ProfileName> and is<ProfileName>OrMore functions
// This are not group specific, so not usable on metadata
angular.forEach($scope.profiles, function(profile) {
userFn['is' + profile] = function() {
return profile === this.profile;
};
userFn['is' + profile + 'OrMore'] = function() {
var profileIndex = $scope.profiles.indexOf(profile),
allowedProfiles = [];
angular.copy($scope.profiles, allowedProfiles);
allowedProfiles.splice(0, profileIndex);
return allowedProfiles.indexOf(this.profile) !== -1;
};
}
);
// Retrieve user information if catalog is online
// append a random number to avoid caching in IE11
var userLogin = catInfo.then(function(value) {
return $http.get('../api/me?_random=' +
Math.floor(Math.random() * 10000)).
success(function(me, status) {
if (angular.isObject(me)) {
me['isAdmin'] = function(groupId) {
return me.admin;
}
angular.forEach($scope.profiles, function(profile) {
// Builds is<ProfileName>ForGroup methods
// to check the profile in the group
me['is' + profile + 'ForGroup'] = function(groupId) {
if('Administrator' == profile) {
return me.admin;
}
if(me['groupsWith' + profile] &&
me['groupsWith' + profile].indexOf(Number(groupId)) !== -1) {
return true;
}
return false;
};
});
angular.extend($scope.user, me);
angular.extend($scope.user, userFn);
$scope.authenticated = true;
} else {
$scope.authenticated = false;
$scope.user = undefined;
}
});
});
// Retrieve main search information
var searchInfo = userLogin.then(function(value) {
var url = 'qi?_content_type=json&summaryOnly=true';
angular.forEach(gnGlobalSettings.gnCfg.mods.search.filters,
function(v, k) {
url += '&' + k + '=' + v;
});
return gnSearchManagerService.search(url).
then(function(data) {
$scope.searchInfo = data;
});
});
};
$scope.userAdminMenu = gnAdminMenu.UserAdmin;
$scope.adminMenu = gnAdminMenu.Administrator;
$scope.$on('loadCatalogInfo', function(event, status) {
$scope.loadCatalogInfo();
});
$scope.allowPublishInvalidMd = function() {
return gnConfig['metadata.workflow.allowPublishInvalidMd'];
};
$scope.$on('StatusUpdated', function(event, status) {
var statusToApply = {};
$.extend(statusToApply, defaultStatus, status);
gnAlertService.addAlert(statusToApply, statusToApply.timeout);
});
gnSessionService.scheduleCheck($scope.user);
$scope.session = gnSessionService.getSession();
$scope.loadCatalogInfo();
$scope.healthCheck = {};
function healthCheckStatus(data) {
angular.forEach(data, function(o) {
$scope.healthCheck[o.name] = (o.status === 'OK');
});
};
$http.get('../../warninghealthcheck')
.success(healthCheckStatus)
.error(healthCheckStatus);
}]);
})();