* refactor: 💡 update worker factory to include api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * feat: 🎸 add tags flyout for workers table ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 move test selector to const ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 only show 'view more tags' if more than 10 tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * test: 💍 update test name ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update how worker tags are shown in flyout ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 add one more api tag for worker in mirage ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 fix tagDisplayName signature ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update tag shortener styling ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889
100 lines
2.4 KiB
JavaScript
100 lines
2.4 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 { tracked } from '@glimmer/tracking';
|
|
import { confirm } from 'core/decorators/confirm';
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
|
|
|
export default class ScopesScopeWorkersIndexController extends Controller {
|
|
// =services
|
|
|
|
@service router;
|
|
@service can;
|
|
|
|
// =attributes
|
|
|
|
@tracked selectedWorker;
|
|
|
|
/**
|
|
* Get the first 10 tags of the selected worker.
|
|
* @type {object[]}
|
|
*/
|
|
get selectedWorkerTags() {
|
|
// only show the first 10 tags if there are more than 10
|
|
return this.selectedWorker.allTags.slice(0, 10);
|
|
}
|
|
|
|
/**
|
|
* Build the display name for a worker tag
|
|
* @param {object} tag
|
|
* @returns {string}
|
|
*/
|
|
tagDisplayName(tag) {
|
|
return `${tag.key} = ${tag.value}`;
|
|
}
|
|
|
|
// =actions
|
|
|
|
/**
|
|
* Toggle the tags flyout to display or hide the tags of a worker.
|
|
* @param {object} selectedWorker
|
|
*/
|
|
@action
|
|
selectWorker(selectedWorker) {
|
|
this.selectedWorker = selectedWorker;
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
}
|