From 63ecfc2820c1083068670534be7f8083899f0e41 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Thu, 21 Mar 2019 11:28:37 +0100 Subject: [PATCH] Fix alarms user Loadin magazine --- Libs/CMS_CORE_Library.dll | Bin 9273856 -> 9273856 bytes .../Controllers/NcToolManagerController.cs | 3 +- Step.NC/NcHandler.cs | 3 +- Step/Controllers/WebApi/ApiAlarmController.cs | 588 +++++++++--------- .../alarms/components/alarm-history.ts | 17 +- .../tooling/components/tooling-equipment.ts | 1 - .../tooling/components/tooling-equipment.vue | 2 +- 7 files changed, 311 insertions(+), 303 deletions(-) diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index b3613909914347cb51cb2b9b2407570f5c10ab9f..3fcb6e8f7600c64d9af955fa0ae39f1fa8915c29 100644 GIT binary patch delta 3107 zcmZ{mdr(y88OG1IyDS$WamC#Qgar)>frSu7Kt-#@kVw5@EsF6Lq&8P$jR;y0OiUzR zGUA&Vl1ze{rtvaXgpDCJtz29cEr~?HC^4OAIxX5xV=|exnvV2&dEq;bGyUWD&G~-M zp0nRMXTJw3w|r!)1iPv%=ZosM-Iy@RVHie$VK@wn+Zr3Yyl}bejx{9NuqVNXr`Ztv z-`rO>F)v7s@To^i)+m>6gU@PF3#t6r2$f849h<7Y@%0?rV~cYodTfTh{C5_^wrRa# z*n(duQbvg5KDYS8wE4I@vhLnAQqrSTkJNW>IzrNVx_aCld*t3UM$!g&Bddh=ev(Az zI|6*mKACM*L+S8|->7G4UXxc%q4K5#<)Yu>_&Qx^N>d+`wb`q-Q(AL^T1ks=oI$TN zXRBM(isN?r7XE#5w|G?v&1gweIaG|}NP4ejy!wVNwRlrL3c2RnSSQ&koo%ooTPAj+wx`)XE_R2u;dpmhW5w2LyMk>r?P+zU z*d_Dp>^shG2KTS>lD1Rqusw7Y>+wr=TW7_b9T6K6KX_lu*}f?@O52%iUlN<7?Krm2 z(cF{Hlzho@br#6kRI!V-?O$aQRiAVg4414-XQ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;8^oH8wVLe*VxQDq5Vw%^`=ZSXo5{AE_H??^7D-m2Pf6nJDY0gS9c4S7 zu5~U_Z8ZI2E_$T$Vvd?XT{!+9`7Y(6Yf3QAqehGaDC%;KYM}y*YiKXVbo%=8UbT%j zUx~LYGe})Zq;ps7nSFhd=t$%~NkE@?`}$)G1RuLv8aeJxQ8Z(VJ0ipH6vbyUyHf@&GP_d-tupfjzrXQey^5~<>milvh#Bt1 zKS<6nM;PDVW{a&=hgJFk<*po?Z^^Cv=8zg@vAH)K%(nn52mztM2J9dVgo6ms4@A}; z%#T_S2#3@8Az zK>$1p=770i9(WEEg6F~SK@pe_7JwJPLhvGZ2`mCHgFk>*z^h;}cnvH8uY)(hQm_mZ zgXN$El!6stC0GSkgEFuNl!LY4kKj$P4y*@nfj@x_paQ%N-T@nH(|2vExMazlTY0>6 fb8P>>CmTP$dTrK>n!MA2usZLK+Uup8qr-m%_YGM+ diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs index 1644b5f5..e7cd125f 100644 --- a/Step.Database/Controllers/NcToolManagerController.cs +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -484,7 +484,8 @@ namespace Step.Database.Controllers dbCtx.Shanks.Attach(shank); // Set ids with new positions shank.MagazineId = magazineId; - //shank.PositionId = positionId; + shank.PositionId = positionId; + // Set original Ids shank.OriginMagazineId = magazineId; shank.OriginPositionId = positionId; diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 35a2256c..84b4c9ec 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1562,8 +1562,7 @@ namespace Step.NC if (!ToolManagerConfig.OffsetOpt) config.OffsetOptionActive = false; - if (!ToolManagerConfig.OffsetOpt) - categories.Add("offset"); + categories.Add("offset"); if (!ToolManagerConfig.TcpOpt) categories.Add("tcp"); diff --git a/Step/Controllers/WebApi/ApiAlarmController.cs b/Step/Controllers/WebApi/ApiAlarmController.cs index 1717bbe4..902900cd 100644 --- a/Step/Controllers/WebApi/ApiAlarmController.cs +++ b/Step/Controllers/WebApi/ApiAlarmController.cs @@ -1,64 +1,64 @@ -using Step.Database.Controllers; -using Step.Model.DatabaseModels; -using Step.Model.DTOModels.AlarmModels; -using Step.NC; -using Step.Provider; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; +using Step.Database.Controllers; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels.AlarmModels; +using Step.NC; +using Step.Provider; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; using System.Net.Http.Headers; -using System.Security.Claims; +using System.Security.Claims; using System.Text; -using System.Threading.Tasks; -using System.Web.Http; -using static Step.Model.Constants; - -namespace Step.Controllers.WebApi -{ - [RoutePrefix("api/alarm")] - public class ApiAlarmController : ApiController - { - [Route("paginated"), HttpPost] - public IHttpActionResult GetDataPaginated([FromBody]DTOAlarmsFilterModel filter) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - 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 - x => x.Value - ); - - using (AlarmsController alarm = new AlarmsController()) - { - List alarms = alarm.GetPaginatedWithFilter(filter.Title, filter.Sources, filter.Page, filter.PageSize, filter.StartDate.Value, filter.EndDate, filter.UserIds, plcMessages, out int pages); - - return Ok(new DTOPaginatedAlarmsModel() - { - Alarms = alarms, - Pages = pages - }); - } +using System.Threading.Tasks; +using System.Web.Http; +using static Step.Model.Constants; + +namespace Step.Controllers.WebApi +{ + [RoutePrefix("api/alarm")] + public class ApiAlarmController : ApiController + { + [Route("paginated"), HttpPost] + public IHttpActionResult GetDataPaginated([FromBody]DTOAlarmsFilterModel filter) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + 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 + x => x.Value + ); + + using (AlarmsController alarm = new AlarmsController()) + { + List alarms = alarm.GetPaginatedWithFilter(filter.Title, filter.Sources, filter.Page, filter.PageSize, filter.StartDate.Value, filter.EndDate, filter.UserIds, plcMessages, out int pages); + + return Ok(new DTOPaginatedAlarmsModel() + { + Alarms = alarms, + Pages = pages + }); + } } - [Route("export"), HttpPost] - public IHttpActionResult ExportAlarms([FromBody]DTOAlarmsFilterModel filter) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - 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 - x => x.Value + [Route("export"), HttpPost] + public IHttpActionResult ExportAlarms([FromBody]DTOAlarmsFilterModel filter) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + 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 + x => x.Value ); - using (AlarmsController alarm = new AlarmsController()) - { + using (AlarmsController alarm = new AlarmsController()) + { List alarms = alarm.GetPaginatedWithFilter(filter.Title, filter.Sources, 0, int.MaxValue, filter.StartDate.Value, filter.EndDate, filter.UserIds, plcMessages, out int pages); Dictionary AlmPLCTras = LanguageController.GetPlcAlarmsTranslations(filter.Language); @@ -71,9 +71,9 @@ namespace Step.Controllers.WebApi alm = AlmPLCTras["alarm_"+model.AlarmId]; csv += model.ToCsvString(alm) + Environment.NewLine; } - - - + + + var stream = new MemoryStream(Encoding.UTF8.GetBytes(csv),0, Encoding.UTF8.GetBytes(csv).Length, false,true); var result = new HttpResponseMessage(HttpStatusCode.OK) @@ -86,240 +86,240 @@ namespace Step.Controllers.WebApi }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv"); - return ResponseMessage(result); - - - } - - } - - [Route("data"), HttpPost] - public IHttpActionResult GetAlarmsData(int pageSize) - { - using (AlarmsController alarmController = new AlarmsController()) - { - var alarms = alarmController.GetAlarmsData(pageSize); - - return Ok(alarms); - } - } - - public class DTOPaginatedAlarmsModel - { - public List Alarms; - public int Pages; - } - - #region Note - - [Route("{alarmDescId:int}/{source:int}/note"), HttpGet] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.READ)] - public IHttpActionResult GetAlarmNotes(int alarmDescId, ALARM_SOURCE source) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); - if (dbAlarm == null) - return NotFound(); - - // Update data - List notes = alarmsController.GetNotesByAlarmDescId(alarmDescId, source); - - return Ok(notes); - } - } - - [Route("{alarmDescId:int}/{source:int}/note"), HttpPost] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] - public IHttpActionResult AddAlarmNote(int alarmDescId, ALARM_SOURCE source, DTONewAlarmNoteModel note) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); - - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); - if (dbAlarm == null) - return NotFound(); - - // Update data - DTOAlarmNoteModel notes = alarmsController.CreateNote(Convert.ToInt32(userId.Value), alarmDescId, source, note); - - return Ok(notes); - } - } - - [Route("{alarmDescId:int}/note/{noteId:int}"), HttpPut] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] - public IHttpActionResult EditAlarmNote(int noteId, DTONewAlarmNoteModel newNote) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); - - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmNoteModel dbNote = alarmsController.FindNoteById(noteId); - if (dbNote == null) - return NotFound(); - - // Check if user is different - if (dbNote.UserId != Convert.ToInt32(userId.Value)) - return Unauthorized(); - - // Update data - DTOAlarmNoteModel notes = alarmsController.UpdateNote(dbNote, newNote); - - return Ok(notes); - } - } - - [Route("{alarmDescId:int}/note/{noteId:int}"), HttpDelete] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] - public IHttpActionResult DeleteAlarmNote(int noteId) - { - if (!ModelState.IsValid) - return BadRequest(ModelState); - - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); - - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmNoteModel dbNote = alarmsController.FindNoteById(noteId); - if (dbNote == null) - return NotFound(); - - // Check if user is different - if (dbNote.UserId != Convert.ToInt32(userId.Value)) - return Unauthorized(); - - // Update data - alarmsController.DeleteNote(dbNote.NoteId); - - return Ok(); - } - } - - #endregion Note - - #region Attachment - - [Route("{alarmDescId:int}/{source:int}/attachments"), HttpGet] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.READ)] - public IHttpActionResult GetAttachmentsByAlarmId(int alarmDescId, ALARM_SOURCE source) - { - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); - if (dbAlarm == null) - return NotFound(); - - List attachments = alarmsController.FindAttachmentByAlarmDescId(alarmDescId, source); - - return Ok(attachments); - } - } - - [Route("attachment/{attachmentId:int}"), HttpGet] - public IHttpActionResult GetAttachment(int attachmentId) - { - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if attachment exist in db or physically - AlarmFileModel attachment = alarmsController.FindAttachmentById(attachmentId); - if (attachment == null) - return NotFound(); - if (!File.Exists(ALARM_ATTACHMENT_PATH + attachment.LocalFileName)) - return NotFound(); - - return new FileResult(ALARM_ATTACHMENT_PATH + attachment.LocalFileName); - } - } - - [Route("{alarmDescId:int}/{source:int}/attachment"), HttpPost] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] - public async Task AddAttachment(int alarmDescId, ALARM_SOURCE source) - { - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); - - // Check whether the POST operation is MultiPart? - if (!Request.Content.IsMimeMultipartContent()) - throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); - - // Create CustomMultipartFormDataStreamProvider - CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider(ALARM_ATTACHMENT_PATH); - List files = new List(); - - // Read all contents of multipart message into CustomMultipartFormDataStreamProvider. - var result = await Request.Content.ReadAsMultipartAsync(provider); - - AlarmFileModel attachment = null; - using (AlarmsController alarmsController = new AlarmsController()) - { - // Check if alarm desc exists - AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); - if (dbAlarm == null) - return NotFound(); - - // TODO: Remove foreach - foreach (MultipartFileData file in provider.FileData) - { - var fileName = Path.GetFileName(file.LocalFileName); - - files.Add(fileName); - attachment = alarmsController - .AddAttachment(file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty), fileName, alarmDescId, Convert.ToInt32(userId.Value), source); - } - } - - // Send OK Response along with saved file names to the client. - return Ok(attachment); - } - - [Route("attachment/{attachmentId:int}"), HttpDelete] - [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] - public IHttpActionResult DeleteAttachment(int attachmentId) - { - var identity = User.Identity as ClaimsIdentity; - // Find user id from the bearer token - var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); - - using (AlarmsController alarmsController = new AlarmsController()) - { - // Get single file - AlarmFileModel attachment = alarmsController.FindAttachmentById(attachmentId); - // Check if exist in db or physically - if (attachment == null) - return NotFound(); - // Check user - if (attachment.UserId != Convert.ToInt32(userId.Value)) - return Unauthorized(); - - alarmsController.DeleteAttachment(attachment); - - return Ok(); - } - } - - #endregion Attachment - } + return ResponseMessage(result); + + + } + + } + + [Route("data"), HttpPost] + public IHttpActionResult GetAlarmsData(int pageSize) + { + using (AlarmsController alarmController = new AlarmsController()) + { + var alarms = alarmController.GetAlarmsData(pageSize); + + return Ok(alarms); + } + } + + public class DTOPaginatedAlarmsModel + { + public List Alarms; + public int Pages; + } + + #region Note + + [Route("{alarmDescId:int}/{source:int}/note"), HttpGet] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.READ)] + public IHttpActionResult GetAlarmNotes(int alarmDescId, ALARM_SOURCE source) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); + if (dbAlarm == null) + return NotFound(); + + // Update data + List notes = alarmsController.GetNotesByAlarmDescId(alarmDescId, source); + + return Ok(notes); + } + } + + [Route("{alarmDescId:int}/{source:int}/note"), HttpPost] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] + public IHttpActionResult AddAlarmNote(int alarmDescId, ALARM_SOURCE source, DTONewAlarmNoteModel note) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); + + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); + if (dbAlarm == null) + return NotFound(); + + // Update data + DTOAlarmNoteModel notes = alarmsController.CreateNote(Convert.ToInt32(userId.Value), alarmDescId, source, note); + + return Ok(notes); + } + } + + [Route("{alarmDescId:int}/note/{noteId:int}"), HttpPut] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] + public IHttpActionResult EditAlarmNote(int noteId, DTONewAlarmNoteModel newNote) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); + + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmNoteModel dbNote = alarmsController.FindNoteById(noteId); + if (dbNote == null) + return NotFound(); + + // Check if user is different + if (dbNote.UserId != Convert.ToInt32(userId.Value)) + return Unauthorized(); + + // Update data + DTOAlarmNoteModel notes = alarmsController.UpdateNote(dbNote, newNote); + + return Ok(notes); + } + } + + [Route("{alarmDescId:int}/note/{noteId:int}"), HttpDelete] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] + public IHttpActionResult DeleteAlarmNote(int noteId) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); + + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmNoteModel dbNote = alarmsController.FindNoteById(noteId); + if (dbNote == null) + return NotFound(); + + // Check if user is different + if (dbNote.UserId != Convert.ToInt32(userId.Value)) + return Unauthorized(); + + // Update data + alarmsController.DeleteNote(dbNote.NoteId); + + return Ok(); + } + } + + #endregion Note + + #region Attachment + + [Route("{alarmDescId:int}/{source:int}/attachments"), HttpGet] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.READ)] + public IHttpActionResult GetAttachmentsByAlarmId(int alarmDescId, ALARM_SOURCE source) + { + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); + if (dbAlarm == null) + return NotFound(); + + List attachments = alarmsController.FindAttachmentByAlarmDescId(alarmDescId, source); + + return Ok(attachments); + } + } + + [Route("attachment/{attachmentId:int}"), HttpGet] + public IHttpActionResult GetAttachment(int attachmentId) + { + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if attachment exist in db or physically + AlarmFileModel attachment = alarmsController.FindAttachmentById(attachmentId); + if (attachment == null) + return NotFound(); + if (!File.Exists(ALARM_ATTACHMENT_PATH + attachment.LocalFileName)) + return NotFound(); + + return new FileResult(ALARM_ATTACHMENT_PATH + attachment.LocalFileName); + } + } + + [Route("{alarmDescId:int}/{source:int}/attachment"), HttpPost] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] + public async Task AddAttachment(int alarmDescId, ALARM_SOURCE source) + { + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); + + // Check whether the POST operation is MultiPart? + if (!Request.Content.IsMimeMultipartContent()) + throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + + // Create CustomMultipartFormDataStreamProvider + CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider(ALARM_ATTACHMENT_PATH); + List files = new List(); + + // Read all contents of multipart message into CustomMultipartFormDataStreamProvider. + var result = await Request.Content.ReadAsMultipartAsync(provider); + + AlarmFileModel attachment = null; + using (AlarmsController alarmsController = new AlarmsController()) + { + // Check if alarm desc exists + AlarmOccurrencesModel dbAlarm = alarmsController.FindById(alarmDescId, source); + if (dbAlarm == null) + return NotFound(); + + // TODO: Remove foreach + foreach (MultipartFileData file in provider.FileData) + { + var fileName = Path.GetFileName(file.LocalFileName); + + files.Add(fileName); + attachment = alarmsController + .AddAttachment(file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty), fileName, alarmDescId, Convert.ToInt32(userId.Value), source); + } + } + + // Send OK Response along with saved file names to the client. + return Ok(attachment); + } + + [Route("attachment/{attachmentId:int}"), HttpDelete] + [WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.ALARM_CMD, Action = ACTIONS.WRITE)] + public IHttpActionResult DeleteAttachment(int attachmentId) + { + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault(); + + using (AlarmsController alarmsController = new AlarmsController()) + { + // Get single file + AlarmFileModel attachment = alarmsController.FindAttachmentById(attachmentId); + // Check if exist in db or physically + if (attachment == null) + return NotFound(); + // Check user + if (attachment.UserId != Convert.ToInt32(userId.Value)) + return Unauthorized(); + + alarmsController.DeleteAttachment(attachment); + + return Ok(); + } + } + + #endregion Attachment + } } \ No newline at end of file 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 eee2b566..3b7d576f 100644 --- a/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts +++ b/Step/wwwroot/src/app_modules/alarms/components/alarm-history.ts @@ -130,13 +130,15 @@ export default class AlarmHistory extends Vue { this.filter.sources.forEach(function (item) { arraySourceFilter.push(item.id); }); - + this.filter.multiUser.forEach(function (item) { - $this.users.forEach(function (items) { + var user = $this.users.find(x => x.username == item) + arrayUserFilter.push(user.id); + /*$this.users.forEach(function (items) { if (items.username == item) { arrayUserFilter.push(items.id); } - }) + })*/ }) // this.paginationData = await alarmsService.getAlarmsData(); @@ -152,6 +154,7 @@ export default class AlarmHistory extends Vue { this.onloading = true; this.users = await awaiter(loginService.getAllUsers()); + this.users.unshift({ id: -1, username: this.$options.filters.localize("alarm_history_users_not_user", "Nessun utente") }); this.paginationData = await awaiter(alarmsService.getAlarmsData()); @@ -191,13 +194,19 @@ export default class AlarmHistory extends Vue { arraySourceFilter.push(item.id); }); - this.filter.multiUser.forEach(function (item) { + /*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); }) + await awaiter(alarmsService.exportAlarms(this.filter.title, arraySourceFilter, arrayUserFilter, from, to)); } diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts index 65e304f0..8454a507 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.ts @@ -443,7 +443,6 @@ export default class toolingEquipment extends Vue { } } - console.log(this.selectedTool, this.selectedEquipment) this.enableAddOffsetToTool = false; this.enableToolModify = false; this.disableList = false; diff --git a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue index e65dff06..c5dbef94 100644 --- a/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue +++ b/Step/wwwroot/src/app_modules/tooling/components/tooling-equipment.vue @@ -74,7 +74,7 @@
- +
{{'tooling_equipment_editlabel' | localize("Modifica utensile %d", selectedTool.id,selectedTool.familyName)}}
{{'tooling_equipment_editlabel' | localize("Modifica utensile %d", selectedTool.id)}}
{{'tooling_equipment_newlabel' | localize("Creazione Nuovo Utensile")}}