1/// <reference path="references.d.ts" /> 2/// <reference path="application.ts" /> 3var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 return new (P || (P = Promise))(function (resolve, reject) { 6 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 }); 11}; 12var __generator = (this && this.__generator) || function (thisArg, body) { 13 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 14 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 15 function verb(n) { return function (v) { return step([n, v]); }; } 16 function step(op) { 17 if (f) throw new TypeError("Generator is already executing."); 18 while (g && (g = 0, op[0] && (_ = 0)), _) try { 19 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 20 if (y = 0, t) op = [op[0] & 2, t.value]; 21 switch (op[0]) { 22 case 0: case 1: t = op; break; 23 case 4: _.label++; return { value: op[1], done: false }; 24 case 5: _.label++; y = op[1]; op = [0]; continue; 25 case 7: op = _.ops.pop(); _.trys.pop(); continue; 26 default: 27 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 28 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 29 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 30 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 31 if (t[2]) _.ops.pop(); 32 _.trys.pop(); continue; 33 } 34 op = body.call(thisArg, _); 35 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 36 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 37 } 38}; 39import { Distiller } from './application.js'; 40var PersonalizedValuesModal = /** @class */ (function () { 41 function PersonalizedValuesModal(params) { 42 var _this = this; 43 this.isLoading = ko.observable(false); 44 this.processing = ko.observable(null); 45 this.filterParams = ko.observable(null); 46 this.personalizedValues = ko.observableArray([]); 47 this.page = ko.observable('import'); 48 this.purpose = ko.observable(null); 49 this.arrayOfRows = ko.observableArray([]); 50 this.uniqueIdentifierCount = ko.observable(0); 51 this.appliedCount = ko.observable(0); 52 this.pendingCount = ko.observable(0); 53 this.normalizeRowKeys = function (row) { 54 var normalized = {}; 55 Object.keys(row || {}).forEach(function (key) { 56 var lower = key.toLowerCase().replace(/[\s_]/g, ''); 57 if (lower === 'userid') { 58 normalized.userId = row[key]; 59 } 60 else if (lower === 'quorumid') { 61 normalized.quorumId = row[key]; 62 } 63 else if (lower === 'tempid') { 64 normalized.tempId = row[key]; 65 } 66 else if (lower === 'variable') { 67 normalized.variable = row[key]; 68 } 69 else if (lower === 'value') { 70 normalized.value = row[key]; 71 } 72 }); 73 return normalized; 74 }; 75 this.parsePersonalizedValues = function (data) { return __awaiter(_this, void 0, void 0, function () { 76 var arrayOfRows, uniqueIds, dataArrayOfObjects, i, normalized, variable, hasUserId, hasQuorumId, hasTempId, row, identityKey; 77 var _a; 78 return __generator(this, function (_b) { 79 switch (_b.label) { 80 case 0: 81 this.processing('csv'); 82 this.arrayOfRows([]); 83 this.uniqueIdentifierCount(0); 84 arrayOfRows = []; 85 uniqueIds = {}; 86 return [4 /*yield*/, Distiller.convertToArray(data)]; 87 case 1: 88 dataArrayOfObjects = _b.sent(); 89 for (i = 0; i < dataArrayOfObjects.length; i++) { 90 normalized = this.normalizeRowKeys(dataArrayOfObjects[i]); 91 variable = normalized.variable != null ? String(normalized.variable).trim() : ''; 92 if (!variable) { 93 continue; 94 } 95 hasUserId = normalized.userId !== undefined && normalized.userId !== null && String(normalized.userId).trim() !== ''; 96 hasQuorumId = normalized.quorumId !== undefined && normalized.quorumId !== null && String(normalized.quorumId).trim() !== ''; 97 hasTempId = normalized.tempId !== undefined && normalized.tempId !== null && String(normalized.tempId).trim() !== ''; 98 if (!hasUserId && !hasQuorumId && !hasTempId) { 99 continue; 100 } 101 row = { 102 userId: hasUserId ? String(normalized.userId).trim() : null, 103 quorumId: hasQuorumId ? String(normalized.quorumId).trim() : null, 104 tempId: hasTempId ? String(normalized.tempId).trim() : null, 105 variable: variable,
106 value: normalized.value != null ? String(normalized.value) : '' 107 }; 108 identityKey = row.userId || row.quorumId || row.tempId; 109 uniqueIds[identityKey] = true; 110 arrayOfRows.push(row); 111 } 112 if (arrayOfRows.length === 0) { 113 alert("Oops! Your CSV needs a variable column and at least one of userId, quorumId, or tempId populated on each row."); 114 this.processing(null); 115 return [2 /*return*/]; 116 } 117 (_a = this.arrayOfRows).push.apply(_a, arrayOfRows); 118 this.uniqueIdentifierCount(Object.keys(uniqueIds).length); 119 this.processing(null); 120 this.xl(false); 121 this.page('confirm'); 122 return [2 /*return*/]; 123 } 124 }); 125 }); }; 126 this.uploadPersonalizedValues = function () { 127 _this.processing('upload'); 128 var self = _this; 129 var stringifiedRows = JSON.stringify(_this.arrayOfRows()); 130 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/uploadPersonalizedValues/" + Distiller.currentUser().userId + "/" + Distiller.studyInView().communityId(), stringifiedRows, function (response) { 131 response = JSON.parse(response); 132 if (!response.err) { 133 self.appliedCount(response.appliedCount || 0); 134 self.pendingCount(response.pendingCount || 0); 135 self.page('success'); 136 self.refreshFunction(true); 137 } 138 else { 139 if (response.err === 'no access') { 140 alert("Oops! Your account doesn't have permission to upload personalized values. Contact [email protected] if you think you're receiving this message in error."); 141 } 142 else if (response.err === 'bad values') { 143 alert(response.message); 144 } 145 else { 146 self.page('error'); 147 } 148 } 149 self.processing(null); 150 }); 151 }; 152 this.downloadUserData = function () { 153 Distiller.httpGetAsync(Distiller.apiEndpoint + "/api/getUserData/" + Distiller.currentUser().userId + "/" + Distiller.studyInView().communityId(), function (response) { 154 response = JSON.parse(response); 155 if (!response.err) { 156 var userData = response.data; 157 var csvContent = 'userId,quorumId,userName' + '\n'; 158 for (var a = 0; a < userData.length; a++) { 159 csvContent += userData[a].userId; 160 csvContent += ',' + userData[a].quorumId; 161 csvContent += ',' + userData[a].userName; 162 csvContent += '\n'; 163 } 164 var fileName = Distiller.studyInView().name() + " userIds"; 165 Distiller.downloadCSV(csvContent, fileName, 'text/csv;encoding:utf-8'); 166 } 167 }); 168 }; 169 this.removePersonalizedValues = function () { 170 var self = _this; 171 _this.processing('remove'); 172 var payload = { 173 recordsToRemove: _this.recordsToRemove(), 174 filters: _this.filterParams() 175 }; 176 Distiller.httpSendAsync(Distiller.apiEndpoint + "/api/removePersonalizedValues/" + Distiller.currentUser().userId + "/" + Distiller.studyInView().communityId(), JSON.stringify(payload), function (response) { 177 return __awaiter(this, void 0, void 0, function () { 178 return __generator(this, function (_a) { 179 response = JSON.parse(response); 180 if (!response.err) { 181 self.refreshFunction(true); 182 self.page('success'); 183 } 184 else { 185 if (response.err === 'no access') { 186 alert("Oops! Looks like you don't have permission to remove personalized values."); 187 } 188 else { 189 alert("Oops! Something went wrong. Please contact [email protected]."); 190 } 191 } 192 self.processing(null); 193 return [2 /*return*/]; 194 }); 195 }); 196 }); 197 }; 198 this.xl = ko.observable(true); 199 this.totalRecordCount = ko.observable(0); 200 this.recordsToRemove = ko.observableArray([]); 201 this.selectedRows = ko.observableArray([]); 202 if (params.purpose) { 203 this.purpose(params.purpose); 204 } 205 if (params.personalizedValues) { 206 this.personalizedValues = params.personalizedValues; 207 } 208 if (params.refreshFunction) { 209 this.refreshFunction = params.refreshFunction; 210 } 211 if (params.filterParams) { 212 this.filterParams(params.filterParams); 213 } 214 if (params.totalRecordCount || params.totalRecordCount === 0) { 215 this.totalRecordCount(params.totalRecordCount); 216 } 217 if (params.selectedRows) { 218 this.selectedRows = params.selectedRows; 219 this.recordsToRemove(this.selectedRows().map(function (a) { return ({ 220 ID: a.ID, 221 status: a.status, 222 userId: a.userId, 223 variable: a.variable, 224 pendingId: a.pendingId 225 }); })); 226 } 227 if (this.purpose() === 'remove') { 228 this.xl(false); 229 this.page('confirm'); 230 } 231 } 232 return PersonalizedValuesModal;
233}()); 234export default PersonalizedValuesModal;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.