Export of Alarm History
This commit is contained in:
@@ -221,6 +221,7 @@ namespace CMS_Client.View
|
||||
Browser.KeyboardHandler.OnKeyEvent += BrowserKeyPress;
|
||||
Browser.ContextMenuHandler.OnBeforeContextMenu += BrowserContextMenu;
|
||||
Browser.DisplayHandler.OnConsoleMessage += BrowserConsoleMessage;
|
||||
Browser.DownloadHandler.OnBeforeDownload += BeforeDownload;
|
||||
//Filter only < Win_10 Platform
|
||||
if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10)
|
||||
ChromiumWebBrowser.RemoteProcessCreated += (e) => { e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged; };
|
||||
@@ -231,6 +232,12 @@ namespace CMS_Client.View
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#region BROWSER_EVENT_HANDLERS_METHODS
|
||||
|
||||
|
||||
private void BeforeDownload(object sender, CfxOnBeforeDownloadEventArgs e)
|
||||
{
|
||||
e.Callback.Continue("",true);
|
||||
}
|
||||
|
||||
//On browser Load-Error. Event Handler called by Browser
|
||||
private void BrowserLoadsError(object sender, CfxOnLoadErrorEventArgs e)
|
||||
{
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace Step.Model.DTOModels.AlarmModels
|
||||
|
||||
bool[] statusBits = new BitArray(new int[] { obj.Processes })
|
||||
.Cast<bool>()
|
||||
.ToArray();
|
||||
|
||||
.ToArray();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (statusBits[i])
|
||||
@@ -56,6 +56,21 @@ namespace Step.Model.DTOModels.AlarmModels
|
||||
Users = obj.Users.Select(x => x.UserId).ToList()
|
||||
};
|
||||
}
|
||||
public string ToCsvString(String alarm)
|
||||
{
|
||||
var alarmCode = 0;
|
||||
var alarmText = alarm;
|
||||
|
||||
if (Source == ALARM_SOURCE.NC)
|
||||
{
|
||||
alarmCode = AlarmId & 0xFFFFFF;
|
||||
alarmText = Title.Replace(System.Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " ").Replace(";", ",");
|
||||
}
|
||||
else
|
||||
alarmCode = AlarmId;
|
||||
|
||||
return alarmCode + ";" + alarmText + ";" + Source + ";" + Type + ";" + String.Join("|", Processes.Select(x => x.ToString()).ToArray()) + ";" + TimeStamp + ";" + String.Join("|", Users.Select(x => x.ToString()).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public class DTOAlarmsFilterModel
|
||||
|
||||
@@ -9,7 +9,9 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using static Step.Model.Constants;
|
||||
@@ -41,6 +43,54 @@ namespace Step.Controllers.WebApi
|
||||
Pages = pages
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Route("export"), HttpPost]
|
||||
public IHttpActionResult ExportAlarms([FromBody]DTOAlarmsFilterModel filter)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
Dictionary<int, string> 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<DTOAlarmHistoricModel> alarms = alarm.GetPaginatedWithFilter(filter.Title, filter.Sources, 0, int.MaxValue, filter.StartDate.Value, filter.EndDate, filter.UserIds, plcMessages, out int pages);
|
||||
|
||||
Dictionary<string, string> AlmPLCTras = LanguageController.GetPlcAlarmsTranslations(filter.Language);
|
||||
|
||||
string csv = "";
|
||||
foreach (DTOAlarmHistoricModel model in alarms)
|
||||
{
|
||||
var alm = "";
|
||||
if(model.Source == ALARM_SOURCE.PLC)
|
||||
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)
|
||||
{
|
||||
Content = new ByteArrayContent(stream.GetBuffer())
|
||||
};
|
||||
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
|
||||
{
|
||||
FileName = "AlarmExport.csv"
|
||||
};
|
||||
result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");
|
||||
|
||||
return ResponseMessage(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Route("data"), HttpPost]
|
||||
|
||||
@@ -179,6 +179,28 @@ export default class AlarmHistory extends Vue {
|
||||
this.notes = await awaiter(alarmsService.getNote(this.selectedAlarm.alarmId, this.selectedAlarm.source));
|
||||
}
|
||||
|
||||
async exportAlarms(){
|
||||
let $this = this;
|
||||
let from = this.filter.interval && this.filter.interval.length ? this.filter.interval[0] : null;
|
||||
let to = this.filter.interval && this.filter.interval.length ? this.filter.interval[1] : null;
|
||||
|
||||
let arraySourceFilter: Array<number> = [];
|
||||
let arrayUserFilter: Array<number> = [];
|
||||
|
||||
this.filter.sources.forEach(function (item) {
|
||||
arraySourceFilter.push(item.id);
|
||||
});
|
||||
|
||||
this.filter.multiUser.forEach(function (item) {
|
||||
$this.users.forEach(function (items) {
|
||||
if (items.username == item) {
|
||||
arrayUserFilter.push(items.id);
|
||||
}
|
||||
})
|
||||
})
|
||||
await awaiter(alarmsService.exportAlarms(this.filter.title, arraySourceFilter, arrayUserFilter, from, to));
|
||||
}
|
||||
|
||||
updateLimitation() {
|
||||
if (this.limitationList > 3)
|
||||
this.limitationList = 3;
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-button">
|
||||
<button class="btn">
|
||||
<button class="btn" @click="exportAlarms">
|
||||
<i class="fa fa-download"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -749,7 +749,6 @@ public isEquipmentSelected(offset){
|
||||
() => {
|
||||
if(this.isSiemens){
|
||||
awaiter(new ToolingService().DeleteEdgeData(tool, model).then(response => {
|
||||
|
||||
this.selectedEquipment = null;
|
||||
this.enableOffsets = false;
|
||||
this.enableParameters = true;
|
||||
|
||||
@@ -11,6 +11,32 @@ export class AlarmsService extends baseRestService {
|
||||
return (await this.Post(this.BASE_URL + `data?pagesize=${pagesize}`, null, true)) as any;
|
||||
}
|
||||
|
||||
async exportAlarms(title: string, sources: Array<number>, users?: Array<number>, fromDate?: Date, toDate?: Date)
|
||||
{
|
||||
|
||||
let result = await this.Post(this.BASE_URL + "export",
|
||||
{
|
||||
"page": 0,
|
||||
"pageSize": 100,
|
||||
"title": title,
|
||||
"sources": sources,
|
||||
"startDate": fromDate,
|
||||
"endDate": toDate,
|
||||
"userIds": users,
|
||||
language: "en"
|
||||
}
|
||||
, true).then(function (response) {
|
||||
const url = window.URL.createObjectURL(new Blob([response]));
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', 'AlarmExport.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getAlarms(title: string, sources: Array<number>, users?: Array<number>, fromDate?: Date, toDate?: Date, page: number = 0, pagesize: number = 100):
|
||||
Promise<{pages:number, alarms:AlarmModel[]}> {
|
||||
let result = await this.Post<{pages:number, alarms:AlarmModel[]}>(this.BASE_URL + "paginated",
|
||||
@@ -65,7 +91,6 @@ export class AlarmsService extends baseRestService {
|
||||
ModalHelper.ShowModal(ModalIframe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user