refactor: 💡 remove route-action usage from credential-stores (#2172)
* refactor: 💡 remove route-action usage from credential-stores ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12604
This commit is contained in:
1 parent
879c196887
commit
d93986c4e2
32 files changed
+412
-250
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesCredentialLibraryIndexController extends Controller {
|
||||
@controller(
|
||||
'scopes/scope/credential-stores/credential-store/credential-libraries/index',
|
||||
)
|
||||
credentialLibraries;
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesIndexController extends Controller {
|
||||
@controller('scopes/scope/credential-stores/index') credentialStores;
|
||||
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on a credential library.
|
||||
* @param {CredentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
async cancel(credentialLibrary) {
|
||||
const { isNew } = credentialLibrary;
|
||||
credentialLibrary.rollbackAttributes();
|
||||
if (isNew)
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credential-libraries',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle save of a credential library
|
||||
* @param {CredentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(credentialLibrary) {
|
||||
await credentialLibrary.save();
|
||||
if (this.can.can('read model', credentialLibrary)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credential-libraries.credential-library',
|
||||
credentialLibrary,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credential-libraries',
|
||||
);
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle delete of a credential library
|
||||
* @param {CredentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(credentialLibrary) {
|
||||
await credentialLibrary.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.credential-stores.credential-store.credential-libraries',
|
||||
);
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the contents of array fields in order to force the instance
|
||||
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
|
||||
* to the original expected array.
|
||||
*
|
||||
* The deep copy implemented here is required to ensure that both the
|
||||
* array itself and its members are all new.
|
||||
*
|
||||
* @param {credentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
edit(credentialLibrary) {
|
||||
const { critical_options, extensions } = credentialLibrary;
|
||||
credentialLibrary.critical_options = structuredClone(critical_options);
|
||||
credentialLibrary.extensions = structuredClone(extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update type of credential library
|
||||
* @param {string} type
|
||||
*/
|
||||
@action
|
||||
async changeType(type) {
|
||||
await this.router.replaceWith({ queryParams: { type } });
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -3,10 +3,13 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewController extends Controller {
|
||||
// =services
|
||||
@controller(
|
||||
'scopes/scope/credential-stores/credential-store/credential-libraries/index',
|
||||
)
|
||||
credentialLibraries;
|
||||
|
||||
// =attributes
|
||||
queryParams = ['type'];
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsCredentialIndexController extends Controller {
|
||||
@controller(
|
||||
'scopes/scope/credential-stores/credential-store/credentials/index',
|
||||
)
|
||||
credentials;
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsIndexController extends Controller {
|
||||
@controller('scopes/scope/credential-stores/index') credentialStores;
|
||||
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on a credential.
|
||||
* @param {CredentialModel} credential
|
||||
*/
|
||||
@action
|
||||
async cancel(credential) {
|
||||
const { isNew } = credential;
|
||||
credential.rollbackAttributes();
|
||||
if (isNew)
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credentials',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle save of a credential
|
||||
* @param {CredentialModel} credential
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(credential) {
|
||||
await credential.save();
|
||||
if (this.can.can('read credential', credential)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credentials.credential',
|
||||
credential,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store.credentials',
|
||||
);
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
/**
|
||||
* Handle delete of a credential
|
||||
* @param {Credential} credential
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(credential) {
|
||||
await credential.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.credential-stores.credential-store.credentials',
|
||||
);
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update type of credential
|
||||
* @param {string} type
|
||||
*/
|
||||
@action
|
||||
async changeType(type) {
|
||||
await this.router.replaceWith({ queryParams: { type } });
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -3,10 +3,13 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsNewController extends Controller {
|
||||
// =services
|
||||
@controller(
|
||||
'scopes/scope/credential-stores/credential-store/credentials/index',
|
||||
)
|
||||
credentials;
|
||||
|
||||
// =attributes
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreIndexController extends Controller {
|
||||
@controller('scopes/scope/credential-stores/index') credentialStores;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
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 ScopesScopeCredentialStoresIndexController extends Controller {
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handle save
|
||||
* @param {CredentialStoreModel} credentialStore
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess('notifications.save-success')
|
||||
async save(credentialStore) {
|
||||
await credentialStore.save();
|
||||
if (this.can.can('read model', credentialStore)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.credential-stores.credential-store',
|
||||
credentialStore,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo('scopes.scope.credential-stores');
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback changes on credential stores.
|
||||
* @param {CredentialStoreModel} credentialStore
|
||||
*/
|
||||
@action
|
||||
async cancel(credentialStore) {
|
||||
const { isNew } = credentialStore;
|
||||
credentialStore.rollbackAttributes();
|
||||
if (isNew) {
|
||||
await this.router.transitionTo('scopes.scope.credential-stores');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the credential store and redirects to index
|
||||
* @param {CredentialStoreModel} credentialStore
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(credentialStore) {
|
||||
await credentialStore.destroyRecord();
|
||||
await this.router.replaceWith('scopes.scope.credential-stores');
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update type of credential store
|
||||
* @param {string} type
|
||||
*/
|
||||
@action
|
||||
async changeType(type) {
|
||||
await this.router.replaceWith({ queryParams: { type } });
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeCredentialStoresNewController extends Controller {
|
||||
// =services
|
||||
@controller('scopes/scope/credential-stores/index') credentialStores;
|
||||
|
||||
// =attributes
|
||||
queryParams = ['type'];
|
||||
|
||||
Reference in new issue
Block a user