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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Modifications to the original nifi code for the ONAP project are made
18 * available under the Apache License, Version 2.0
21 /* global define, module, require, exports */
23 (function (root, factory) {
24 if (typeof define === 'function' && define.amd) {
27 function ($, nfCommon) {
28 return (nf.ng.BreadcrumbsCtrl = factory($, nfCommon));
30 } else if (typeof exports === 'object' && typeof module === 'object') {
31 module.exports = (nf.ng.BreadcrumbsCtrl =
32 factory(require('jquery'),
33 require('nf.Common')));
35 nf.ng.BreadcrumbsCtrl = factory(root.$,
38 }(this, function ($, nfCommon) {
41 return function (serviceProvider) {
44 function BreadcrumbsCtrl() {
45 this.breadcrumbs = [];
48 BreadcrumbsCtrl.prototype = {
49 constructor: BreadcrumbsCtrl,
52 * Register the breadcrumbs controller.
54 register: function () {
55 if (serviceProvider.breadcrumbsCtrl === undefined) {
56 serviceProvider.register('breadcrumbsCtrl', breadcrumbsCtrl);
61 * Generate the breadcrumbs.
63 * @param {object} breadcrumbEntity The breadcrumb
65 generateBreadcrumbs: function (breadcrumbEntity) {
66 var label = breadcrumbEntity.id;
67 if (breadcrumbEntity.permissions.canRead) {
68 label = breadcrumbEntity.breadcrumb.name;
71 this.breadcrumbs.unshift($.extend({
73 }, breadcrumbEntity));
75 if (nfCommon.isDefinedAndNotNull(breadcrumbEntity.parentBreadcrumb)) {
76 this.generateBreadcrumbs(breadcrumbEntity.parentBreadcrumb);
81 * Updates the version control information for the specified process group.
83 * @param processGroupId
84 * @param versionControlInformation
86 updateVersionControlInformation: function (processGroupId, versionControlInformation) {
87 $.each(this.breadcrumbs, function (_, breadcrumbEntity) {
88 if (breadcrumbEntity.id === processGroupId) {
89 breadcrumbEntity.breadcrumb.versionControlInformation = versionControlInformation;
96 * Reset the breadcrumbs.
98 resetBreadcrumbs: function () {
99 this.breadcrumbs = [];
103 * Whether this crumb is tracking.
105 * @param breadcrumbEntity
108 isTracking: function (breadcrumbEntity) {
109 return nfCommon.isDefinedAndNotNull(breadcrumbEntity.versionedFlowState);
113 * Returns the class string to use for the version control of the specified breadcrumb.
115 * @param breadcrumbEntity
118 getVersionControlClass: function (breadcrumbEntity) {
119 if (nfCommon.isDefinedAndNotNull(breadcrumbEntity.versionedFlowState)) {
120 var vciState = breadcrumbEntity.versionedFlowState;
121 if (vciState === 'SYNC_FAILURE') {
122 console.log("it is been sync failed..000");
123 $('#environmentType').prop('disabled', true);
124 if($('#environmentType').val() && !$('#environmentType').prop('disabled')){
125 $('#operate-submit-btn').prop('disabled', false);
126 }else{$('#operate-submit-btn').prop('disabled', true);}
128 return 'breadcrumb-version-control-gray fa fa-question'
129 } else if (vciState === 'LOCALLY_MODIFIED_AND_STALE') {
130 console.log("it is been locally modified and stale...000");
131 $('#environmentType').prop('disabled', true);
132 if($('#environmentType').val() && !$('#environmentType').prop('disabled')){
133 $('#operate-submit-btn').prop('disabled', false);
134 }else{$('#operate-submit-btn').prop('disabled', true);}
136 return 'breadcrumb-version-control-red fa fa-exclamation-circle';
137 } else if (vciState === 'STALE') {
138 console.log("it is been stale...000");
139 $('#environmentType').prop('disabled', true);
140 if($('#environmentType').val() && !$('#environmentType').prop('disabled')){
141 $('#operate-submit-btn').prop('disabled', false);
142 }else{$('#operate-submit-btn').prop('disabled', true);}
144 return 'breadcrumb-version-control-red fa fa-arrow-circle-up';
145 } else if (vciState === 'LOCALLY_MODIFIED') {
146 console.log("it is been locally modified...000");
147 $('#environmentType').prop('disabled', true);
148 if($('#environmentType').val() && !$('#environmentType').prop('disabled')){
149 $('#operate-submit-btn').prop('disabled', false);
150 }else{$('#operate-submit-btn').prop('disabled', true);}
152 return 'breadcrumb-version-control-gray fa fa-asterisk';
154 $('#environmentType').prop('disabled', false);
155 if($('#environmentType').val() && !$('#environmentType').prop('disabled')){
156 $('#operate-submit-btn').prop('disabled', false);
157 }else{$('#operate-submit-btn').prop('disabled', true);}
158 return 'breadcrumb-version-control-green fa fa-check';
161 console.log("it is NOT been version controlled...000");
162 $('#environmentType').prop('disabled', true);
168 * Gets the content for the version control tooltip for the specified breadcrumb.
170 * @param breadcrumbEntity
172 getVersionControlTooltip: function (breadcrumbEntity) {
173 if (nfCommon.isDefinedAndNotNull(breadcrumbEntity.versionedFlowState) && breadcrumbEntity.permissions.canRead) {
174 return nfCommon.getVersionControlTooltip(breadcrumbEntity.breadcrumb.versionControlInformation);
176 return 'This Process Group is not under version control.'
181 * Get the breadcrumbs.
183 getBreadcrumbs: function () {
184 return this.breadcrumbs;
188 * Update the breadcrumbs css.
190 * @param {object} style The style to be applied.
192 updateBreadcrumbsCss: function (style) {
193 $('#breadcrumbs').css(style);
197 * Reset initial scroll position.
199 resetScrollPosition: function () {
200 var title = $('#data-flow-title-container');
201 var titlePosition = title.position();
202 var titleWidth = title.outerWidth();
203 var titleRight = titlePosition.left + titleWidth;
205 var padding = $('#breadcrumbs-right-border').width();
206 var viewport = $('#data-flow-title-viewport');
207 var viewportWidth = viewport.width();
208 var viewportRight = viewportWidth - padding;
210 // if the title's right is past the viewport's right, shift accordingly
211 if (titleRight > viewportRight) {
212 // adjust the position
213 title.css('left', (titlePosition.left - (titleRight - viewportRight)) + 'px');
215 title.css('left', '10px');
220 * Registers a scroll event on the `element`
222 * @param {object} element The element event listener will be registered upon.
224 registerMouseWheelEvent: function (element) {
225 // mousewheel -> IE, Chrome
226 // DOMMouseScroll -> FF
229 // still having issues with this in IE :/
230 element.on('DOMMouseScroll mousewheel', function (evt, d) {
231 if (nfCommon.isUndefinedOrNull(evt.originalEvent)) {
235 var title = $('#data-flow-title-container');
236 var titlePosition = title.position();
237 var titleWidth = title.outerWidth();
238 var titleRight = titlePosition.left + titleWidth;
240 var padding = $('#breadcrumbs-right-border').width();
241 var viewport = $('#data-flow-title-viewport');
242 var viewportWidth = viewport.width();
243 var viewportRight = viewportWidth - padding;
245 // if the width of the title is larger than the viewport
246 if (titleWidth > viewportWidth) {
251 //Chrome and Safari both have evt.originalEvent.detail defined but
252 //evt.originalEvent.wheelDelta holds the correct value so we must
253 //check for evt.originalEvent.wheelDelta first!
254 if (nfCommon.isDefinedAndNotNull(evt.originalEvent.wheelDelta)) {
255 delta = evt.originalEvent.wheelDelta;
256 } else if (nfCommon.isDefinedAndNotNull(evt.originalEvent.detail)) {
257 delta = -evt.originalEvent.detail;
260 // determine the increment
261 if (delta > 0 && titleRight > viewportRight) {
264 } else if (delta < 0 && (titlePosition.left - padding) < 0) {
267 // don't shift too far
268 if (titlePosition.left + increment > padding) {
269 increment = padding - titlePosition.left;
276 // adjust the position
277 title.css('left', (titlePosition.left + increment) + 'px');
284 var breadcrumbsCtrl = new BreadcrumbsCtrl();
285 breadcrumbsCtrl.register();
286 return breadcrumbsCtrl;