From 7b7399182a1a9011b476d43ea08e1f0884dd393d Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Sat, 29 Jun 2019 16:10:42 +0200 Subject: [PATCH] Fix production scada Fix delete alarm attachment Fix reload page after login Added delete alarm-history --- .../Controllers/MachinesUsersController.cs | 12 ++++++ Step.Database/Controllers/UsersController.cs | 6 ++- Step.Model/Constants.cs | 2 + Step/Controllers/WebApi/ApiAlarmController.cs | 18 +++++++- .../WebApi/ApiMaintenanceController.cs | 3 -- .../alarms/components/alarm-detail.ts | 2 +- .../alarms/components/alarm-history.ts | 20 ++++----- .../alarms/components/alarm-history.vue | 2 +- .../app_modules/machine/components/login.ts | 8 ++-- .../maintenance/components/maintenance.ts | 13 +++--- .../components/card-axes-production.vue | 1 - .../scada/components/card-scada-production.ts | 18 +++++++- .../components/card-scada-production.vue | 41 ++++++++++++------- .../app_modules/scada/components/scada.vue | 22 ++++++---- .../components/depot-action-transfer.ts | 1 - .../under-the-hood/components/nc-hmi-menu.vue | 1 - .../under-the-hood/components/plc-softkeys.ts | 2 +- .../timeline-chart/timeline-chart-header.ts | 1 - Step/wwwroot/src/main.js | 2 +- Step/wwwroot/src/services/alarmsService.ts | 5 ++- Step/wwwroot/src/services/loginService.ts | 1 + 21 files changed, 118 insertions(+), 63 deletions(-) diff --git a/Step.Database/Controllers/MachinesUsersController.cs b/Step.Database/Controllers/MachinesUsersController.cs index 7e19a5b8..d2f88073 100644 --- a/Step.Database/Controllers/MachinesUsersController.cs +++ b/Step.Database/Controllers/MachinesUsersController.cs @@ -93,6 +93,18 @@ namespace Step.Database.Controllers return false; } + public bool RoleIsAdminOrHigher(int roleId) + { + var tmpRole = dbCtx.Roles + .ToList() + .First(X => X.RoleId == roleId); + + if (tmpRole == null) + return false; + else + return tmpRole.Level >= MIN_ADMIN_ROLE; + } + public int CompareUsersRole(int firstUserId, int secondUserId, int machineId) { MachineUserModel firstUser = FindByUserId(machineId, firstUserId); diff --git a/Step.Database/Controllers/UsersController.cs b/Step.Database/Controllers/UsersController.cs index 5c721386..f30bc14d 100644 --- a/Step.Database/Controllers/UsersController.cs +++ b/Step.Database/Controllers/UsersController.cs @@ -238,10 +238,12 @@ namespace Step.Database.Controllers return GetUserInfo(userId); } - public Boolean isCMSRole(int roleId) + public bool isCMSRole(int roleId) { + var tmpRole = dbCtx.Roles + .ToList() + .First(X => X.RoleId == roleId); - var tmpRole = dbCtx.Roles.ToList().First(X => X.RoleId == roleId); if (tmpRole == null) return true; else diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index d4ddfc20..4254ac62 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -20,6 +20,8 @@ namespace Step.Model } public const int MIN_CMS_ROLE = 100; + public const int MIN_ADMIN_ROLE = 30; + public enum ROLE_IDS { CMS_SERVICE = 1, diff --git a/Step/Controllers/WebApi/ApiAlarmController.cs b/Step/Controllers/WebApi/ApiAlarmController.cs index cfe10eee..151360d2 100644 --- a/Step/Controllers/WebApi/ApiAlarmController.cs +++ b/Step/Controllers/WebApi/ApiAlarmController.cs @@ -16,6 +16,7 @@ using System.Text; using System.Threading.Tasks; using System.Web.Http; using static Step.Model.Constants; +using static Step.Config.ServerConfig; namespace Step.Controllers.WebApi { @@ -23,11 +24,24 @@ namespace Step.Controllers.WebApi public class ApiAlarmController : ApiController { [Route("paginated"), HttpPost] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.READ)] public IHttpActionResult GetDataPaginated([FromBody]DTOAlarmsFilterModel filter) { if (!ModelState.IsValid) return BadRequest(ModelState); + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); + + bool canDelete = false; + using (MachinesUsersController machineUserController = new MachinesUsersController()) + { + RoleModel role = machineUserController.GetUserRole(MachineConfig.MachineId, Convert.ToInt32(userId.Value)); + canDelete = machineUserController.RoleIsAdminOrHigher(role.RoleId); + } + + // Retrieve plc messages Dictionary plcMessages = LanguageController.GetPlcAlarmsTranslations(filter.Language) .ToDictionary( x => Convert.ToInt32(x.Key.Split('_').Last()), // This function return "alarm_id" as id, i need only the id number @@ -41,7 +55,8 @@ namespace Step.Controllers.WebApi return Ok(new DTOPaginatedAlarmsModel() { Alarms = alarms, - Pages = pages + Pages = pages, + CanDelete = canDelete }); } } @@ -133,6 +148,7 @@ namespace Step.Controllers.WebApi { public List Alarms; public int Pages; + public bool CanDelete; } #region Note diff --git a/Step/Controllers/WebApi/ApiMaintenanceController.cs b/Step/Controllers/WebApi/ApiMaintenanceController.cs index edce3c27..1156f49e 100644 --- a/Step/Controllers/WebApi/ApiMaintenanceController.cs +++ b/Step/Controllers/WebApi/ApiMaintenanceController.cs @@ -13,11 +13,8 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Security.Claims; -using System.Threading; using System.Threading.Tasks; -using System.Web; using System.Web.Http; using static Step.Config.ServerConfig; using static Step.Model.Constants; diff --git a/Step/wwwroot/src/app_modules/alarms/components/alarm-detail.ts b/Step/wwwroot/src/app_modules/alarms/components/alarm-detail.ts index fc75039a..389ed3c3 100644 --- a/Step/wwwroot/src/app_modules/alarms/components/alarm-detail.ts +++ b/Step/wwwroot/src/app_modules/alarms/components/alarm-detail.ts @@ -97,7 +97,7 @@ export default class AlarmDetail extends Vue { let idx = $this.attaches.indexOf(attach); $this.attaches.splice(idx, 1); }); - }, null); + }, null, "modal"); } } diff --git a/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts b/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts index 2783a94d..975817e7 100644 --- a/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts +++ b/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts @@ -11,7 +11,7 @@ import { AlarmModel } from "@/src/store"; import { loginService } from "src/services"; import { alarmsService } from "src/services/alarmsService"; -import { awaiter } from "src/_base"; +import { awaiter, messageService } from "src/_base"; import { getColorFromName, isDarkColor } from "src/_base/utils"; import DatePicker from "vue2-datepicker"; @@ -73,6 +73,7 @@ export default class AlarmHistory extends Vue { currentPage: number = 0; itemsPerPage: number = 9; totalPages: number = 1; + canDelete: boolean = false; get currentUser() { @@ -111,7 +112,7 @@ export default class AlarmHistory extends Vue { this.$store.state.currentUser.language)); this.data = result.alarms; this.totalPages = result.pages; - + this.canDelete = result.canDelete; } async mounted() { @@ -126,14 +127,17 @@ export default class AlarmHistory extends Vue { this.filter.multiUser.push(this.users[index].username); } this.onloading = false; + + messageService.subscribeToChannel("login-reload", + () => { + this.filterChanged("","") + }); } async onChange(e) { this.newAttach = e.target.files[0]; let result = await awaiter(alarmsService.postAttachment(this.selectedAlarm.alarmId, this.selectedAlarm.source, this.newAttach)); this.attaches.push(result.data); - - // new MaintenanceService().uploadFile(this.selectedMaintenance, this.state.file); } user(id: number) { @@ -167,14 +171,6 @@ export default class AlarmHistory extends Vue { arraySourceFilter.push(item.id); }); - /*this.filter.multiUser.forEach(function (item) { - $this.users.forEach(function (items) { - if (items.username == item) { - arrayUserFilter.push(items.id); - } - }) - })*/ - this.filter.multiUser.forEach(function (item) { var user = $this.users.find(x => x.username == item) arrayUserFilter.push(user.id); diff --git a/Step/wwwroot/src/app_modules/alarms/components/alarm-history.vue b/Step/wwwroot/src/app_modules/alarms/components/alarm-history.vue index 707be3a5..32504567 100644 --- a/Step/wwwroot/src/app_modules/alarms/components/alarm-history.vue +++ b/Step/wwwroot/src/app_modules/alarms/components/alarm-history.vue @@ -85,7 +85,7 @@ - diff --git a/Step/wwwroot/src/app_modules/machine/components/login.ts b/Step/wwwroot/src/app_modules/machine/components/login.ts index 993b2dd9..0ab9c5ae 100644 --- a/Step/wwwroot/src/app_modules/machine/components/login.ts +++ b/Step/wwwroot/src/app_modules/machine/components/login.ts @@ -23,11 +23,11 @@ export default class Login extends Vue { var userNotAuthorized = false; this.logginIn = true; await awaiter(service.doLogin(this.user)).then(() => { - messageService.publishToChannel("update-maintenance"); + // messageService.publishToChannel("update-maintenance"); messageService.publishToChannel("update-softkeys-favorite"); - console.log((store.state as any).machineStatus.functions) - - // Check if user can access to current view, redirect to production + messageService.publishToChannel("login-reload"); + + // Check if user can access to current view, else redirect to production if(!this.checkIfUserIsAuthorized()){ userNotAuthorized = true; } diff --git a/Step/wwwroot/src/app_modules/maintenance/components/maintenance.ts b/Step/wwwroot/src/app_modules/maintenance/components/maintenance.ts index f6c1c649..87a6a5fe 100644 --- a/Step/wwwroot/src/app_modules/maintenance/components/maintenance.ts +++ b/Step/wwwroot/src/app_modules/maintenance/components/maintenance.ts @@ -16,6 +16,7 @@ declare let $: any; export default class Maintenance extends Vue { $route: any; + public maintenanceService = new MaintenanceService(); public get maintenances(): server.Maintenance[] { return (this.$store.state as AppModel).maintenance.maintenances; } @@ -68,11 +69,11 @@ export default class Maintenance extends Vue { async mounted() { this.isSCMVisualStyle; this.onloading = true; - messageService.subscribeToChannel("update-maintenance", args => { - awaiter(new MaintenanceService().GetMaintenances()); + messageService.subscribeToChannel("login-reload", args => { + awaiter(this.maintenanceService.GetMaintenances()); }); ModalHelper.HideModal("modal-internal"); - await awaiter(new MaintenanceService().GetMaintenances()); + await awaiter(this.maintenanceService.GetMaintenances()); if (this.$route.params.id) { this.selectedMaintenanceId = this.$route.params.id; this.enableMaintenance = false; @@ -112,7 +113,7 @@ export default class Maintenance extends Vue { } public async reloadMaintenances() { - await awaiter(new MaintenanceService().GetMaintenances()); + await awaiter(this.maintenanceService.GetMaintenances()); } public getTitleMaintenance(m) { @@ -193,11 +194,11 @@ export default class Maintenance extends Vue { ModalHelper.ShowModal(CreateMaintenance); } async getNoteMaintenance(m) { - await awaiter(new MaintenanceService().GetNotesMaintenance(m)); + await awaiter(this.maintenanceService.GetNotesMaintenance(m)); } async getAttachmentMaintenance(m) { - await awaiter(new MaintenanceService().GetAttachmentsMaintenance(m)); + await awaiter(this.maintenanceService.GetAttachmentsMaintenance(m)); } async selectMaintenance(m) { diff --git a/Step/wwwroot/src/app_modules/production/components/card-axes-production.vue b/Step/wwwroot/src/app_modules/production/components/card-axes-production.vue index 33a457bf..630b2f9a 100644 --- a/Step/wwwroot/src/app_modules/production/components/card-axes-production.vue +++ b/Step/wwwroot/src/app_modules/production/components/card-axes-production.vue @@ -138,7 +138,6 @@ export default { return this.$store.state.process.valueAxisSelected.machine; }, axesProgrammePos: function() { - debugger return this.$store.state.process.valueAxisSelected.programmePos; }, axesToGo: function() { diff --git a/Step/wwwroot/src/app_modules/scada/components/card-scada-production.ts b/Step/wwwroot/src/app_modules/scada/components/card-scada-production.ts index 89fc14de..97c18e44 100644 --- a/Step/wwwroot/src/app_modules/scada/components/card-scada-production.ts +++ b/Step/wwwroot/src/app_modules/scada/components/card-scada-production.ts @@ -9,6 +9,13 @@ import { scadaService } from "src/services/scadaService"; } }) export default class CardScadaProduction extends Vue { + + public topShift = 0; + public leftShift = 0; + + public SCADABOX_HEIGHT = 88; + public SCADABOX_WIDTH = 530; + get scadaId() { let currentIdScada; let scada = (this.$store.state as AppModel).scada.scadaItems.filter(s => s.isInProductionPage == true); @@ -31,8 +38,17 @@ export default class CardScadaProduction extends Vue { get scadaImage() { let scada = this.$store.getters.getScada(this.scadaId); - if (scada) + if (scada){ + var i = new Image(); + // Calculate items shift from the top left image corner n + i.onload = () => { + this.topShift = this.SCADABOX_HEIGHT/2 - i.height/2 ; + this.leftShift = this.SCADABOX_WIDTH/2 - i.width/2; + }; + + i.src = scada.backgroundImage; return scada.backgroundImage; + } return null; } diff --git a/Step/wwwroot/src/app_modules/scada/components/card-scada-production.vue b/Step/wwwroot/src/app_modules/scada/components/card-scada-production.vue index 80159fb5..e311ff3e 100644 --- a/Step/wwwroot/src/app_modules/scada/components/card-scada-production.vue +++ b/Step/wwwroot/src/app_modules/scada/components/card-scada-production.vue @@ -1,7 +1,11 @@