From 0ebcc715e1faf5677eff07f325c6e0a37e981ca2 Mon Sep 17 00:00:00 2001 From: vimniky Date: Sat, 24 Feb 2018 12:46:17 +0800 Subject: [PATCH] Alert bugfix --- .../addon/components/alert-table/component.js | 28 +++++++++---- .../addon/components/alert-table/template.hbs | 5 +-- .../alert/form-cluster-rules/component.js | 10 +++++ .../alert/form-cluster-rules/template.hbs | 2 +- .../alert/form-project-rules/component.js | 34 +++++++++++++-- .../alert/form-project-rules/template.hbs | 2 +- .../alert/form-recipients/component.js | 6 +++ .../components/alert/new-edit/template.hbs | 3 -- .../components/cluster-alert-row/component.js | 6 --- .../components/cluster-alert-row/template.hbs | 9 ++-- .../components/project-alert-row/component.js | 7 ---- .../components/project-alert-row/template.hbs | 4 +- lib/alert/addon/index/route.js | 8 +--- lib/alert/addon/index/template.hbs | 6 +-- lib/alert/addon/mixins/model-alert.js | 41 +++++++++++++++++++ lib/alert/addon/mixins/notifier.js | 9 ---- lib/alert/addon/new/route.js | 1 - .../notifier/notifier-table/component.js | 12 ++++-- 18 files changed, 131 insertions(+), 62 deletions(-) diff --git a/lib/alert/addon/components/alert-table/component.js b/lib/alert/addon/components/alert-table/component.js index 08ce7e2ed..477ed133b 100644 --- a/lib/alert/addon/components/alert-table/component.js +++ b/lib/alert/addon/components/alert-table/component.js @@ -21,8 +21,8 @@ const headers = [ { translationKey: 'alertPage.index.table.target', name: 'target', - searchField: ['target', 'displayTargetType'], - sort: ['target', 'id'], + searchField: ['nodeName', 'resourceKind', 'displayTargetType'], + sort: ['nodeName', 'id', 'resourceKind'], }, { translationKey: 'alertPage.index.table.condition', @@ -33,14 +33,16 @@ const headers = [ { translationKey: 'alertPage.index.table.recipients', name: 'recipients', - searchField: ['recipient'], - sort: ['recipients'], + searchField: ['recipient', 'firstRecipient'], + sort: ['recipients', 'firstRecipient'], }, ]; export default Component.extend({ - pageScope: reads('scope.currentPageScope'), scope: service(), + clusterId: reads('scope.currentCluster.id'), + projectId: reads('scope.currentProject.id'), + pageScope: reads('scope.currentPageScope'), // input model: null, @@ -54,7 +56,19 @@ export default Component.extend({ search: true, searchText: null, + filteredNotifiers: function() { + const clusterId = get(this, 'clusterId'); + return get(this, 'notifiers').filterBy('clusterId', clusterId); + }.property('clusterId', 'notifiers.@each.{clusterId}'), + filteredAlerts: function() { - return get(this, 'model'); - }.property('model.[]'), + const clusterId = get(this, 'clusterId'); + const projectId = get(this, 'projectId'); + const ps = get(this, 'pageScope'); + if (ps === 'cluster') { + return get(this, 'alerts').filterBy('clusterId', clusterId); + } else { + return get(this, 'alerts').filterBy('projectId', projectId); + } + }.property('alerts.@each.{clusterId,projectId}', 'clusterId', 'projectId', 'pageScope'), }); diff --git a/lib/alert/addon/components/alert-table/template.hbs b/lib/alert/addon/components/alert-table/template.hbs index 8c6434b0e..146b4cb26 100644 --- a/lib/alert/addon/components/alert-table/template.hbs +++ b/lib/alert/addon/components/alert-table/template.hbs @@ -9,14 +9,13 @@ searchText=searchText headers=headers body=filteredAlerts - fullRows=fullRows as |sortable kind row dt| }} {{#if (eq kind "row")}} {{#if (eq pageScope 'cluster')}} - {{cluster-alert-row notifiers=notifiers model=row}} + {{cluster-alert-row notifiers=filteredNotifiers model=row}} {{else if (eq pageScope 'project')}} - {{project-alert-row notifiers=notifiers model=row}} + {{project-alert-row notifiers=filteredNotifiers model=row}} {{else}}
Oops, it's impossible
{{/if}} diff --git a/lib/alert/addon/components/alert/form-cluster-rules/component.js b/lib/alert/addon/components/alert/form-cluster-rules/component.js index 7bfa41ef2..9f226d934 100644 --- a/lib/alert/addon/components/alert/form-cluster-rules/component.js +++ b/lib/alert/addon/components/alert/form-cluster-rules/component.js @@ -1,5 +1,7 @@ import { get, set } from '@ember/object'; import Component from '@ember/component'; +import { inject as service } from '@ember/service'; +import { reads } from '@ember/object/computed'; const SYSTEM_SERVICES = [ {label: 'Etcd', value: 'etcd'}, @@ -16,6 +18,9 @@ const RESOURCE_KINDS = [ {label: 'Daemonset', value: 'Daemonset'}, ]; export default Component.extend({ + globalStore: service(), + scope: service(), + clusterId: reads('scope.currentCluster.id'), init(...args) { this._super(...args); @@ -23,6 +28,11 @@ export default Component.extend({ this.set('resourceKinds', RESOURCE_KINDS); }, + nodes: function() { + const clusterId = get(this, 'clusterId'); + return get(this, 'globalStore').all('node').filterBy('clusterId', clusterId); + }.property('clusterId'), + isEventTarget: function() { const t = get(this, 'model._targetType'); return t === 'warningEvent' || t === 'normalEvent'; diff --git a/lib/alert/addon/components/alert/form-cluster-rules/template.hbs b/lib/alert/addon/components/alert/form-cluster-rules/template.hbs index 133da0843..d0c1c3719 100644 --- a/lib/alert/addon/components/alert/form-cluster-rules/template.hbs +++ b/lib/alert/addon/components/alert/form-cluster-rules/template.hbs @@ -53,7 +53,7 @@
{{searchable-select - content=resourceMap.nodes + content=nodes class="form-control" value=model.targetNode.nodeId optionValuePath="id" diff --git a/lib/alert/addon/components/alert/form-project-rules/component.js b/lib/alert/addon/components/alert/form-project-rules/component.js index 35319cb6f..499ebeb62 100644 --- a/lib/alert/addon/components/alert/form-project-rules/component.js +++ b/lib/alert/addon/components/alert/form-project-rules/component.js @@ -1,4 +1,6 @@ import { get, set } from '@ember/object'; +import { inject as service } from '@ember/service'; +import { reads } from '@ember/object/computed'; import Component from '@ember/component'; const WORLOAD_TYPES = [ @@ -8,6 +10,10 @@ const WORLOAD_TYPES = [ ]; export default Component.extend({ + globalStore: service(), + scope: service(), + clusterId: reads('scope.currentCluster.id'), + projectId: reads('scope.currentProject.id'), restartIntervalSeconds: null, @@ -19,6 +25,26 @@ export default Component.extend({ set(this, 'model.targetPod.restartIntervalSeconds', n * 60); }, + pods: function() { + const clusterId = get(this, 'clusterId'); + return get(this, 'store').all('pod').filterBy('clusterId', clusterId); + }.property('clusterId'), + + deployments: function() { + const projectId = get(this, 'projectId'); + return get(this, 'store').all('deployment').filterBy('projectId', projectId); + }.property('projectId'), + + daemonsets: function() { + const projectId = get(this, 'projectId'); + return get(this, 'store').all('daemonset').filterBy('projectId', projectId); + }.property('projectId'), + + statefulsets: function() { + const projectId = get(this, 'projectId'); + return get(this, 'store').all('statefulset').filterBy('projectId', projectId); + }.property('projectId'), + restartIntervalSecondsChanged: function() { const n = +get(this, 'restartIntervalSeconds') || 5; set(this, 'model.targetPod.restartIntervalSeconds', n * 60); @@ -27,15 +53,15 @@ export default Component.extend({ workloads: function() { const t = get(this, 'model.targetWorkload.workloadType'); if (t === 'deployment') { - return get(this, 'resourceMap.deployments'); + return get(this, 'deployments'); } if (t === 'daemonset') { - return get(this, 'resourceMap.daemonsets'); + return get(this, 'daemonsets'); } if (t === 'statefulset') { - return get(this, 'resourceMap.statefulsets'); + return get(this, 'statefulsets'); } - }.property('resourceMap.deployments.[]', 'resourceMap.daemonsets.[]', 'resourceMap.statefulsets.[]', 'model.targetWorkload.workloadType'), + }.property('deployments.[]', 'daemonsets.[]', 'statefulsets.[]', 'model.targetWorkload.workloadType'), actions: { // todo, don't know that this is needed diff --git a/lib/alert/addon/components/alert/form-project-rules/template.hbs b/lib/alert/addon/components/alert/form-project-rules/template.hbs index 6dd6a8b37..043c3ea81 100644 --- a/lib/alert/addon/components/alert/form-project-rules/template.hbs +++ b/lib/alert/addon/components/alert/form-project-rules/template.hbs @@ -14,7 +14,7 @@
{{searchable-select - content=resourceMap.pods + content=pods class="form-control" value=model.targetPod.podId optionValuePath="id" diff --git a/lib/alert/addon/components/alert/form-recipients/component.js b/lib/alert/addon/components/alert/form-recipients/component.js index 5fee42302..4a3517106 100644 --- a/lib/alert/addon/components/alert/form-recipients/component.js +++ b/lib/alert/addon/components/alert/form-recipients/component.js @@ -4,6 +4,7 @@ import { reads } from '@ember/object/computed'; import Component from '@ember/component'; export default Component.extend({ + globalStore: service(), scope: service(), clusterId: reads('scope.currentCluster.id'), @@ -20,6 +21,11 @@ export default Component.extend({ get(this, 'model.recipients').pushObject(nue); }, + notifiers: function() { + const clusterId = get(this, 'clusterId'); + return get(this, 'globalStore').all('notifier').filterBy('clusterId', clusterId); + }.property('clusterId'), + disableRemove: function() { return get(this, 'model.recipients.length') <= 1; }.property('model.recipients.length'), diff --git a/lib/alert/addon/components/alert/new-edit/template.hbs b/lib/alert/addon/components/alert/new-edit/template.hbs index b7ffa7bc0..07f41e614 100644 --- a/lib/alert/addon/components/alert/new-edit/template.hbs +++ b/lib/alert/addon/components/alert/new-edit/template.hbs @@ -16,7 +16,6 @@
{{# if (eq pageScope 'cluster')}} {{alert/form-cluster-rules - resourceMap=resourceMap pageScope=pageScope isCreate=isCreate model=newAlert @@ -24,7 +23,6 @@ {{else if (eq pageScope 'project')}} {{alert/form-project-rules pageScope=pageScope - resourceMap=resourceMap isCreate=isCreate model=newAlert }} @@ -35,7 +33,6 @@ {{alert/form-recipients pageScope=pageScope isCreate=isCreate - notifiers=resourceMap.notifiers model=newAlert }}
diff --git a/lib/alert/addon/components/cluster-alert-row/component.js b/lib/alert/addon/components/cluster-alert-row/component.js index 648d8b7be..cb918ff1b 100644 --- a/lib/alert/addon/components/cluster-alert-row/component.js +++ b/lib/alert/addon/components/cluster-alert-row/component.js @@ -11,12 +11,6 @@ export default Component.extend(notifierMixin, { classNames: 'main-row', bulkActions: true, - resourceKind: function() { - const rk = get(this, 'model.targetEvent.resourceKind'); - return get(this, 'intl').t(`alertPage.resourceKinds.${rk}`); - - }.property('model.targetEvent.resourceKind'), - selectorList: function() { const t = get(this, 'model.targetType'); if (t === 'nodeSelector') { diff --git a/lib/alert/addon/components/cluster-alert-row/template.hbs b/lib/alert/addon/components/cluster-alert-row/template.hbs index f188db7cc..999dc6b5d 100644 --- a/lib/alert/addon/components/cluster-alert-row/template.hbs +++ b/lib/alert/addon/components/cluster-alert-row/template.hbs @@ -36,7 +36,7 @@ {{/if}} {{else if (eq model.targetType 'node')}}
- {{model.targetNode.nodeId}} + {{model.nodeName}}
{{else if (eq model.targetType 'systemService')}}
@@ -44,7 +44,7 @@
{{else if (eq model.targetType 'event')}}
- {{resourceKind}} {{t 'alertPage.targetTypes.event'}} + {{model.resourceKind}} {{t 'alertPage.targetTypes.event'}}
{{/if}} @@ -58,9 +58,10 @@ {{#if (eq model.recipients.length 1)}}
{{item.notifierType}}
- {{#if firstRecipient}} - {{firstRecipient.name}} + {{#if model.firstRecipient}} + {{model.firstRecipient}} {{else}} + {{t 'alertPage.na'}} {{/if}}
{{else if (gt model.recipients.length 1)}} diff --git a/lib/alert/addon/components/project-alert-row/component.js b/lib/alert/addon/components/project-alert-row/component.js index fc205a327..1adb0241c 100644 --- a/lib/alert/addon/components/project-alert-row/component.js +++ b/lib/alert/addon/components/project-alert-row/component.js @@ -18,13 +18,6 @@ export default Component.extend(notifierMixin, { return t === 'pod' && c === 'restarts'; }.property('model.targetType', 'model.targetPod.condition'), - displayTargetType: function() { - const t = get(this, 'model.targetType'); - const intl = get(this, 'intl'); - return intl.t(`alertPage.targetTypes.${t}`); - }.property('model.targetType'), - - selectorList: function() { const t = get(this, 'model.targetType'); if (t === 'workloadSelector') { diff --git a/lib/alert/addon/components/project-alert-row/template.hbs b/lib/alert/addon/components/project-alert-row/template.hbs index 83e10ac41..960eae6df 100644 --- a/lib/alert/addon/components/project-alert-row/template.hbs +++ b/lib/alert/addon/components/project-alert-row/template.hbs @@ -59,8 +59,8 @@ {{#if (eq model.recipients.length 1)}}
{{item.notifierType}}
- {{#if firstRecipient}} - {{firstRecipient.name}} + {{#if model.firstRecipient}} + {{model.firstRecipient}} {{else}} {{t 'alertPage.na'}} {{/if}} diff --git a/lib/alert/addon/index/route.js b/lib/alert/addon/index/route.js index f08934aa5..f720650e1 100644 --- a/lib/alert/addon/index/route.js +++ b/lib/alert/addon/index/route.js @@ -15,9 +15,7 @@ export default Route.extend({ const opt = { filter: {clusterId}, }; - const notifiers = gs.findAll('notifier', opt).then(() => { - return gs.all('notifier'); - }); + const notifiers = gs.findAll('notifier', opt); const alerts = gs.findAll('clusterAlert', opt).then(() => { return gs.all('clusterAlert'); }); @@ -28,9 +26,7 @@ export default Route.extend({ }, loadProjectResource({clusterId, projectId}) { let gs = get(this, 'globalStore'); - const notifiers = gs.findAll('notifier', {filter: {clusterId}}).then(() => { - return gs.all('notifier'); - }); + const notifiers = gs.findAll('notifier', {filter: {clusterId}}); const alerts = gs.findAll('projectAlert', {filter: {projectId}}).then(() => { return gs.all('projectAlert'); }); diff --git a/lib/alert/addon/index/template.hbs b/lib/alert/addon/index/template.hbs index 3398b6007..86ce673f7 100644 --- a/lib/alert/addon/index/template.hbs +++ b/lib/alert/addon/index/template.hbs @@ -5,8 +5,4 @@
-{{alert-table - pageScope=pageScope - notifiers=notifiers - model=alerts -}} \ No newline at end of file +{{alert-table alerts=model.alerts notifiers=model.notifiers}} \ No newline at end of file diff --git a/lib/alert/addon/mixins/model-alert.js b/lib/alert/addon/mixins/model-alert.js index 5d0839f1d..6a24e51c1 100644 --- a/lib/alert/addon/mixins/model-alert.js +++ b/lib/alert/addon/mixins/model-alert.js @@ -5,7 +5,9 @@ import { reads } from '@ember/object/computed'; export default Mixin.create({ router: service(), + globalStore: service(), scope: service(), + intl: service(), pageScope: reads('scope.currentPageScope'), relevantState: function() { @@ -22,6 +24,45 @@ export default Mixin.create({ this.constructor.stateMap = stateMap }, + + displayTargetType: function() { + const t = get(this, 'targetType'); + const intl = get(this, 'intl'); + return intl.t(`alertPage.targetTypes.${t}`); + }.property('targetType'), + + resourceKind: function() { + const rk = get(this, 'targetEvent.resourceKind'); + return get(this, 'intl').t(`alertPage.resourceKinds.${rk}`); + + }.property('targetEvent.resourceKind'), + + firstRecipient: function() { + const recipient = (get(this, 'recipients') || []).get('firstObject'); + if (recipient && get(recipient, 'notifierId')) { + const notifierId = get(recipient, 'notifierId'); + if (!notifierId) return null; + const notifier = get(this, 'globalStore').all('notifier').filterBy('id', notifierId).get('firstObject'); + if (!notifier) { + return null; + } + return notifier.get('displayName'); + } + return null; + }.property('recipients.length'), + + nodeName: function() { + const id = get(this, 'targetNode.nodeId'); + if (!id) { + return null; + } + const node = get(this, 'globalStore').all('node').filterBy('id', id).get('firstObject'); + if (!node) { + return null; + } + return node.get('displayName'); + }.property('targetNode.nodeId'), + actions: { edit() { const ps = get(this, 'pageScope'); diff --git a/lib/alert/addon/mixins/notifier.js b/lib/alert/addon/mixins/notifier.js index f2893af45..b70533ae0 100644 --- a/lib/alert/addon/mixins/notifier.js +++ b/lib/alert/addon/mixins/notifier.js @@ -11,15 +11,6 @@ export default Mixin.create({ return notifiers.filterBy('id', id).get('firstObject'); }, - firstRecipient: function() { - const recipient = get(this, 'model.recipients').get('firstObject'); - if (recipient && get(recipient, 'notifierId')) { - const notifierId = get(recipient, 'notifierId'); - return this.getNotifierById(notifierId) - } - return null; - }.property('model.recipients.length'), - recipientsTip: function() { const recipients = get(this, 'model.recipients') || []; const out = recipients.map(recipient => { diff --git a/lib/alert/addon/new/route.js b/lib/alert/addon/new/route.js index 0fb78fe9f..7011712fe 100644 --- a/lib/alert/addon/new/route.js +++ b/lib/alert/addon/new/route.js @@ -76,7 +76,6 @@ export default Route.extend({ const globalStore = get(this, 'globalStore'); const newAlert = this.getNewProjectAlert(projectId); const opt = {filter: {projectId}}; - return hash({ pods: store.findAll('pod', opt), statefulsets: store.findAll('statefulset', opt), diff --git a/lib/shared/addon/components/notifier/notifier-table/component.js b/lib/shared/addon/components/notifier/notifier-table/component.js index 34cf751ac..8896ac1f6 100644 --- a/lib/shared/addon/components/notifier/notifier-table/component.js +++ b/lib/shared/addon/components/notifier/notifier-table/component.js @@ -1,4 +1,7 @@ import Component from '@ember/component'; +import { inject as service } from '@ember/service'; +import { reads } from '@ember/object/computed'; +import { get } from '@ember/object'; import layout from './template'; const headers = [ @@ -30,6 +33,8 @@ const headers = [ ]; export default Component.extend({ + scope: service(), + clusterId: reads('scope.currentCluster.id'), layout, // input model: null, @@ -37,7 +42,8 @@ export default Component.extend({ headers, filteredNotifiers: function() { - const notifiers = this.get('model') || []; - return notifiers; - }.property('model.[]'), + const data = this.get('model') || []; + const clusterId = get(this, 'clusterId') + return data.filterBy('clusterId', clusterId); + }.property('model.@each.{clusterId}', 'clusterId'), });