forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHealthDataPreview.js
More file actions
1 lines (1 loc) · 1.75 KB
/
Copy pathHealthDataPreview.js
File metadata and controls
1 lines (1 loc) · 1.75 KB
1
define(function(require,exports,module){var _=brackets.getModule("thirdparty/lodash"),Mustache=brackets.getModule("thirdparty/mustache/mustache"),PreferencesManager=brackets.getModule("preferences/PreferencesManager"),Strings=brackets.getModule("strings"),Dialogs=brackets.getModule("widgets/Dialogs"),ExtensionUtils=brackets.getModule("utils/ExtensionUtils"),Metrics=brackets.getModule("utils/Metrics"),HealthDataPreviewDialog=require("text!htmlContent/healthdata-preview-dialog.html"),prefs=PreferencesManager.getExtensionPrefs("healthData");function _buildPreviewData(){let content,auditData=Metrics.getLoggedDataForAudit(),sortedData=new Map([...auditData.entries()].sort()),displayData=[];for(const[key,value]of sortedData.entries()){let valueString="";value.count>1&&(valueString=`(${value.count})`),value.eventType===Metrics.AUDIT_TYPE_COUNT?displayData.push(`${key} total: ${value.sum} ${valueString}`):value.eventType===Metrics.AUDIT_TYPE_VALUE&&0!==value.count&&displayData.push(`${key} avg: ${value.sum/value.count} ${valueString}`)}return content=JSON.stringify(displayData,null,2),content=(content=(content=_.escape(content)).replace(/ /g," ")).replace(/(?:\r\n|\r|\n)/g,"<br />")}function previewHealthData(){let hdPref=prefs.get("healthDataTracking"),template=Mustache.render(HealthDataPreviewDialog,{Strings:Strings,content:_buildPreviewData(),hdPref:hdPref}),$template=$(template);Dialogs.addLinkTooltips($template),Dialogs.showModalDialogUsingTemplate($template).done(function(id){if("save"===id){var newHDPref=$template.find("[data-target]:checkbox").is(":checked");hdPref!==newHDPref&&prefs.set("healthDataTracking",newHDPref)}else"clear"===id&&Metrics.clearAuditData()})}ExtensionUtils.loadStyleSheet(module,"styles.css"),exports.previewHealthData=previewHealthData});