68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Controller from '@ember/controller';
|
|
import { inject as service } from '@ember/service';
|
|
import { action } from '@ember/object';
|
|
import { loading } from 'ember-loading';
|
|
import { confirm } from 'core/decorators/confirm';
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
|
|
|
export default class ScopesScopeWorkersIndexController extends Controller {
|
|
// =services
|
|
|
|
@service router;
|
|
@service can;
|
|
|
|
// =actions
|
|
|
|
/**
|
|
* Rollback changes on workers.
|
|
* @param {WorkerModel} worker
|
|
*/
|
|
@action
|
|
cancel(worker) {
|
|
const { isNew } = worker;
|
|
worker.rollbackAttributes();
|
|
if (isNew) this.router.transitionTo('scopes.scope.workers');
|
|
}
|
|
|
|
/**
|
|
* Save a worker in current scope.
|
|
* @param {WorkerModel} worker
|
|
* @param {Event} e
|
|
*/
|
|
@action
|
|
@loading
|
|
@notifyError(({ message }) => message)
|
|
@notifySuccess(({ isNew }) =>
|
|
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
|
)
|
|
async save(worker) {
|
|
await worker.save();
|
|
if (this.can.can('read model', worker)) {
|
|
await this.router.transitionTo('scopes.scope.workers.worker', worker);
|
|
} else {
|
|
await this.router.transitionTo('scopes.scope.workers');
|
|
}
|
|
await this.router.refresh();
|
|
}
|
|
|
|
/**
|
|
* Delete worker in current scope and redirect to index.
|
|
* @param {WorkerModel} worker
|
|
*/
|
|
@action
|
|
@loading
|
|
@confirm('questions.delete-confirm')
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
@notifySuccess('notifications.delete-success')
|
|
async delete(worker) {
|
|
await worker.destroyRecord();
|
|
await this.router.replaceWith('scopes.scope.workers');
|
|
await this.router.refresh();
|
|
}
|
|
}
|