Files
threshold-ui/ui/admin/app/routes/scopes/scope/host-catalogs.js
T
2024-04-12 14:55:33 -04:00

76 lines
1.8 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Route from '@ember/routing/route';
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 ScopesScopeHostCatalogsRoute extends Route {
// =services
@service session;
@service router;
// =methods
/**
* If arriving here unauthenticated, redirect to index for further processing.
*/
beforeModel() {
if (!this.session.isAuthenticated) this.router.transitionTo('index');
}
// =actions
/**
* Rollback changes on host catalog.
* @param {HostCatalogModel} hostCatalog
*/
@action
cancel(hostCatalog) {
const { isNew } = hostCatalog;
hostCatalog.rollbackAttributes();
if (isNew) this.router.transitionTo('scopes.scope.host-catalogs');
}
/**
* Handle save.
* @param {HostCatalogModel} hostCatalog
* @param {Event} e
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success',
)
async save(hostCatalog) {
await hostCatalog.save();
await this.router.transitionTo(
'scopes.scope.host-catalogs.host-catalog',
hostCatalog,
);
this.refresh();
}
/**
* Deletes the host catalog and redirects to index.
* @param {HostCatalogModel} hostCatalog
*/
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(hostCatalog) {
await hostCatalog.destroyRecord();
this.router.replaceWith('scopes.scope.host-catalogs');
this.refresh();
}
}