summary.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * 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, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.MainServiceInfoSummaryController = Em.Controller.extend({
  19. name: 'mainServiceInfoSummaryController',
  20. selectedFlumeAgent: null,
  21. /**
  22. * Indicates whether Ranger plugins status update polling is active
  23. * @type {boolean}
  24. */
  25. isRangerUpdateWorking: false,
  26. /**
  27. * Indicates whether array with initial Ranger plugins data is set
  28. * @type {boolean}
  29. */
  30. isRangerPluginsArraySet: false,
  31. /**
  32. * Indicates whether previous AJAX request for Ranger plugins config properties has failed
  33. * @type {boolean}
  34. */
  35. isPreviousRangerConfigsCallFailed: false,
  36. /**
  37. * UI section name
  38. */
  39. sectionName: function () {
  40. return this.get('content.serviceName') + "_SUMMARY";
  41. }.property('content.serviceName'),
  42. /**
  43. * UI default layout name
  44. */
  45. defaultLayoutName: function () {
  46. return "default_" + this.get('content.serviceName').toLowerCase() + "_dashboard";
  47. }.property('content.serviceName'),
  48. /**
  49. * Does Service has widget descriptor defined in the stack
  50. * @type {boolean}
  51. */
  52. isServiceWithEnhancedWidgets: function () {
  53. var serviceName = this.get('content.serviceName');
  54. var stackService = App.StackService.find().findProperty('serviceName', serviceName);
  55. return stackService.get('isServiceWithWidgets') && App.supports.customizedWidgets;
  56. }.property('content.serviceName'),
  57. /**
  58. * Ranger plugins data
  59. * @type {array}
  60. */
  61. rangerPlugins: [
  62. {
  63. serviceName: 'HDFS',
  64. type: 'ranger-hdfs-plugin-properties',
  65. propertyName: 'ranger-hdfs-plugin-enabled'
  66. },
  67. {
  68. serviceName: 'HIVE',
  69. type: 'ranger-hive-plugin-properties',
  70. propertyName: 'ranger-hive-plugin-enabled'
  71. },
  72. {
  73. serviceName: 'HBASE',
  74. type: 'ranger-hbase-plugin-properties',
  75. propertyName: 'ranger-hbase-plugin-enabled'
  76. },
  77. {
  78. serviceName: 'KNOX',
  79. type: 'ranger-knox-plugin-properties',
  80. propertyName: 'ranger-knox-plugin-enabled'
  81. },
  82. {
  83. serviceName: 'STORM',
  84. type: 'ranger-storm-plugin-properties',
  85. propertyName: 'ranger-storm-plugin-enabled'
  86. }
  87. ],
  88. /**
  89. * Set initial Ranger plugins data
  90. * @method setRangerPlugins
  91. */
  92. setRangerPlugins: function () {
  93. if (App.get('router.clusterController.isLoaded') && !this.get('isRangerPluginsArraySet')) {
  94. this.setProperties({
  95. rangerPlugins: this.get('rangerPlugins').map(function (item) {
  96. var stackService = App.StackService.find().findProperty('serviceName', item.serviceName);
  97. var displayName = (stackService) ? stackService.get('displayName') : item.serviceName;
  98. return $.extend(item, {
  99. pluginTitle: Em.I18n.t('services.service.summary.ranger.plugin.title').format(displayName),
  100. isDisplayed: App.Service.find().someProperty('serviceName', item.serviceName),
  101. status: Em.I18n.t('services.service.summary.ranger.plugin.loadingStatus')
  102. });
  103. }),
  104. isRangerPluginsArraySet: true
  105. });
  106. }
  107. }.observes('App.router.clusterController.isLoaded'),
  108. /**
  109. * Get latest config tags
  110. * @method updateRangerPluginsStatus
  111. * @param callback
  112. */
  113. updateRangerPluginsStatus: function (callback) {
  114. App.ajax.send({
  115. name: 'config.tags',
  116. sender: this,
  117. success: 'getRangerPluginsStatus',
  118. callback: callback
  119. });
  120. },
  121. /**
  122. * Get latest Ranger plugins config properties
  123. * @method getRangerPluginsStatus
  124. * @param data
  125. */
  126. getRangerPluginsStatus: function (data) {
  127. var urlParams = [];
  128. this.get('rangerPlugins').forEach(function (item) {
  129. if (App.Service.find().someProperty('serviceName', item.serviceName)) {
  130. var currentTag = data.Clusters.desired_configs[item.type].tag;
  131. var isTagChanged = item.tag != currentTag;
  132. Em.set(item, 'isDisplayed', true);
  133. //Request for properties should be sent either if configs have changed or if previous Ranger plugins config properties has failed
  134. if (isTagChanged || this.get('isPreviousRangerConfigsCallFailed')) {
  135. Em.set(item, 'tag', currentTag);
  136. urlParams.push('(type=' + item.type + '&tag=' + currentTag + ')');
  137. }
  138. } else {
  139. Em.set(item, 'isDisplayed', false);
  140. }
  141. }, this);
  142. if (urlParams.length) {
  143. App.ajax.send({
  144. name: 'reassign.load_configs',
  145. sender: this,
  146. data: {
  147. urlParams: urlParams.join('|')
  148. },
  149. success: 'getRangerPluginsStatusSuccess',
  150. error: 'getRangerPluginsStatusError'
  151. });
  152. }
  153. },
  154. /**
  155. * Set Ranger plugins statuses
  156. * @method getRangerPluginsStatusSuccess
  157. * @param data
  158. */
  159. getRangerPluginsStatusSuccess: function (data) {
  160. this.set('isPreviousRangerConfigsCallFailed', false);
  161. data.items.forEach(function (item) {
  162. var serviceName = this.get('rangerPlugins').findProperty('type', item.type).serviceName;
  163. var propertyName = this.get('rangerPlugins').findProperty('type', item.type).propertyName;
  164. var statusMap = {
  165. Yes: 'alerts.table.state.enabled',
  166. No: 'alerts.table.state.disabled'
  167. };
  168. var statusString = statusMap[item.properties[propertyName]] || 'common.unknown';
  169. Em.set(this.get('rangerPlugins').findProperty('serviceName', serviceName), 'status', Em.I18n.t(statusString));
  170. }, this);
  171. },
  172. /**
  173. * Method executed if Ranger plugins config properties request has failed
  174. * @method getRangerPluginsStatusError
  175. */
  176. getRangerPluginsStatusError: function () {
  177. this.set('isPreviousRangerConfigsCallFailed', true);
  178. },
  179. /**
  180. * Send start command for selected Flume Agent
  181. * @method startFlumeAgent
  182. */
  183. startFlumeAgent: function () {
  184. var selectedFlumeAgent = arguments[0].context;
  185. if (selectedFlumeAgent && selectedFlumeAgent.get('status') === 'NOT_RUNNING') {
  186. var self = this;
  187. App.showConfirmationPopup(function () {
  188. var state = 'STARTED';
  189. var context = Em.I18n.t('services.service.summary.flume.start.context').format(selectedFlumeAgent.get('name'));
  190. self.sendFlumeAgentCommandToServer(state, context, selectedFlumeAgent);
  191. });
  192. }
  193. },
  194. /**
  195. * Send stop command for selected Flume Agent
  196. * @method stopFlumeAgent
  197. */
  198. stopFlumeAgent: function () {
  199. var selectedFlumeAgent = arguments[0].context;
  200. if (selectedFlumeAgent && selectedFlumeAgent.get('status') === 'RUNNING') {
  201. var self = this;
  202. App.showConfirmationPopup(function () {
  203. var state = 'INSTALLED';
  204. var context = Em.I18n.t('services.service.summary.flume.stop.context').format(selectedFlumeAgent.get('name'));
  205. self.sendFlumeAgentCommandToServer(state, context, selectedFlumeAgent);
  206. });
  207. }
  208. },
  209. /**
  210. * Send command for Flume Agent to server
  211. * @param {string} state
  212. * @param {string} context
  213. * @param {Object} agent
  214. * @method sendFlumeAgentCommandToServer
  215. */
  216. sendFlumeAgentCommandToServer: function (state, context, agent) {
  217. App.ajax.send({
  218. name: 'service.flume.agent.command',
  219. sender: this,
  220. data: {
  221. state: state,
  222. context: context,
  223. agentName: agent.get('name'),
  224. host: agent.get('hostName')
  225. },
  226. success: 'commandSuccessCallback'
  227. });
  228. },
  229. /**
  230. * Callback, that shows Background operations popup if request was successful
  231. */
  232. commandSuccessCallback: function () {
  233. console.log('Send request for refresh configs successfully');
  234. // load data (if we need to show this background operations popup) from persist
  235. App.router.get('applicationController').dataLoading().done(function (showPopup) {
  236. if (showPopup) {
  237. App.router.get('backgroundOperationsController').showPopup();
  238. }
  239. });
  240. },
  241. gotoConfigs: function () {
  242. App.router.get('mainServiceItemController').set('routeToConfigs', true);
  243. App.router.transitionTo('main.services.service.configs', this.get('content'));
  244. App.router.get('mainServiceItemController').set('routeToConfigs', false);
  245. },
  246. showServiceAlertsPopup: function (event) {
  247. var service = event.context;
  248. return App.ModalPopup.show({
  249. header: Em.I18n.t('services.service.summary.alerts.popup.header').format(service.get('displayName')),
  250. autoHeight: false,
  251. classNames: ['forty-percent-width-modal'],
  252. bodyClass: Em.View.extend({
  253. templateName: require('templates/main/service/info/service_alert_popup'),
  254. classNames: ['service-alerts'],
  255. controllerBinding: 'App.router.mainAlertDefinitionsController',
  256. didInsertElement: function () {
  257. Em.run.next(this, function () {
  258. App.tooltip($(".timeago"));
  259. });
  260. },
  261. alerts: function () {
  262. var serviceDefinitions = this.get('controller.content').filterProperty('service', service);
  263. // definitions should be sorted in order: critical, warning, ok, unknown, other
  264. var criticalDefinitions = [], warningDefinitions = [], okDefinitions = [], unknownDefinitions = [];
  265. serviceDefinitions.forEach(function (definition) {
  266. if (definition.get('isCritical')) {
  267. criticalDefinitions.push(definition);
  268. serviceDefinitions = serviceDefinitions.without(definition);
  269. } else if (definition.get('isWarning')) {
  270. warningDefinitions.push(definition);
  271. serviceDefinitions = serviceDefinitions.without(definition);
  272. } else if (definition.get('isOK')) {
  273. okDefinitions.push(definition);
  274. serviceDefinitions = serviceDefinitions.without(definition);
  275. } else if (definition.get('isUnknown')) {
  276. unknownDefinitions.push(definition);
  277. serviceDefinitions = serviceDefinitions.without(definition);
  278. }
  279. });
  280. serviceDefinitions = criticalDefinitions.concat(warningDefinitions, okDefinitions, unknownDefinitions, serviceDefinitions);
  281. return serviceDefinitions;
  282. }.property('controller.content'),
  283. gotoAlertDetails: function (event) {
  284. if (event && event.context) {
  285. this.get('parentView').hide();
  286. App.router.transitionTo('main.alerts.alertDetails', event.context);
  287. }
  288. },
  289. closePopup: function () {
  290. this.get('parentView').hide();
  291. }
  292. }),
  293. isHideBodyScroll: false,
  294. primary: Em.I18n.t('common.close'),
  295. secondary: null
  296. });
  297. },
  298. /**
  299. * @type {boolean}
  300. */
  301. isWidgetsLoaded: false,
  302. /**
  303. * @type {boolean}
  304. */
  305. isWidgetLayoutsLoaded: false,
  306. /**
  307. * @type {boolean}
  308. */
  309. isAllSharedWidgetsLoaded: false,
  310. /**
  311. * @type {boolean}
  312. */
  313. isMineWidgetsLoaded: false,
  314. /**
  315. * @Type {App.WidgetLayout}
  316. */
  317. activeWidgetLayout: {},
  318. /**
  319. * @type {Em.A}
  320. */
  321. widgets: function () {
  322. if (this.get('isWidgetsLoaded')) {
  323. if (this.get('activeWidgetLayout.widgets')) {
  324. return this.get('activeWidgetLayout.widgets').toArray();
  325. } else {
  326. return [];
  327. }
  328. }
  329. }.property('isWidgetsLoaded'),
  330. /**
  331. * @type {Em.A}
  332. */
  333. widgetLayouts: function () {
  334. return App.WidgetLayout.find();
  335. }.property('isWidgetLayoutsLoaded'),
  336. /**
  337. * load widget layouts across all users in CLUSTER scope
  338. * @returns {$.ajax}
  339. */
  340. loadWidgetLayouts: function () {
  341. this.set('isWidgetLayoutsLoaded', false);
  342. return App.ajax.send({
  343. name: 'widgets.layouts.get',
  344. sender: this,
  345. data: {
  346. sectionName: this.get('sectionName')
  347. },
  348. success: 'loadWidgetLayoutsSuccessCallback'
  349. });
  350. },
  351. loadWidgetLayoutsSuccessCallback: function (data) {
  352. App.widgetLayoutMapper.map(data);
  353. this.set('isWidgetLayoutsLoaded', true);
  354. },
  355. /**
  356. * load widgets defined by user
  357. * @returns {$.ajax}
  358. */
  359. loadActiveWidgetLayout: function () {
  360. this.set('activeWidgetLayout', {});
  361. this.set('isWidgetsLoaded', false);
  362. if (this.get('isServiceWithEnhancedWidgets')) {
  363. return App.ajax.send({
  364. name: 'widget.layout.get',
  365. sender: this,
  366. data: {
  367. layoutName: this.get('defaultLayoutName'),
  368. serviceName: this.get('content.serviceName')
  369. },
  370. success: 'loadActiveWidgetLayoutSuccessCallback'
  371. });
  372. } else {
  373. this.set('isWidgetsLoaded', true);
  374. }
  375. },
  376. /**
  377. * success callback of <code>loadWidgets()</code>
  378. * @param {object|null} data
  379. */
  380. loadActiveWidgetLayoutSuccessCallback: function (data) {
  381. if (data.items[0]) {
  382. App.widgetMapper.map(data.items[0].WidgetLayoutInfo);
  383. App.widgetLayoutMapper.map(data);
  384. this.set('activeWidgetLayout', App.WidgetLayout.find().findProperty('layoutName', this.get('defaultLayoutName')));
  385. this.set('isWidgetsLoaded', true);
  386. }
  387. },
  388. /**
  389. * load all shared widgets to show on widget browser
  390. * @returns {$.ajax}
  391. */
  392. loadAllSharedWidgets: function () {
  393. this.set('isAllSharedWidgetsLoaded', false);
  394. return App.ajax.send({
  395. name: 'widgets.all.shared.get',
  396. sender: this,
  397. success: 'loadAllSharedWidgetsSuccessCallback'
  398. });
  399. },
  400. /**
  401. * success callback of <code>loadAllSharedWidgets</code>
  402. * @param {object|null} data
  403. */
  404. loadAllSharedWidgetsSuccessCallback: function (data) {
  405. var addedWidgetsNames = this.get('widgets').mapProperty('widgetName');
  406. if (data.items[0] && data.items.length) {
  407. this.set("allSharedWidgets",
  408. data.items.filter(function (widget) {
  409. return widget.WidgetInfo.widget_type != "HEATMAP";
  410. }).map(function (widget) {
  411. var widgetType = widget.WidgetInfo.widget_type;
  412. var widgetName = widget.WidgetInfo.widget_name;
  413. return Em.Object.create({
  414. id: widget.WidgetInfo.id,
  415. widgetName: widgetName,
  416. displayName: widget.WidgetInfo.display_name,
  417. description: widget.WidgetInfo.description,
  418. widgetType: widgetType,
  419. iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
  420. serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
  421. added: addedWidgetsNames.contains(widgetName),
  422. isShared: true
  423. });
  424. })
  425. );
  426. }
  427. this.set('isAllSharedWidgetsLoaded', true);
  428. },
  429. allSharedWidgets: [],
  430. mineWidgets: [],
  431. /**
  432. * load all mine widgets of current user to show on widget browser
  433. * @returns {$.ajax}
  434. */
  435. loadMineWidgets: function () {
  436. this.set('isMineWidgetsLoaded', false);
  437. return App.ajax.send({
  438. name: 'widgets.all.mine.get',
  439. sender: this,
  440. data: {
  441. loginName: App.router.get('loginName')
  442. },
  443. success: 'loadMineWidgetsSuccessCallback'
  444. });
  445. },
  446. /**
  447. * success callback of <code>loadMineWidgets</code>
  448. * @param {object|null} data
  449. */
  450. loadMineWidgetsSuccessCallback: function (data) {
  451. var addedWidgetsNames = this.get('widgets').mapProperty('widgetName');
  452. if (data.items[0] && data.items.length) {
  453. this.set("mineWidgets",
  454. data.items.filter(function (widget) {
  455. return widget.WidgetInfo.widget_type != "HEATMAP";
  456. }).map(function (widget) {
  457. var widgetType = widget.WidgetInfo.widget_type;
  458. var widgetName = widget.WidgetInfo.widget_name;
  459. return Em.Object.create({
  460. id: widget.WidgetInfo.id,
  461. widgetName: widgetName,
  462. displayName: widget.WidgetInfo.display_name,
  463. description: widget.WidgetInfo.description,
  464. widgetType: widgetType,
  465. iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
  466. serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
  467. added: addedWidgetsNames.contains(widgetName),
  468. isShared: false
  469. });
  470. })
  471. );
  472. }
  473. this.set('isMineWidgetsLoaded', true);
  474. },
  475. /**
  476. * add widgets, on click handler for "Add"
  477. */
  478. addWidget: function (event) {
  479. var widgetToAdd = event.context;
  480. var activeLayout = this.get('activeWidgetLayout');
  481. var widgetIds = activeLayout.get('widgets').map(function(widget) {
  482. return {
  483. "id": widget.get("id")
  484. }
  485. });
  486. widgetIds.pushObject({
  487. "id": widgetToAdd.id
  488. })
  489. var data = {
  490. "WidgetLayoutInfo": {
  491. "display_name": activeLayout.get("displayName"),
  492. "id": activeLayout.get("id"),
  493. "layout_name": activeLayout.get("layoutName"),
  494. "scope": activeLayout.get("scope"),
  495. "section_name": activeLayout.get("sectionName"),
  496. "widgets": widgetIds
  497. }
  498. };
  499. widgetToAdd.set('added', !widgetToAdd.added);
  500. return App.ajax.send({
  501. name: 'widget.layout.edit',
  502. sender: this,
  503. data: {
  504. layoutId: activeLayout.get("id"),
  505. data: data
  506. },
  507. success: 'updateActiveLayout'
  508. });
  509. },
  510. /**
  511. * hide widgets, on click handler for "Added"
  512. */
  513. hideWidget: function (event) {
  514. var widgetToHide = event.context;
  515. var activeLayout = this.get('activeWidgetLayout');
  516. var widgetIds = activeLayout.get('widgets').map(function(widget) {
  517. return {
  518. "id": widget.get("id")
  519. }
  520. });
  521. var data = {
  522. "WidgetLayoutInfo": {
  523. "display_name": activeLayout.get("displayName"),
  524. "id": activeLayout.get("id"),
  525. "layout_name": activeLayout.get("layoutName"),
  526. "scope": activeLayout.get("scope"),
  527. "section_name": activeLayout.get("sectionName"),
  528. "widgets": widgetIds.filter(function(widget) {
  529. return widget.id != widgetToHide.id;
  530. })
  531. }
  532. };
  533. widgetToHide.set('added', !widgetToHide.added);
  534. return App.ajax.send({
  535. name: 'widget.layout.edit',
  536. sender: this,
  537. data: {
  538. layoutId: activeLayout.get("id"),
  539. data: data
  540. },
  541. success: 'updateActiveLayout'
  542. });
  543. },
  544. /**
  545. * update current active widget layout
  546. */
  547. updateActiveLayout: function () {
  548. this.loadActiveWidgetLayout();
  549. },
  550. /**
  551. * delete widgets, on click handler for "Delete"
  552. */
  553. deleteWidget: function (event) {
  554. var widget = event.context;
  555. var self = this;
  556. var bodyMessage = Em.Object.create({
  557. confirmMsg: Em.I18n.t('dashboard.widgets.browser.action.delete.bodyMsg').format(widget.displayName),
  558. confirmButton: Em.I18n.t('dashboard.widgets.browser.action.delete.btnMsg')
  559. });
  560. return App.showConfirmationFeedBackPopup(function (query) {
  561. return App.ajax.send({
  562. name: 'widget.action.delete',
  563. sender: self,
  564. data: {
  565. id: widget.id
  566. },
  567. success: 'updateWidgetBrowser'
  568. });
  569. }, bodyMessage);
  570. },
  571. /**
  572. * update widget browser content after deleted some widget
  573. */
  574. updateWidgetBrowser: function () {
  575. this.loadAllSharedWidgets();
  576. this.loadMineWidgets();
  577. },
  578. /**
  579. * unshare widgets, on click handler for "Unshare"
  580. */
  581. unshareWidget: function (event) {
  582. var widget = event.context;
  583. var widgetName = widget.widgetName;
  584. //todo unshare current widget
  585. },
  586. /**
  587. * Share widgets, on click handler for "Share"
  588. */
  589. shareWidget: function (event) {
  590. var widget = event.context;
  591. var widgetName = widget.widgetName;
  592. // todo share current widget
  593. },
  594. /**
  595. * save layout after re-order widgets
  596. * return {$.ajax}
  597. */
  598. saveReorderedLayout: function (widgets) {
  599. var activeLayout = this.get('activeWidgetLayout');
  600. var data = {
  601. "WidgetLayoutInfo": {
  602. "display_name": activeLayout.get("displayName"),
  603. "id": activeLayout.get("id"),
  604. "layout_name": activeLayout.get("layoutName"),
  605. "scope": activeLayout.get("scope"),
  606. "section_name": activeLayout.get("sectionName"),
  607. "widgets": widgets.map(function (widget) {
  608. return {
  609. "id": widget.get('id')
  610. }
  611. })
  612. }
  613. };
  614. return App.ajax.send({
  615. name: 'widget.layout.edit',
  616. sender: this,
  617. data: {
  618. layoutId: activeLayout.get("id"),
  619. data: data
  620. }
  621. });
  622. },
  623. /**
  624. * create widget
  625. */
  626. createWidget: function () {
  627. App.router.send('addServiceWidget', this.get('content'));
  628. },
  629. /**
  630. * launch Widgets Browser popup
  631. * @method showPopup
  632. * @return {App.ModalPopup}
  633. */
  634. goToWidgetsBrowser: function () {
  635. var self = this;
  636. return App.ModalPopup.show({
  637. header: function () {
  638. return Em.I18n.t('dashboard.widgets.browser.header');
  639. }.property(''),
  640. classNames: ['sixty-percent-width-modal', 'widgets-browser-popup'],
  641. primary: Em.I18n.t('common.close'),
  642. secondary: null,
  643. onPrimary: function () {
  644. this.hide();
  645. self.set('isAllSharedWidgetsLoaded', false);
  646. self.set('allSharedWidgets', []);
  647. self.set('isMineWidgetsLoaded', false);
  648. self.set('mineWidgets', []);
  649. },
  650. autoHeight: false,
  651. isHideBodyScroll: false,
  652. bodyClass: Ember.View.extend({
  653. templateName: require('templates/common/modal_popups/widget_browser_popup'),
  654. controller: self,
  655. willInsertElement: function () {
  656. this.get('controller').loadAllSharedWidgets();
  657. this.get('controller').loadMineWidgets();
  658. },
  659. isLoaded: function () {
  660. return !!this.get('controller.isAllSharedWidgetsLoaded');
  661. }.property('controller.isAllSharedWidgetsLoaded'),
  662. isWidgetEmptyList: function () {
  663. return !this.get('filteredContent.length');
  664. }.property('filteredContent.length'),
  665. activeTab: 'shared',
  666. activeService: '',
  667. activeStatus: '',
  668. content: function () {
  669. if (this.get('activeTab') == 'mine') {
  670. return this.get('controller.mineWidgets');
  671. } else if (this.get('activeTab') == 'shared') {
  672. return this.get('controller.allSharedWidgets');
  673. }
  674. }.property('controller.allSharedWidgets.length', 'controller.isAllSharedWidgetsLoaded',
  675. 'controller.mineWidgets.length', 'controller.isMineWidgetsLoaded', 'activeTab'),
  676. /**
  677. * displaying content filtered by service name and status.
  678. */
  679. filteredContent: function () {
  680. var activeService = this.get('activeService') ? this.get('activeService') : this.get('controller.content.serviceName');
  681. var result = [];
  682. this.get('content').forEach(function (widget) {
  683. if (widget.get('serviceName').indexOf(activeService) >= 0) {
  684. result.pushObject(widget);
  685. }
  686. });
  687. return result;
  688. }.property('content', 'activeService', 'activeStatus'),
  689. /**
  690. * top tabs: Share / Mine
  691. */
  692. categories: [
  693. {
  694. name: 'shared',
  695. label: Em.I18n.t('dashboard.widgets.browser.menu.shared')
  696. },
  697. {
  698. name: 'mine',
  699. label: Em.I18n.t('dashboard.widgets.browser.menu.mine')
  700. }
  701. ],
  702. NavItemView: Ember.View.extend({
  703. tagName: 'li',
  704. classNameBindings: 'isActive:active'.w(),
  705. isActive: function () {
  706. return this.get('item') == this.get('parentView.activeTab');
  707. }.property('item', 'parentView.activeTab'),
  708. elementId: Ember.computed(function () {
  709. var label = Em.get(this, 'templateData.keywords.category.label');
  710. return label ? 'widget-browser-view-tab-' + label.toLowerCase().replace(/\s/g, '-') : "";
  711. }),
  712. count: function () {
  713. if (this.get('item') == 'mine') {
  714. return this.get('parentView.controller.mineWidgets.length');
  715. } else if (this.get('item') == 'shared') {
  716. return this.get('parentView.controller.allSharedWidgets.length');
  717. }
  718. }.property('item', 'parentView.controller.mineWidgets.length',
  719. 'parentView.controller.allSharedWidgets.length'),
  720. goToWidgetTab: function (event) {
  721. var targetName = event.context;
  722. this.set('parentView.activeTab', targetName);
  723. }
  724. }),
  725. /**
  726. * service name filter
  727. */
  728. services: function () {
  729. var view = this;
  730. return App.Service.find().map(function (service) {
  731. return Em.Object.create({
  732. value: service.get('serviceName'),
  733. label: service.get('displayName'),
  734. isActive: function () {
  735. var activeService = view.get('activeService') ? view.get('activeService') : view.get('controller.content.serviceName');
  736. return this.get('value') == activeService;
  737. }.property('value', 'view.activeService')
  738. })
  739. });
  740. }.property('activeService'),
  741. filterByService: function (event) {
  742. this.set('activeService', event.context);
  743. },
  744. createWidget: function () {
  745. this.get('parentView').onPrimary();
  746. this.get('controller').createWidget();
  747. },
  748. didInsertElement: function () {
  749. }
  750. })
  751. });
  752. }
  753. });