Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
future-pirate-king committed Dec 24, 2024
1 parent 4125ad8 commit 245c847
Show file tree
Hide file tree
Showing 96 changed files with 3,085 additions and 4,615 deletions.
13 changes: 13 additions & 0 deletions app/adapters/available-automated-device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import CommondrfNestedAdapter from './commondrf-nested';

export default class AvailableAutomatedDeviceAdapter extends CommondrfNestedAdapter {
setNestedUrlNamespace(projectId: string) {
this.namespace = `${this.namespace_v2}/projects/${projectId}`;
}
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'available-automated-device': AvailableAutomatedDeviceAdapter;
}
}
13 changes: 13 additions & 0 deletions app/adapters/available-manual-device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import CommondrfNestedAdapter from './commondrf-nested';

export default class AvailableManualDeviceAdapter extends CommondrfNestedAdapter {
setNestedUrlNamespace(projectId: string) {
this.namespace = `${this.namespace_v2}/projects/${projectId}`;
}
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'available-manual-device': AvailableManualDeviceAdapter;
}
}
30 changes: 30 additions & 0 deletions app/adapters/commondrf-nested.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import CommonDRFAdapter from './commondrf';
import { underscore } from '@ember/string';
import type ModelRegistry from 'ember-data/types/registries/model';

export default class CommondrfNestedAdapter extends CommonDRFAdapter {
namespace = '';
pathTypeName: keyof ModelRegistry | null = null;

pathForType(type: keyof ModelRegistry) {
return underscore(super.pathForType(this.pathTypeName || type));
}

handleResponse(
status: number,
headers: object,
payload: object,
requestData: object
) {
if (status >= 400 && this.namespace === '') {
throw new Error(
'setNestUrlNamespace should be called before making a request'
);
}

// reset namespace
this.namespace = '';

return super.handleResponse(status, headers, payload, requestData);
}
}
19 changes: 19 additions & 0 deletions app/adapters/ds-automated-device-preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import CommondrfNestedAdapter from './commondrf-nested';

export default class DsAutomatedDevicePreferenceAdapter extends CommondrfNestedAdapter {
_buildURL() {
return this.buildURLFromBase(
`${this.namespace}/ds_automated_device_preference`
);
}

setNestedUrlNamespace(profileId: string) {
this.namespace = `${this.namespace_v2}/profiles/${profileId}`;
}
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'ds-automated-device-preference': DsAutomatedDevicePreferenceAdapter;
}
}
17 changes: 17 additions & 0 deletions app/adapters/ds-automation-preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import CommondrfNestedAdapter from './commondrf-nested';

export default class DsAutomationPreferenceAdapter extends CommondrfNestedAdapter {
_buildURL() {
return this.buildURLFromBase(`${this.namespace}/automation_preference`);
}

setNestedUrlNamespace(profileId: string) {
this.namespace = `${this.namespace_v2}/profiles/${profileId}`;
}
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'ds-automation-preference': DsAutomationPreferenceAdapter;
}
}
19 changes: 19 additions & 0 deletions app/adapters/ds-manual-device-preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import CommondrfNestedAdapter from './commondrf-nested';

