I want to change the Fleet name in edit mode.But its not getting changed.Can u please help me in detail on how to solve this? #12489
Description
let $injector = widgetContext.$scope.$injector;
let customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));
let assetService = $injector.get(widgetContext.servicesMap.get('assetService'));
let attributeService = $injector.get(widgetContext.servicesMap.get('attributeService'));
let http = $injector.get(widgetContext.servicesMap.get('http'));
openEditAssetDialog();
function openEditAssetDialog() {
customDialog.customDialog(htmlTemplate, EditAssetDialogController).subscribe();
}
function EditAssetDialogController(instance) {
let vm = instance;
vm.allowWrite = false;
vm.asset = null;
vm.editAssetFormGroup = vm.fb.group({
assetLabel: ['', [vm.validators.required]],
nextPmHours: ['', [vm.validators.pattern(/^\d+$/)]]
});
vm.cancel = function () {
vm.dialogRef.close(null);
};
vm.save = function () {
vm.editAssetFormGroup.markAsPristine();
let nextPmHours = vm.editAssetFormGroup.get('nextPmHours').value;
let assetLabel = vm.editAssetFormGroup.get('assetLabel').value;
if (vm.allowWrite) {
attributeService
.saveEntityAttributes(entityId, 'SERVER_SCOPE', [
{ key: 'assetLabel', value: assetLabel },
{ key: 'nextPmHours', value: nextPmHours }
])
.subscribe(() => {
widgetContext.updateWidgetParams();
widgetContext.detectChanges();
});
}
let params = widgetContext.stateController.getStateParams();
params.nextPmHours = nextPmHours;
params.assetLabel = assetLabel;
widgetContext.stateController.updateState(params);
vm.cancel();
};
getEntityInfo(vm);
getPermissions(vm);
}
// Fetch Entity Info
function getEntityInfo(vm) {
console.log("Fetching entity info...");
assetService.getAsset(entityId).subscribe((asset) => {
console.log("Asset fetched: ", asset);
attributeService
.getEntityAttributes(entityId, 'SERVER_SCOPE', ['assetLabel', 'nextPmHours'])
.subscribe(
(attributes) => {
console.log("Attributes fetched: ", attributes);
vm.attributes = {};
for (let i = 0; i < attributes.length; i++) {
vm.attributes[attributes[i].key] = attributes[i].value;
}
vm.asset = asset;
console.log("Populating form with attributes...");
$("#title").text(`Edit ${vm.asset.name}`);
vm.editAssetFormGroup.patchValue({
assetLabel: vm.attributes.assetLabel || '',
nextPmHours: vm.attributes.nextPmHours || ''
});
},
(error) => {
console.error("Error fetching attributes:", error);
}
);
});
}
function getPermissions(vm) {
http.get('/api/permissions/allowedPermissions').subscribe(
(response) => {
const permissions = response.userPermissions.genericPermissions;
if (
permissions &&
(permissions.ASSET && permissions.ASSET.includes('WRITE')) ||
(permissions.ALL && permissions.ALL[0] === 'ALL')
) {
vm.allowWrite = true;
} else {
console.error("No write permissions available.");
}
},
(error) => {
console.error("Error fetching permissions: ", error);
}
);
}
This is js code that i have give in actions for the Edit section