Catalog app rollback

This commit is contained in:
loganhz 2018-04-19 10:54:39 +08:00
parent 59258216c8
commit 2412563010
4 changed files with 56 additions and 47 deletions

View File

@ -1,6 +1,4 @@
import { inject as service } from '@ember/service';
import { get, set, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import Component from '@ember/component';
import ModalBase from 'shared/mixins/modal-base';
import layout from './template';
@ -10,12 +8,13 @@ export default Component.extend(ModalBase, {
classNames: ['large-modal'],
revisions: alias('model.status.releases'),
selectedRevision: null,
loading: true,
revisions: null,
revisionId: null,
actions: {
save(cb) {
const revision = get(this, 'selectedRevision');
const revision = get(this, 'revisionId');
get(this, 'model').doAction('rollback', {
revision,
}).then(() => {
@ -29,17 +28,28 @@ export default Component.extend(ModalBase, {
didReceiveAttrs() {
let model = get(this, 'modalService.modalOpts.originalModel').clone();
set(this, 'model', model);
get(this, 'store').rawRequest({
url: get(model, 'links.revision'),
method: 'GET',
}).then((revs) => {
set(this, 'revisions', revs.body.data);
}).catch((err) => {
this.send('cancel');
get(this, 'growl').fromError(err);
}).finally(() => {
set(this, 'loading', false);
});
},
choices: computed('revisions.[]', function () {
return (get(this, 'revisions') || [])
.sortBy('createTimestamp')
.sortBy('created')
.reverse()
.map((r) => {
let time = moment(get(r, 'createTimestamp'));
let time = moment(get(r, 'created'));
return {
label: get(r, 'name') + ': ' + time.format('YYYY-MM-DD HH:mm:ss') + ' (' + time.fromNow() + ')',
value: get(r, 'version'),
value: get(r, 'name'),
data: r,
};
});
@ -49,14 +59,14 @@ export default Component.extend(ModalBase, {
return get(this, 'choices.firstObject.data');
}),
selected: computed('revision', 'revisions.[]', function () {
return get(this, 'revisions').findBy('version', get(this, 'revision'));
selected: computed('revisionId', 'revisions.[]', function () {
return get(this, 'revisions').findBy('name', get(this, 'revisionId'));
}),
diff: computed('current', 'selected', function () {
if (get(this, 'current') && get(this, 'selected')) {
let left = '';
let right = '';
let left = get(this, 'current.status');
let right = get(this, 'selected.status');
var delta = jsondiffpatch.diff(left, right);
jsondiffpatch.formatters.html.hideUnchanged();
return jsondiffpatch.formatters.html.format(delta, left).htmlSafe();

View File

@ -13,17 +13,21 @@
</div>
</div>
<div class="col span-8">
<label class="acc-label">{{t 'modalRollbackApp.revision.label'}}</label>
{{new-select
content=choices
value=selectedRevision
prompt="modalRollbackApp.revision.prompt"
localizedPrompt=true
optionLabelPath="label"
optionValuePath="value"
}}
</div>
{{#if loading}}
<i class="icon icon-spinner icon-spin"/> {{t 'generic.loading'}}
{{else}}
<div class="col span-8">
<label class="acc-label">{{t 'modalRollbackApp.revision.label'}}</label>
{{new-select
content=choices
value=revisionId
prompt="modalRollbackApp.revision.prompt"
localizedPrompt=true
optionLabelPath="label"
optionValuePath="value"
}}
</div>
{{/if}}
</div>
{{#if (and diff diff.string)}}

View File

@ -50,13 +50,15 @@
</div>
{{/accordion-list-item}}
{{#accordion-list-item
title=(t 'newCatalog.newApp')
detail=(t 'newCatalog.newAppDetail')
expandAll=al.expandAll
expandOnInit=true
expand=(action expandFn)
title=(t (if (or (eq templateKind 'native') selectedTemplateModel.questions) 'inputAnswers.config' 'newCatalog.helm.label'))
detail=(t (if (or (eq templateKind 'native') selectedTemplateModel.questions) 'inputAnswers.protip' 'newCatalog.helm.protip'))
expandAll=al.expandAll
expandOnInit=true
expand=(action expandFn)
}}
<div class="row">
<div class="col span-6">
{{form-name-description
@ -98,22 +100,16 @@
{{/if}}
</div>
</div>
{{/accordion-list-item}}
{{#if getTemplate.isRunning}}
<section class="row">
<div class="text-center">
<i class="icon icon-spinner icon-spin" style="font-size:36px;"></i>
</div>
</section>
{{else}}
{{#accordion-list-item
title=(t (if (or (eq templateKind 'native') selectedTemplateModel.questions) 'inputAnswers.config' 'newCatalog.helm.label'))
detail=(t (if (or (eq templateKind 'native') selectedTemplateModel.questions) 'inputAnswers.protip' 'newCatalog.helm.protip'))
expandAll=al.expandAll
expandOnInit=true
expand=(action expandFn)
}}
<hr/>
{{#if getTemplate.isRunning}}
<section class="row">
<div class="text-center">
<i class="icon icon-spinner icon-spin" style="font-size:36px;"></i>
</div>
</section>
{{else}}
<div class="row">
{{#if selectedTemplateModel}}
{{#if (eq templateKind 'native')}}
@ -146,8 +142,8 @@
{{/if}}
{{/if}}
</div>
{{/accordion-list-item}}
{{/if}}
{{/if}}
{{/accordion-list-item}}
{{/accordion-list}}

View File

@ -4226,9 +4226,8 @@ newCatalog:
maintainedBy: Maintained by community members
maintainer: "Maintainer:"
newNamespace: New Namespace
newApp: New Application
newAppDetail: Choose application version and namespace for the application
appInfo: Application Read Me
appInfo: Detailed Description
appInfoDetail: Application information and user guid
noConfig: This template has no configuration options
official: Officially Certified