export default class DsManualDevicePreferenceAdapter extends CommondrfNestedAdapter {
_buildURL() {
return this.buildURLFromBase(
`${this.namespace}/ds_manual_device_preference`
);
}

setNestedUrlNamespace(profileId: string | number) {
this.namespace = `${this.namespace_v2}/profiles/${profileId}`;
}
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'ds-manual-device-preference': DsManualDevicePreferenceAdapter;
}
}
2 changes: 1 addition & 1 deletion app/adapters/dynamicscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class DynamicscanAdapter extends commondrf {

extendTime(modelName: string, snapshot: DynamicscanModel, time: number) {
const id = snapshot.id;
const url = this.buildURL(modelName, id);
const url = `${this.buildURL(modelName, id)}/extend`;

return this.ajax(url, 'PUT', {
data: { time },
Expand Down
24 changes: 22 additions & 2 deletions app/adapters/file.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import commondrf from './commondrf';
import CommonDRFAdapter from './commondrf';
import type DynamicscanModel from 'irene/models/dynamicscan';

interface ProjectFilesQuery {
projectId: string;
}

export default class File extends commondrf {
export default class File extends CommonDRFAdapter {
_buildURL(_: string | number, id: string | number) {
if (id) {
const baseurl = `${this.namespace_v2}/files`;

return this.buildURLFromBase(`${baseurl}/${encodeURIComponent(id)}`);
}
}

_buildNestedURL(modelName: string | number, projectId: string) {
const filesURL = `${this.namespace}/projects/${projectId}/files`;

return this.buildURLFromBase(filesURL);
}

urlForQuery(query: ProjectFilesQuery, modelName: string | number) {
return this._buildNestedURL(modelName, query.projectId);
}

async getLastDynamicScan(
fileId: string,
mode: number
): Promise<DynamicscanModel | null> {
const url = `${this._buildURL('file', fileId)}/dynamicscans?limit=1&mode=${mode}`;

const res = await this.ajax(url, 'GET');

if (res.results[0]) {
const normailized = this.store.normalize('dynamicscan', res.results[0]);

return this.store.push(normailized) as DynamicscanModel;
}

return null;
}
}

declare module 'ember-data/types/registries/adapter' {
Expand Down
46 changes: 0 additions & 46 deletions app/adapters/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import ProfileModel, {
type ProfileRegulatoryReportPreference,
type SaveReportPreferenceData,
type SetProfileRegulatorPrefData,
type SetProfileDSAutomatedDevicePrefData,
type SetProfileDSManualDevicePrefData,
} from 'irene/models/profile';

export default class ProfileAdapter extends commondrf {
Expand All @@ -19,50 +17,6 @@ export default class ProfileAdapter extends commondrf {
return this.buildURLFromBase(baseurl);
}

buildDSManualDevicePrefUrl(modelId: string | number) {
return (
this._buildURL('profile', modelId, this.namespace_v2) +
'/ds_manual_device_preference'
);
}

buildDSAutomatedDevicePrefUrl(modelId: string | number) {
return (
this._buildURL('profile', modelId, this.namespace_v2) +
'/ds_automated_device_preference'
);
}

async setDSManualDevicePrefData(
modelInstance: ProfileModel,
data: SetProfileDSManualDevicePrefData
) {
const url = this.buildDSManualDevicePrefUrl(modelInstance.get('id'));

return this.ajax(url, 'PUT', { data });
}

async setDSAutomatedDevicePrefData(
modelInstance: ProfileModel,
data: SetProfileDSAutomatedDevicePrefData
) {
const url = this.buildDSAutomatedDevicePrefUrl(modelInstance.get('id'));

return this.ajax(url, 'PUT', { data });
}

async getDsManualDevicePreference(modelInstance: ProfileModel) {
const url = this.buildDSManualDevicePrefUrl(modelInstance.get('id'));

return this.ajax(url, 'GET');
}

async getDsAutomatedDevicePreference(modelInstance: ProfileModel) {
const url = this.buildDSAutomatedDevicePrefUrl(modelInstance.get('id'));

return this.ajax(url, 'GET');
}

async saveReportPreference(
modelInstance: ProfileModel,
data: SaveReportPreferenceData
Expand Down
15 changes: 15 additions & 0 deletions app/components/ds-preference-provider/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{yield
(hash
dsManualDevicePreference=this.dsManualDevicePreference
loadingDsManualDevicePref=this.fetchDsManualDevicePref.isRunning
dsAutomatedDevicePreference=this.dsAutomatedDevicePreference
loadingDsAutomatedDevicePref=this.fetchDsAutomatedDevicePref.isRunning
fetchAvailableDevices=(perform this.fetchAvailableDevices)
availableManualDevices=this.availableDevicesResponse
loadingAvailableDevices=this.fetchAvailableDevices.isRunning
updateDsManualDevicePref=this.handleUpdateDsManualDevicePreference
updatingDsManualDevicePref=this.updateDsManualDevicePreference.isRunning
updateDsAutomatedDevicePref=this.handleUpdateDsAutomatedDevicePreference
updatingDsAutomatedDevicePref=this.updateDsAutomatedDevicePreference.isRunning
)
}}
Loading

0 comments on commit 245c847

Please sign in to comment.