Link DCAE MOD design tool to Acumos Adapter
[dcaegen2/platform.git] / mod / designtool / designtool-web / src / main / webapp / js / nf / canvas / controllers / nf-ng-canvas-global-menu-controller.js
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Modifications to the original nifi code for the ONAP project are made
18  * available under the Apache License, Version 2.0
19  */
20
21 /* global define, module, require, exports */
22
23 (function (root, factory) {
24     if (typeof define === 'function' && define.amd) {
25         define(['jquery',
26                 'nf.Common',
27                 'nf.QueueListing',
28                 'nf.Shell',
29                 'nf.PolicyManagement',
30                 'nf.ClusterSummary',
31                 'nf.ErrorHandler',
32                 'nf.Settings',
33                 'nf.CanvasUtils'],
34             function ($, nfCommon, nfQueueListing, nfShell, nfPolicyManagement, nfClusterSummary, nfErrorHandler, nfSettings, nfCanvasUtils) {
35                 return (nf.ng.Canvas.GlobalMenuCtrl = factory($, nfCommon, nfQueueListing, nfShell, nfPolicyManagement, nfClusterSummary, nfErrorHandler, nfSettings, nfCanvasUtils));
36             });
37     } else if (typeof exports === 'object' && typeof module === 'object') {
38         module.exports = (nf.ng.Canvas.GlobalMenuCtrl =
39             factory(require('jquery'),
40                 require('nf.Common'),
41                 require('nf.QueueListing'),
42                 require('nf.Shell'),
43                 require('nf.PolicyManagement'),
44                 require('nf.ClusterSummary'),
45                 require('nf.ErrorHandler'),
46                 require('nf.Settings'),
47                 require('nf.CanvasUtils')));
48     } else {
49         nf.ng.Canvas.GlobalMenuCtrl = factory(root.$,
50             root.nf.Common,
51             root.nf.QueueListing,
52             root.nf.Shell,
53             root.nf.PolicyManagement,
54             root.nf.ClusterSummary,
55             root.nf.ErrorHandler,
56             root.nf.Settings,
57             root.nf.CanvasUtils);
58     }
59 }(this, function ($, nfCommon, nfQueueListing, nfShell, nfPolicyManagement, nfClusterSummary, nfErrorHandler, nfSettings, nfCanvasUtils) {
60     'use strict';
61
62     return function (serviceProvider) {
63         'use strict';
64
65         var config = {
66             urls: {
67                 helpDocument: '../nifi-docs/documentation',
68                 controllerAbout: '../nifi-api/flow/about'
69             }
70         };
71
72         function GlobalMenuCtrl(serviceProvider) {
73
74             /**
75              * The summary menu item controller.
76              */
77             this.summary = {
78
79                 /**
80                  * The summary menu item's shell controller.
81                  */
82                 shell: {
83
84                     /**
85                      * Launch the summary shell.
86                      */
87                     launch: function () {
88                         nfShell.showPage('summary');
89                     }
90                 }
91             };
92
93             /**
94              * The counters menu item controller.
95              */
96             this.counters = {
97
98                 /**
99                  * The counters menu item's shell controller.
100                  */
101                 shell: {
102
103                     /**
104                      * Launch the counters shell.
105                      */
106                     launch: function () {
107                         if (nfCommon.canAccessCounters()) {
108                             nfShell.showPage('counters');
109                         }
110                     }
111                 }
112             };
113
114             /**
115              * The bulletin board menu item controller.
116              */
117             this.bulletinBoard = {
118
119                 /**
120                  * The bulletin board menu item's shell controller.
121                  */
122                 shell: {
123
124                     /**
125                      * Launch the bulletin board shell.
126                      */
127                     launch: function () {
128                         nfShell.showPage('bulletin-board');
129                     }
130                 }
131             };
132
133             /**
134              * The data provenance menu item controller.
135              */
136             this.dataProvenance = {
137
138                 /**
139                  * The data provenance menu item's shell controller.
140                  */
141                 shell: {
142
143                     /**
144                      * Launch the data provenance shell.
145                      */
146                     launch: function () {
147                         if (nfCommon.canAccessProvenance()) {
148                             nfShell.showPage('provenance');
149                         }
150                     }
151                 }
152             };
153
154             /**
155              * The controller settings menu item controller.
156              */
157             this.controllerSettings = {
158
159                 /**
160                  * The controller settings menu item's shell controller.
161                  */
162                 shell: {
163
164                     /**
165                      * Launch the settings shell.
166                      */
167                     launch: function () {
168                         nfSettings.showSettings();
169                     }
170                 }
171             };
172
173             /**
174              * The cluster menu item controller.
175              */
176             this.cluster = {
177
178                 /**
179                  * Determines if the cluster menu item is enabled.
180                  *
181                  * @returns {*|boolean}
182                  */
183                 visible: function () {
184                     return nfClusterSummary.isConnectedToCluster();
185                 },
186
187                 /**
188                  * The cluster menu item's shell controller.
189                  */
190                 shell: {
191
192                     /**
193                      * Launch the cluster shell.
194                      */
195                     launch: function () {
196                         if (nfCommon.canAccessController()) {
197                             nfShell.showPage('cluster');
198                         }
199                     }
200                 }
201             };
202
203             /**
204              * The flow config history menu item controller.
205              */
206             this.flowConfigHistory = {
207
208                 /**
209                  * The flow config history menu item's shell controller.
210                  */
211                 shell: {
212
213                     /**
214                      * Launch the history shell.
215                      */
216                     launch: function () {
217                         nfShell.showPage('history');
218                     }
219                 }
220             };
221
222             /**
223              * The users menu item controller.
224              */
225             this.users = {
226
227                 /**
228                  * The users menu item's shell controller.
229                  */
230                 shell: {
231
232                     /**
233                      * Launch the users shell.
234                      */
235                     launch: function () {
236                         if (nfCommon.canAccessTenants()) {
237                             nfShell.showPage('users');
238                         }
239                     }
240                 }
241             };
242
243             /**
244              * The policies menu item controller.
245              */
246             this.policies = {
247
248                 /**
249                  * The policies menu item's shell controller.
250                  */
251                 shell: {
252
253                     /**
254                      * Launch the policies shell.
255                      */
256                     launch: function () {
257                         if (nfCommon.canModifyPolicies() && nfCommon.canAccessTenants()) {
258                             nfPolicyManagement.showGlobalPolicies();
259                         }
260                     }
261                 }
262             };
263
264             /**
265              * The templates menu item controller.
266              */
267             this.templates = {
268
269                 /**
270                  * The templates menu item's shell controller.
271                  */
272                 shell: {
273
274                     /**
275                      * Launch the templates shell.
276                      */
277                     launch: function () {
278                         nfShell.showPage('templates?' + $.param({
279                                 groupId: nfCanvasUtils.getGroupId()
280                             }));
281                     }
282                 }
283             };
284
285             /**
286              * The help menu item controller.
287              */
288             this.help = {
289
290                 /**
291                  * The help menu item's shell controller.
292                  */
293                 shell: {
294
295                     /**
296                      * Launch the help documentation shell.
297                      */
298                     launch: function () {
299                         nfShell.showPage(config.urls.helpDocument);
300                     }
301                 }
302             };
303
304             /**
305              * The about menu item controller.
306              */
307             this.about = {
308
309                 /**
310                  * Initialize the about details.
311                  */
312                 init: function () {
313                     // get the about details
314                     $.ajax({
315                         type: 'GET',
316                         url: config.urls.controllerAbout,
317                         dataType: 'json'
318                     }).done(function (response) {
319                         var aboutDetails = response.about;
320                         // set the document title and the about title
321                         document.title = aboutDetails.title;
322                         $('#nf-version').text(aboutDetails.version);
323                         var showVersionDetail = false;
324                         if (aboutDetails.buildTag && aboutDetails.buildTag !== 'HEAD') {
325                             $('#nf-about-build-tag').text(aboutDetails.buildTag);
326                             $('#nf-version-detail-tag').show();
327                             showVersionDetail = true;
328                         }
329                         if (aboutDetails.buildRevision) {
330                             $('#nf-about-build-revision').text(aboutDetails.buildRevision);
331                             $('#nf-about-build-branch').text(aboutDetails.buildBranch);
332                             $('#nf-version-detail-commit').show();
333                             showVersionDetail = true
334                         }
335                         if (aboutDetails.buildTimestamp) {
336                             $('#nf-about-build-timestamp').text(aboutDetails.buildTimestamp);
337                             $('#nf-version-detail-timestamp').show();
338                             showVersionDetail = true;
339                         }
340                         if (showVersionDetail) {
341                             $('#nf-version-detail').show();
342                         }
343
344                         // store the content viewer url if available
345                         if (!nfCommon.isBlank(aboutDetails.contentViewerUrl)) {
346                             $('#nifi-content-viewer-url').text(aboutDetails.contentViewerUrl);
347                             nfQueueListing.initFlowFileDetailsDialog();
348                         }
349                     }).fail(nfErrorHandler.handleAjaxError);
350
351                     this.modal.init();
352                 },
353
354                 /**
355                  * The about menu item's modal controller.
356                  */
357                 modal: {
358
359                     /**
360                      * Gets the modal element.
361                      *
362                      * @returns {*|jQuery|HTMLElement}
363                      */
364                     getElement: function () {
365                         return $('#nf-about');
366                     },
367
368                     /**
369                      * Initialize the modal.
370                      */
371                     init: function () {
372                         var aboutModal = this;
373
374                         var resizeAbout = function () {
375                             var dialog = $(this);
376                             var top = $('#nf-about-pic-container').height() + $('.dialog-header').height() + 10; //10 for padding-top
377                             dialog.find('.dialog-content').css('top', top);
378                         };
379
380                         this.getElement().modal({
381                             scrollableContentStyle: 'scrollable',
382                             headerText: 'About Apache NiFi',
383                             handler: {
384                                 resize: resizeAbout
385                             },
386                             buttons: [{
387                                 buttonText: 'Ok',
388                                 color: {
389                                     base: '#728E9B',
390                                     hover: '#004849',
391                                     text: '#ffffff'
392                                 },
393                                 handler: {
394                                     click: function () {
395                                         aboutModal.hide();
396                                     }
397                                 }
398                             }]
399                         });
400                     },
401
402                     /**
403                      * Updates the modal config.
404                      *
405                      * @param {string} name             The name of the property to update.
406                      * @param {object|array} config     The config for the `name`.
407                      */
408                     update: function (name, config) {
409                         this.getElement().modal(name, config);
410                     },
411
412                     /**
413                      * Show the modal
414                      */
415                     show: function () {
416                         this.getElement().modal('show');
417                     },
418
419                     /**
420                      * Hide the modal
421                      */
422                     hide: function () {
423                         this.getElement().modal('hide');
424                     }
425                 }
426             };
427
428             /**
429              * The import model menu item controller.
430              */
431             this.importModel = {
432
433                 /**
434                  * The import model menu item's shell controller.
435                  */
436                 shell: {
437
438                     /**
439                      * Launch the import model shell.
440                      */
441                     launch: function () {
442                         $("#model-type").val("-");
443                         nfShell.showContent('#import-model');
444                     }
445                 }
446             };
447
448             /**
449              * The import component specificaton menu item controller.
450              */
451             this.importComponent = {
452
453                 /**
454                  * The import component specification menu item's shell controller.
455                  */
456                 shell: {
457
458                     /**
459                      * Launch the import component shell.
460                      */
461                     launch: function () {
462                         nfShell.showContent('#import-component');
463                     }
464                 }
465             };
466
467             /**
468              * The import data format menu item controller.
469              */
470             this.importDataFormat = {
471
472                 /**
473                  * The import data format menu item's shell controller.
474                  */
475                 shell: {
476
477                     /**
478                      * Launch the import data format shell.
479                      */
480                     launch: function () {
481                         nfShell.showContent('#import-data-format');
482                     }
483                 }
484             };
485         }
486
487         GlobalMenuCtrl.prototype = {
488             constructor: GlobalMenuCtrl,
489
490             /**
491              * Initialize the global menu controls.
492              */
493             init: function () {
494                 this.about.init();
495             }
496         }
497
498         var globalMenuCtrl = new GlobalMenuCtrl();
499         return globalMenuCtrl;
500     };
501 }));