{"version":3,"sources":["webpack:///./scripts/components/myIncidentsTable.js","webpack:///./scripts/helpers/ajaxTable.js"],"names":["component","momentModule","window","moment","$myIncidentsTableElement","$","$myIncidentsProfileSummary","userStateManager","getUserProfileData","data","apiProblemOccured","displayErrorMessage","parent","isNullUndefinedEmpty","Incidents","fullListing","incidentsData","map","item","DateOccurred","format","BguName","Type","Location","AjaxTable","slice","length","css","display","listHtml","max","content","summary","truncateToWord","html","$el","headers","this","$thead","find","$tbody","render","arrRow","value","join","headerRow","rows","getRow","error"],"mappings":"qTAMO,IAAMA,EAAS,e,EAAA,G,EAAA,yBAAG,uHACM,wDADN,OACfC,EADe,OAErBC,OAAOC,OAASF,EAAY,QAEtBG,EAA2BC,EAAE,uBAC7BC,EAA6BD,EAAE,iCAErCE,IAAiBC,oBAAmB,SAAUC,GAC1C,GAAIA,GAAQA,EAAKC,kBAGb,OAFAC,YAAoBP,EAAyBQ,eAC7CD,YAAoBL,GAA4B,GAAM,GAI1D,IAAKO,YAAqBJ,EAAKK,WAAY,CACvC,IAAMC,EAAcX,EAAyBK,KAAK,QAI9CO,EAAgBP,EAAKK,UAAUG,KAAI,SAACC,GAGpC,MAAO,CAFgBL,YAAqBK,EAAKC,cAAiE,IAAjDhB,OAAOe,EAAKC,cAAcC,OAAO,cAE3EF,EAAKG,QAASH,EAAKI,KAAMJ,EAAKK,aAiBzD,GAdIR,EACA,IAAIS,IAAUpB,EAA0BY,IAExC,IAAIQ,IAAUpB,EAA0BY,EAAcS,MAAM,EAZpD,IAeJT,EAAcU,OAfV,GAgBJrB,EAAE,+CAA+CsB,IAAI,CACjDC,QAAS,WAMjBtB,EAA2BoB,OAAS,EAAG,CACvC,IAAMG,EAAWpB,EAAKK,UAAUW,MAAM,EAAGK,GAASb,KAAI,SAACC,GAAD,OAS1Ba,EATuEb,EAUzGc,EAAUC,YAAeF,EAAQT,KAAM,IAC7C,yFAE4BnB,OAAO4B,EAAQZ,cAAcC,OAAO,cAFhE,uDAG+BY,EAH/B,0BAFJ,IAA4CD,EAClCC,KATM1B,EAA2B4B,KAAKL,QAEhCvB,EAA2B4B,KAAK,8DA3CvB,0C,+KAAH,sD,4VCNDV,E,WAOpB,WAAYW,EAAK1B,GAAoB,IAAd2B,EAAc,uDAAJ,GAAI,UACpCC,KAAKF,IAAMA,EACXE,KAAK5B,KAAOA,EACZ4B,KAAKD,QAAUA,EACfC,KAAKC,OAASD,KAAKF,IAAII,KAAK,SAC5BF,KAAKG,OAASH,KAAKF,IAAII,KAAK,SAC5BF,KAAKI,S,sDAGCC,GACN,sCAEIA,EAAOzB,KAAI,SAAA0B,GACZ,OAAOA,SAAkDA,EAAMjB,OAAS,EAAjE,cAA4EiB,EAA5E,yBACLC,KAAK,IAJV,yB,+BASQ,WACR,IACC,GAAIP,KAAKD,QAAQV,OAAS,EAAG,CAC5B,IAAImB,EAAYR,KAAKD,QAAQnB,KAAI,SAAAC,GAAI,oBAAWA,EAAX,YAAwB0B,KAAK,IAClEP,KAAKC,OAAOJ,KAAKW,GAElB,IAAIC,EAAOT,KAAK5B,KAAKQ,KAAI,SAAAC,GAAI,OAAI,EAAK6B,OAAO7B,MAAO0B,KAAK,IACzDP,KAAKG,OAAON,KAAKY,GAChB,MAAOE,U","file":"8.653b2d13810d7f489e69.js","sourcesContent":["import { isNullUndefinedEmpty, truncateToWord } from '../helpers/helpers';\n\nimport AjaxTable from '../helpers/ajaxTable';\nimport { displayErrorMessage } from '../helpers/displayError';\nimport userStateManager from '../helpers/stateManager';\n\nexport const component = async () => {\n const momentModule = await import('moment-mini');\n window.moment = momentModule.default;\n\n const $myIncidentsTableElement = $('#my-incidents-table');\n const $myIncidentsProfileSummary = $('#my-incidents-profile-summary');\n\n userStateManager.getUserProfileData(function (data) {\n if (data && data.apiProblemOccured) {\n displayErrorMessage($myIncidentsTableElement.parent());\n displayErrorMessage($myIncidentsProfileSummary, true, false);\n return;\n }\n\n if (!isNullUndefinedEmpty(data.Incidents)) {\n const fullListing = $myIncidentsTableElement.data('full');\n const max = 5;\n\n //Format data ready to map to table\n var incidentsData = data.Incidents.map((item) => {\n const dateFormatted = !isNullUndefinedEmpty(item.DateOccurred) ? moment(item.DateOccurred).format('DD/MM/YYYY') : '-';\n\n return [dateFormatted, item.BguName, item.Type, item.Location];\n });\n\n if (fullListing) {\n new AjaxTable($myIncidentsTableElement, incidentsData);\n } else {\n new AjaxTable($myIncidentsTableElement, incidentsData.slice(0, max));\n\n //show a button if more than max\n if (incidentsData.length > max) {\n $('.button-wrapper.my-incidents-button-wrapper').css({\n display: 'block',\n });\n }\n }\n\n //Setup my profile summary if it exists\n if ($myIncidentsProfileSummary.length > 0) {\n const listHtml = data.Incidents.slice(0, max - 1).map((item) => getProfileSummaryIncidentsListItem(item));\n $myIncidentsProfileSummary.html(listHtml);\n } else {\n $myIncidentsProfileSummary.html('

It looks like you do not yet have any incidents

');\n }\n }\n });\n};\n\nfunction getProfileSummaryIncidentsListItem(content) {\n const summary = truncateToWord(content.Type, 50);\n return `\n\t\t
\n\t\t\t
${moment(content.DateOccurred).format('DD/MM/YYYY')}
\n\t\t\t
${summary}
\n\t\t
\n\t`;\n}\n","export default class AjaxTable {\n /**\n * Helper class to render a table body (optional column headers) after an AJAX call.\n * @param {Object} $el jQuery element\n * @param {Array.} data Array of strings within an array of rows. Keypair data should be mapped to an array of strings first!\n\t * @param {string[]} headers (Optional) specify the headers for each column. Use if headers are dynamic and not set via view.\n */\n\tconstructor($el, data, headers = []) {\n\t\tthis.$el = $el;\n\t\tthis.data = data;\n\t\tthis.headers = headers;\n\t\tthis.$thead = this.$el.find('thead');\n\t\tthis.$tbody = this.$el.find('tbody');\n\t\tthis.render();\n\t}\n\n\tgetRow(arrRow){\n\t\treturn `\n\t\t\t\n\t\t\t\t${arrRow.map(value => {\n\t\t\t\t\treturn value !== null && typeof value !== 'undefined' && value.length > 0 ? `${value}` : `-`\n\t\t\t\t}).join('')}\n\t\t\t\n\t\t`\n }\n\n\trender() {\n\t\ttry {\n\t\t\tif (this.headers.length > 0) {\n\t\t\t\tvar headerRow = this.headers.map(item => `${item}`).join('');\n\t\t\t\tthis.$thead.html(headerRow);\n\t\t\t}\n\t\t\tvar rows = this.data.map(item => this.getRow(item)).join('');\n\t\t\tthis.$tbody.html(rows);\n\t\t} catch (error) {\n\t\t\tconsole.error('There was an issue generating an Ajax Table', error);\n\t\t}\n\t}\n}\n\n"],"sourceRoot":""}