# <center>12^th^ August, 2019</center> ###### tags: `Daily Internship Documentation` --- ## 29^th^ Day of Internship ## Summary URL: * [**NTUST_RepairmanApp Github ver 2019.08.**](https://github.com/ianjoseph2204/NTUST_RepairmanApp/tree/) --- ## Documentation ### 1. Home Page #### 1.1 home.page.ts 1. Move the *ngOnInit()* method to be below the constructor. ```typescript=46 async ngOnInit() { // initialize this.loadReady = false; this.fragmentTitle = this.fragmentTitleArray[1]; this.currentTime = UnitConverter.convertDateToApiTimeFormat(new Date()); // dummy data this.device_id = "MA_03_01"; this.employee_id = "1"; let doneMissionRawData = await this.api.getAssignmentDone(this.device_id, this.employee_id); if (doneMissionRawData.length !== 0) { this.doneMissionList = await this.processDataDoneMission(doneMissionRawData); } else { this.doneMissionList = null; } let todayMissionRawData = await this.api.getAssignmentToday(this.device_id, this.employee_id, this.currentTime); if (todayMissionRawData.length !== 0) { this.todayMissionList = await this.processDataTodayMission(todayMissionRawData); } else { this.todayMissionList = null; } let futureMissionRawData = await this.api.getAssignmentNext(this.device_id, this.employee_id, this.currentTime); if (futureMissionRawData.length !== 0) { this.futureMissionList = await this.processDataFutureMission(futureMissionRawData); } else { this.futureMissionList = null; } this.loadReady = true; } ``` 2. Create a method to safe some data into Preference that needed for the Report Repair page. ```typescript=98 /** * Safe the Report Detail to Preference. */ async setDetailReportToPref(data: any){ await this.pref.setData(StaticVariables.KEY__DEVICE_ID, data['DeviceID']); await this.pref.setData(StaticVariables.KEY__DEVICE_TYPE, data['DeviceType']); await this.pref.setData(StaticVariables.KEY__EMPLOYEE_NAME, data['Repairman']); await this.pref.setData(StaticVariables.KEY__DEVICE_BUILDING_LOC, data['DeviceBuildingLocation']); await this.pref.setData(StaticVariables.KEY__DEVICE_PLACEMENT_LOC, data['DevicePlacementPosition']); await this.pref.setData(StaticVariables.KEY__PROBLEM_DESCRIPTION, data['ProblemDescription']); } ``` 3. Create a simplified method to add time into JSON object. ```typescript=241 /** * Add after processed time stamp data into JSON. * @param Data Array of processed data. */ addTimeToJSON (Data: any){ let newDate = UnitConverter.convertApiTimeToDate(Data[0]['MissionTime']); let newDayString = this.dayNameArray[newDate.getDay()]; let newMonthString = this.monthNameArray[newDate.getMonth()]; let DateString = newMonthString + " " + newDate.getDate(); this.loadReady = true; return { "DateString": DateString , "DayString": newDayString , "Date": newDate , "Data": Data }; } ``` 4. Create a method to add detail informations into JSON object: ```typescript=286 /** * Add time stamp & machine detail to JSON. * @param dataJSON rawData from api. */ async addDetailsToJSON(dataJSON: any){ // add time stamp and machine details into json let dataAddOn = []; for (let i = 0 ; i < dataJSON.length ; i++) { let Data = dataJSON[i]; let dateDetails = HomePage.getDateDetail(Data['RepairCallTime']); let machineDetails = await this.api.getDispenserDetail(Data['Device_ID']); let newJson = { dateDetails, Data, machineDetails }; dataAddOn.push(newJson); } // grouping by date return dataAddOn; } ``` 5. Add DeviceID, DeviceType, DeviceNumber, DeviceBuildingLocation, DevicePlacementPosition, & ProblemDescription into the NewData variable of the *processDataDoneMission*, *processDataTodayMission*, & *processDataFutureMission* methods: * processDataDoneMission: ```typescript=343 let newData = { "ClientName": "..." , "ClientAddress": "..." , "MissionTime": getData['RepairCallTime'] , "MissionTimeOnlyHour": MissionTimeOnlyHour , "ClientPhone": "..." , "ClientContactPerson": "..." , "DeviceID": "MA_04_01", "DeviceType": getObject['Data'][j]['machineDetails']['Type'] , "DeviceNumber": "..." , "DeviceBuildingLocation": "Management Building 4F", "DevicePlacementPosition": "next to the elevator", "ErrorCode": getData['ErrorType'] , "ProblemDescription": getData['Description'] , "NotificationTime": getData['NotifyTime'] , "Repairman": getData['Maintainer'] , "ClientNumber": "..." , "MissionNumber": getData['MissionNumber'] , "ReportIndex": getData['Complete_Index'] , "ReportImages": ReportImages }; ``` * processDataTodayMission: ```typescript=388 let newData = { "ClientName": "..." , "ClientAddress": "..." , "MissionTime": getObject['Data']['RepairCallTime'] , "MissionTimeOnlyHour": MissionTimeOnlyHour , "ClientPhone": "..." , "ClientContactPerson": "..." , "DeviceID": "...", "DeviceType": getObject['machineDetails']['Type'] , "DeviceNumber": "..." , "DeviceBuildingLocation": "...", "DevicePlacementPosition": "...", "ErrorCode": getObject['Data']['ErrorType'] , "ProblemDescription": getObject['Data']['Description'] , "NotificationTime": getObject['Data']['NotifyTime'] , "Repairman": getObject['Data']['Maintainer'] , "ClientNumber": "..." , "MissionNumber": getObject['Data']['MissionNumber'] , }; ``` * processDataFutureMission: ```typescript=437 let newData = { "ClientName": "..." , "ClientAddress": "..." , "MissionTime": getData['RepairCallTime'] , "MissionTimeOnlyHour": MissionTimeOnlyHour , "ClientPhone": "..." , "ClientContactPerson": "..." , "DeviceID": "...", "DeviceType": getObject['Data'][j]['machineDetails']['Type'] , "DeviceNumber": "..." , "DeviceBuildingLocation": "...", "DevicePlacementPosition": "...", "ErrorCode": getData['ErrorType'] , "ProblemDescription": getData['Description'] , "NotificationTime": getData['NotifyTime'] , "Repairman": getData['Maintainer'] , "ClientNumber": "..." , "MissionNumber": getData['MissionNumber'] , }; ``` ### 2. Detail Page #### 2.1 detail.page.ts 1. Add a NavController library. ```typescript=2 import {ModalController, NavController, NavParams} from '@ionic/angular'; ``` ```typescript=19 public navCtrl: NavController ``` 2. Create a method to close the modal page & go to report-repair page. ```typescript=45 completeRepair() { //this.inputCamera = true; this.dismiss(); this.navCtrl.navigateForward(['report-repair']); } ``` ### 3. Static Variable class #### 3.1 static-variables.ts 1. Add new keys into the static-variable ```typescript=3 public static KEY__LOGIN_EMAIL = "login_email"; public static KEY__LOGIN_EMPLOYEE_ID = "login_employee_id"; public static KEY__EMPLOYEE_NAME = "employee_name"; public static KEY__DEVICE_ID = "device_id"; public static KEY__DEVICE_TYPE = "device_type"; public static KEY__DEVICE_BUILDING_LOC = "device_building_location"; public static KEY__DEVICE_PLACEMENT_LOC = "device_placement_location"; public static KEY__PROBLEM_DESCRIPTION = "problem_description"; ``` --- ## Result