Best JavaScript code snippet using argos
equipment.installation.js
Source:equipment.installation.js
1/**2 * Created by kings on 2018-12-20.3 */4var equipmentInstallation = {};5equipmentInstallation.config = {6 name: "设å¤å®è£
",7 frm: "equipmentInstallationFrm",8 table: "equipmentInstallationTableList",9 box: "equipmentInstallationBox",10 fileId: "equipmentInstallationFileId",11 copy: "equipmentInstallationInputGroup",12 excelUpload: "equipmentInstallationUpload",13 declareBuildingConstructionPermit: {14 box: "declareBuildingConstructionPermitBoxE",15 frm: "declareBuildingConstructionPermitFrmE",16 fileId: "declareBuildingConstructionPermitFileIdE",17 name: "建çå·¥ç¨æ½å·¥è®¸å¯è¯"18 },19 declarePreSalePermit: {20 box: "declarePreSalePermitBoxE",21 frm: "declarePreSalePermitFrmE",22 fileId: "declarePreSalePermitFileIdE",23 name: "ååæ¿é¢å®è®¸å¯è¯"24 },25 declareLandUsePermit: {26 box: "declareLandUsePermitBoxE",27 frm: "declareLandUsePermitFrmE",28 fileId: "declareLandUsePermitFileIdE",29 name: "建设ç¨å°è§å许å¯è¯"30 },31 declareBuildingPermit: {32 box: "declareBuildingPermitBoxE",33 frm: "declareBuildingPermitFrmE",34 fileId: "declareBuildingPermitFileIdE",35 name: "建设工ç¨è§å许å¯è¯"36 },37 declareRealtyLandCert: {38 box: "declareRealtyLandCertBoxE",39 frm: "declareRealtyLandCertFrmE",40 fileId: "declareRealtyLandCertFileIdE",41 name: "åå°è¯"42 },43 declareRealtyRealEstateCert: {44 box: "declareRealtyRealEstateCertBoxE",45 frm: "declareRealtyRealEstateCertFrmE",46 fileId: "declareRealtyRealEstateCertFileIdE",47 name: "ä¸å¨äº§"48 },49 declareEconomicIndicators: {50 box: "declareEconomicIndicatorsBoxE",51 frm: "declareEconomicIndicatorsFrmE",52 fileId: "declareEconomicIndicatorsFileIdE",53 name: "ç»æµææ "54 }55};56equipmentInstallation.isNotBlank = function (item) {57 if (item) {58 return true;59 }60 return false;61};62equipmentInstallation.objectWriteSelectData = function (frm, data, name) {63 if (equipmentInstallation.isNotBlank(data)) {64 $("#" + frm + " ." + name).val(data).trigger("change");65 } else {66 $("#" + frm + " ." + name).val(null).trigger("change");67 }68};69equipmentInstallation.showFile = function (target, tableName, id) {70 FileUtils.getFileShows({71 target: target,72 formData: {73 fieldsName: target,74 tableName: tableName,75 tableId: id76 },77 deleteFlag: true78 });79};80equipmentInstallation.fileUpload = function (target, tableName, id) {81 FileUtils.uploadFiles({82 target: target,83 disabledTarget: "btn_submit",84 onUpload: function (file) {85 var formData = {86 fieldsName: target,87 tableName: tableName,88 tableId: id89 };90 return formData;91 }, onUploadComplete: function (result, file) {92 equipmentInstallation.showFile(target, tableName, id);93 },94 deleteFlag: true95 });96};97equipmentInstallation.deleteByType = function (data,callback) {98 $.ajax({99 type: "post",100 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/deleteByType",101 data: data,102 success: function (result) {103 if (result.ret) {104 callback(result);105 } else {106 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);107 }108 },109 error: function (result) {110 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);111 }112 });113};114/**115 * 设å¤å®è£
åå§å并èµå¼116 * @param item117 */118equipmentInstallation.init = function (item) {119 $("#" + equipmentInstallation.config.frm).clearAll();120 $("#" + equipmentInstallation.config.frm).initForm(item);121 //ä½¿æ ¡éªçæ122 $("#" + equipmentInstallation.config.frm).validate();123 AssessCommon.initAreaInfo({124 provinceTarget: $("#" + equipmentInstallation.config.frm).find("select[name='province']"),125 cityTarget: $("#" + equipmentInstallation.config.frm).find("select[name='city']"),126 districtTarget: $("#" + equipmentInstallation.config.frm).find("select[name='district']"),127 provinceValue: item.province,128 cityValue: item.city,129 districtValue: item.district130 });131 equipmentInstallation.showFile(equipmentInstallation.config.fileId, AssessDBKey.DeclareBuildEquipmentInstall, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");132 equipmentInstallation.fileUpload(equipmentInstallation.config.fileId, AssessDBKey.DeclareBuildEquipmentInstall, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");133};134/**135 * @author: zch136 * æè¿°:å¨å»ºå·¥ç¨ï¼è®¾å¤å®è£
ï¼æ¾ç¤º137 * @date:2018-09-27138 **/139equipmentInstallation.showAddModel = function () {140 $('#' + equipmentInstallation.config.box).find("#" + commonDeclareApplyModel.config.equipmentInstallation.handleId).remove();141 $('#' + equipmentInstallation.config.box).find(".panel-body").append(commonDeclareApplyModel.equipmentInstallation.getHtml());142 //ç±äºæ¯å¡«å
çhmtlæ以éè¦æå¨åå§åselect2143 DatepickerUtils.parse();144 $('#' + equipmentInstallation.config.box).find(".select2").each(function () {145 $(this).select2();146 });147 //ä½¿æ ¡éªçæ148 $("#" + equipmentInstallation.config.frm).validate();149 $('#' + equipmentInstallation.config.box).modal("show");150 mapPosition.getCurrentCityByArea(function (area) {151 equipmentInstallation.init(area);152 });153};154/**155 * @author: zch156 * æè¿°:å¨å»ºå·¥ç¨ï¼è®¾å¤å®è£
ï¼æ´æ°157 * @date:2018-09-27158 **/159equipmentInstallation.saveAndUpdateData = function () {160 if (!$("#" + equipmentInstallation.config.frm).valid()) {161 return false;162 }163 var data = formParams(equipmentInstallation.config.frm);164 data.planDetailsId = declareCommon.getPlanDetailsId();165 data.declareType = declareFunObj.getDeclareType("设å¤å®è£
");166 $.ajax({167 type: "POST",168 url: getContextPath() + "/declareBuildEquipmentInstall/saveAndUpdateDeclareBuildEquipmentInstall",169 data: data,170 success: function (result) {171 if (result.ret) {172 equipmentInstallation.loadList();173 notifySuccess('æå','æå!');174 $('#' + equipmentInstallation.config.box).modal("hide");175 } else {176 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);177 }178 },179 error: function (result) {180 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);181 }182 });183};184equipmentInstallation.getData = function (id, callback) {185 $.ajax({186 url: getContextPath() + "/declareBuildEquipmentInstall/getDeclareBuildEquipmentInstallById",187 type: "get",188 dataType: "json",189 data: {id: id},190 success: function (result) {191 if (result.ret) {192 if (result.data) {193 callback(result.data);194 }195 }196 },197 error: function (result) {198 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);199 }200 });201};202/**203 * @author: zch204 * æè¿°:å¨å»ºå·¥ç¨ï¼è®¾å¤å®è£
ï¼ç¼è¾205 * @date:2018-09-27206 **/207equipmentInstallation.editData = function () {208 var rows = $("#" + equipmentInstallation.config.table).bootstrapTable('getSelections');209 if (!rows || rows.length <= 0) {210 notifyInfo('æ示',"请éæ©è¦ç¼è¾çæ°æ®");211 } else if (rows.length == 1) {212 equipmentInstallation.showAddModel();213 equipmentInstallation.getData(rows[0].id, function (data) {214 equipmentInstallation.init(data);215 });216 $('#' + equipmentInstallation.config.box).modal("show");217 } else {218 notifyInfo('æ示',"åªè½éæ©ä¸è¡æ°æ®è¿è¡ç¼è¾");219 }220};221/**222 * @author: zch223 * æè¿°:å¨å»ºå·¥ç¨ï¼è®¾å¤å®è£
ï¼å é¤224 * @date:2018-09-27225 **/226equipmentInstallation.deleteData = function () {227 var rows = $("#" + equipmentInstallation.config.table).bootstrapTable('getSelections');228 if (!rows || rows.length <= 0) {229 notifyInfo('æ示',"请éæ©è¦å é¤çæ°æ®");230 } else {231 AlertConfirm("确认è¦å é¤ä¹", "å é¤åæ°æ®å°ä¸å¯æ¢å¤", function () {232 var idArray = [];233 $.each(rows, function (i, item) {234 idArray.push(item.id);235 });236 $.ajax({237 type: "post",238 url: getContextPath() + "/declareBuildEquipmentInstall/deleteDeclareBuildEquipmentInstallById",239 data: {ids: idArray.join()},240 success: function (result) {241 if (result.ret) {242 equipmentInstallation.loadList();243 } else {244 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);245 }246 },247 error: function (result) {248 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);249 }250 });251 })252 }253};254equipmentInstallation.handleFather = function (item) {255 $.ajax({256 type: "POST",257 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/saveAndUpdateDeclareBuildEngineeringAndEquipmentCenter",258 data: item,259 success: function (result) {260 if (result.ret) {261 equipmentInstallation.loadList();262 } else {263 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);264 }265 },266 error: function (result) {267 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);268 }269 });270};271/**272 * @author: zch273 * æè¿°:建设工ç¨è§å许å¯è¯ view274 * @date:2018-09-28275 **/276equipmentInstallation.declareBuildingPermitView = function (id) {277 $('#' + equipmentInstallation.config.declareBuildingPermit.box).find("#" + commonDeclareApplyModel.config.buildingPermit.handleId).remove();278 $('#' + equipmentInstallation.config.declareBuildingPermit.box).find(".panel-body").append(commonDeclareApplyModel.buildingPermit.getHtml());279 DatepickerUtils.parse();280 $('#' + equipmentInstallation.config.declareBuildingPermit.box).modal("show");281 $("#" + equipmentInstallation.config.declareBuildingPermit.frm).clearAll();282 $.ajax({283 type: "get",284 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",285 data: {id: id},286 success: function (result) {287 if (result.ret) {288 var buildingPermitId = result.data.buildingPermitId;289 if (equipmentInstallation.isNotBlank(buildingPermitId)) {290 $.ajax({291 url: getContextPath() + "/declareBuildingPermit/getDeclareBuildingPermitById",292 type: "get",293 dataType: "json",294 data: {id: buildingPermitId},295 success: function (result) {296 if (result.ret) {297 var data = result.data;298 if (equipmentInstallation.isNotBlank(data)) {299 data.pid = id;300 $("#" + equipmentInstallation.config.declareBuildingPermit.frm).initForm(data);301 $("#" + equipmentInstallation.config.declareBuildingPermit.frm + " input[name='date']").val(formatDate(data.date));302 equipmentInstallation.showFile(equipmentInstallation.config.declareBuildingPermit.fileId, AssessDBKey.DeclareBuildingPermit, data.id);303 equipmentInstallation.fileUpload(equipmentInstallation.config.declareBuildingPermit.fileId, AssessDBKey.DeclareBuildingPermit, data.id);304 }305 }306 },307 error: function (result) {308 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);309 }310 });311 } else {312 $("#" + equipmentInstallation.config.declareBuildingPermit.frm).initForm({pid: id});313 equipmentInstallation.showFile(equipmentInstallation.config.declareBuildingPermit.fileId, AssessDBKey.DeclareBuildingPermit, 0);314 equipmentInstallation.fileUpload(equipmentInstallation.config.declareBuildingPermit.fileId, AssessDBKey.DeclareBuildingPermit, 0);315 }316 } else {317 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);318 }319 },320 error: function (result) {321 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);322 }323 });324};325/**326 * @author: zch327 * æè¿°:建设工ç¨è§å许å¯è¯ æ´æ°328 * @date:2018-09-28329 **/330equipmentInstallation.declareBuildingPermitSaveAndUpdate = function () {331 if (!$("#" + equipmentInstallation.config.declareBuildingPermit.frm).valid()) {332 return false;333 }334 var data = formParams(equipmentInstallation.config.declareBuildingPermit.frm);335 $.ajax({336 type: "POST",337 url: getContextPath() + "/declareBuildingPermit/saveAndUpdateDeclareBuildingPermit",338 data: data,339 success: function (result) {340 if (result.ret) {341 $('#' + equipmentInstallation.config.declareBuildingPermit.box).modal("hide");342 var item = result.data;343 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)344 var fData = {};345 fData.buildingPermitId = item;346 fData.id = data.pid;347 equipmentInstallation.handleFather(fData);348 notifySuccess('æå','æå!');349 }350 } else {351 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);352 }353 },354 error: function (result) {355 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);356 }357 });358};359equipmentInstallation.declareBuildingPermitRemove = function () {360 var data = formParams(equipmentInstallation.config.declareBuildingPermit.frm);361 if (data.id) {362 var item = {dataId: data.id, centerId: data.pid, type: "DeclareBuildingPermit"};363 equipmentInstallation.deleteByType(item, function () {364 $('#' + equipmentInstallation.config.declareBuildingPermit.box).modal("hide");365 equipmentInstallation.loadList();366 notifySuccess('æå','æå!');367 });368 } else {369 notifySuccess('æå','æ å é¤æ°æ®!');370 }371};372/**373 * @author: zch374 * æè¿°:建设ç¨å°è§å许å¯è¯ view375 * @date:2018-09-28376 **/377equipmentInstallation.declareLandUsePermitView = function (id) {378 $('#' + equipmentInstallation.config.declareLandUsePermit.box).find("#" + commonDeclareApplyModel.config.landUsePermit.handleId).remove();379 $('#' + equipmentInstallation.config.declareLandUsePermit.box).find(".panel-body").append(commonDeclareApplyModel.landUsePermit.getHtml());380 DatepickerUtils.parse();381 $('#' + equipmentInstallation.config.declareLandUsePermit.box).modal("show");382 $("#" + equipmentInstallation.config.declareLandUsePermit.frm).clearAll();383 $.ajax({384 type: "get",385 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",386 data: {id: id},387 success: function (result) {388 if (result.ret) {389 var landUsePermitId = result.data.landUsePermitId;390 if (equipmentInstallation.isNotBlank(landUsePermitId)) {391 $.ajax({392 url: getContextPath() + "/declareLandUsePermit/getDeclareLandUsePermitById",393 type: "get",394 dataType: "json",395 data: {id: landUsePermitId},396 success: function (result) {397 if (result.ret) {398 var data = result.data;399 if (equipmentInstallation.isNotBlank(data)) {400 data.pid = id;401 $("#" + equipmentInstallation.config.declareLandUsePermit.frm).initForm(data);402 $("#" + equipmentInstallation.config.declareLandUsePermit.frm + " input[name='date']").val(formatDate(data.date));403 equipmentInstallation.showFile(equipmentInstallation.config.declareLandUsePermit.fileId, AssessDBKey.DeclareLandUsePermit, data.id);404 equipmentInstallation.fileUpload(equipmentInstallation.config.declareLandUsePermit.fileId, AssessDBKey.DeclareLandUsePermit, data.id);405 }406 }407 },408 error: function (result) {409 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);410 }411 });412 } else {413 $("#" + equipmentInstallation.config.declareLandUsePermit.frm).initForm({pid: id});414 equipmentInstallation.showFile(equipmentInstallation.config.declareLandUsePermit.fileId, AssessDBKey.DeclareLandUsePermit, 0);415 equipmentInstallation.fileUpload(equipmentInstallation.config.declareLandUsePermit.fileId, AssessDBKey.DeclareLandUsePermit, 0);416 }417 } else {418 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);419 }420 },421 error: function (result) {422 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);423 }424 });425};426/**427 * @author: zch428 * æè¿°:建设ç¨å°è§å许å¯è¯ æ´æ°429 * @date:2018-09-28430 **/431equipmentInstallation.declareLandUsePermitSaveAndUpdate = function () {432 if (!$("#" + equipmentInstallation.config.declareLandUsePermit.frm).valid()) {433 return false;434 }435 var data = formParams(equipmentInstallation.config.declareLandUsePermit.frm);436 $.ajax({437 type: "POST",438 url: getContextPath() + "/declareLandUsePermit/saveAndUpdateDeclareLandUsePermit",439 data: data,440 success: function (result) {441 if (result.ret) {442 $('#' + equipmentInstallation.config.declareLandUsePermit.box).modal("hide");443 var item = result.data;444 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)445 var fData = {};446 fData.landUsePermitId = item;447 fData.id = data.pid;448 equipmentInstallation.handleFather(fData);449 notifySuccess('æå','æå!');450 }451 } else {452 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);453 }454 },455 error: function (result) {456 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);457 }458 });459};460equipmentInstallation.declareLandUsePermitRemove = function () {461 var data = formParams(equipmentInstallation.config.declareLandUsePermit.frm);462 if (data.id) {463 var item = {dataId: data.id, centerId: data.pid, type: "DeclareLandUsePermit"};464 equipmentInstallation.deleteByType(item, function () {465 $('#' + equipmentInstallation.config.declareLandUsePermit.box).modal("hide");466 equipmentInstallation.loadList();467 notifySuccess('æå','æå!');468 });469 } else {470 notifySuccess('æå','æ å é¤æ°æ®!');471 }472};473/**474 * @author: zch475 * æè¿°:ååæ¿é¢å®è®¸å¯è¯ view476 * @date:2018-09-28477 **/478equipmentInstallation.declarePreSalePermitView = function (id) {479 $('#' + equipmentInstallation.config.declarePreSalePermit.box).find("#" + commonDeclareApplyModel.config.preSalePermit.handleId).remove();480 $('#' + equipmentInstallation.config.declarePreSalePermit.box).find(".panel-body").append(commonDeclareApplyModel.preSalePermit.getHtml());481 DatepickerUtils.parse();482 $("#" + equipmentInstallation.config.declarePreSalePermit.frm).clearAll();483 $('#' + equipmentInstallation.config.declarePreSalePermit.box).modal("show");484 $.ajax({485 type: "get",486 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",487 data: {id: id},488 success: function (result) {489 if (result.ret) {490 var preSalePermitId = result.data.preSalePermitId;491 if (equipmentInstallation.isNotBlank(preSalePermitId)) {492 $.ajax({493 url: getContextPath() + "/declarePreSalePermit/getDeclarePreSalePermitById",494 type: "get",495 dataType: "json",496 data: {id: preSalePermitId},497 success: function (result) {498 if (result.ret) {499 var data = result.data;500 if (equipmentInstallation.isNotBlank(data)) {501 data.pid = id;502 $("#" + equipmentInstallation.config.declarePreSalePermit.frm).initForm(data);503 $("#" + equipmentInstallation.config.declarePreSalePermit.frm + " input[name='date']").val(formatDate(data.date));504 equipmentInstallation.showFile(equipmentInstallation.config.declarePreSalePermit.fileId, AssessDBKey.DeclarePreSalePermit, data.id);505 equipmentInstallation.fileUpload(equipmentInstallation.config.declarePreSalePermit.fileId, AssessDBKey.DeclarePreSalePermit, data.id);506 }507 }508 },509 error: function (result) {510 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);511 }512 });513 } else {514 $("#" + equipmentInstallation.config.declarePreSalePermit.frm).initForm({pid: id});515 equipmentInstallation.showFile(equipmentInstallation.config.declarePreSalePermit.fileId, AssessDBKey.DeclarePreSalePermit, 0);516 equipmentInstallation.fileUpload(equipmentInstallation.config.declarePreSalePermit.fileId, AssessDBKey.DeclarePreSalePermit, 0);517 }518 } else {519 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);520 }521 },522 error: function (result) {523 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);524 }525 });526};527/**528 * @author: zch529 * æè¿°:ååæ¿é¢å®è®¸å¯è¯ æ´æ°530 * @date:2018-09-28531 **/532equipmentInstallation.declarePreSalePermitSaveAndUpdate = function () {533 if (!$("#" + equipmentInstallation.config.declarePreSalePermit.frm).valid()) {534 return false;535 }536 var data = formParams(equipmentInstallation.config.declarePreSalePermit.frm);537 $.ajax({538 type: "POST",539 url: getContextPath() + "/declarePreSalePermit/saveAndUpdateDeclarePreSalePermit",540 data: data,541 success: function (result) {542 if (result.ret) {543 $('#' + equipmentInstallation.config.declarePreSalePermit.box).modal("hide");544 var item = result.data;545 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)546 var fData = {};547 fData.preSalePermitId = item;548 fData.id = data.pid;549 equipmentInstallation.handleFather(fData);550 notifySuccess('æå','æå!');551 }552 } else {553 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);554 }555 },556 error: function (result) {557 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);558 }559 });560};561equipmentInstallation.declarePreSalePermitRemove = function () {562 var data = formParams(equipmentInstallation.config.declarePreSalePermit.frm);563 if (data.id) {564 var item = {dataId: data.id, centerId: data.pid, type: "DeclarePreSalePermit"};565 equipmentInstallation.deleteByType(item, function () {566 $('#' + equipmentInstallation.config.declarePreSalePermit.box).modal("hide");567 equipmentInstallation.loadList();568 notifySuccess('æå','æå!');569 });570 } else {571 notifySuccess('æå','æ å é¤æ°æ®!');572 }573};574/**575 * @author: zch576 * æè¿°:建çå·¥ç¨æ½å·¥è®¸å¯è¯ view577 * @date:2018-09-28578 **/579equipmentInstallation.declareBuildingConstructionPermitView = function (id) {580 $('#' + equipmentInstallation.config.declareBuildingConstructionPermit.box).find("#" + commonDeclareApplyModel.config.buildingConstructionPermit.handleId).remove();581 $('#' + equipmentInstallation.config.declareBuildingConstructionPermit.box).find(".panel-body").append(commonDeclareApplyModel.buildingConstructionPermit.getHtml());582 DatepickerUtils.parse();583 $("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm).clearAll();584 $('#' + equipmentInstallation.config.declareBuildingConstructionPermit.box).modal("show");585 $.ajax({586 type: "get",587 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",588 data: {id: id},589 success: function (result) {590 if (result.ret) {591 var buildingConstructionPermitId = result.data.buildingConstructionPermitId;592 if (equipmentInstallation.isNotBlank(buildingConstructionPermitId)) {593 $.ajax({594 url: getContextPath() + "/declareBuildingConstructionPermit/getDeclareBuildingConstructionPermitById",595 type: "get",596 dataType: "json",597 data: {id: buildingConstructionPermitId},598 success: function (result) {599 if (result.ret) {600 var data = result.data;601 if (equipmentInstallation.isNotBlank(data)) {602 data.pid = id;603 $("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm).initForm(data);604 $("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm + " input[name='contractPeriod']").val(formatDate(data.contractPeriod));605 $("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm + " input[name='date']").val(formatDate(data.date));606 equipmentInstallation.showFile(equipmentInstallation.config.declareBuildingConstructionPermit.fileId, AssessDBKey.DeclareBuildingConstructionPermit, data.id);607 equipmentInstallation.fileUpload(equipmentInstallation.config.declareBuildingConstructionPermit.fileId, AssessDBKey.DeclareBuildingConstructionPermit, data.id);608 }609 }610 },611 error: function (result) {612 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);613 }614 });615 } else {616 $("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm).initForm({pid: id});617 equipmentInstallation.showFile(equipmentInstallation.config.declareBuildingConstructionPermit.fileId, AssessDBKey.DeclareBuildingConstructionPermit, 0);618 equipmentInstallation.fileUpload(equipmentInstallation.config.declareBuildingConstructionPermit.fileId, AssessDBKey.DeclareBuildingConstructionPermit, 0);619 }620 } else {621 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);622 }623 },624 error: function (result) {625 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);626 }627 });628};629/**630 * @author: zch631 * æè¿°:建çå·¥ç¨æ½å·¥è®¸å¯è¯ æ´æ°632 * @date:2018-09-28633 **/634equipmentInstallation.declareBuildingConstructionPermitSaveAndUpdate = function () {635 if (!$("#" + equipmentInstallation.config.declareBuildingConstructionPermit.frm).valid()) {636 return false;637 }638 var data = formParams(equipmentInstallation.config.declareBuildingConstructionPermit.frm);639 $.ajax({640 type: "POST",641 url: getContextPath() + "/declareBuildingConstructionPermit/saveAndUpdateDeclareBuildingConstructionPermit",642 data: data,643 success: function (result) {644 if (result.ret) {645 $('#' + equipmentInstallation.config.declareBuildingConstructionPermit.box).modal("hide");646 var item = result.data;647 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)648 var fData = {};649 fData.buildingConstructionPermitId = item;650 fData.id = data.pid;651 equipmentInstallation.handleFather(fData);652 notifySuccess('æå','æå!');653 }654 } else {655 console.log(result.errmsg);656 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);657 }658 },659 error: function (result) {660 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);661 }662 });663};664equipmentInstallation.declareBuildingConstructionPermitRemove = function () {665 var data = formParams(equipmentInstallation.config.declareBuildingConstructionPermit.frm);666 if (data.id) {667 var item = {dataId: data.id, centerId: data.pid, type: "DeclareBuildingConstructionPermit"};668 equipmentInstallation.deleteByType(item, function () {669 $('#' + equipmentInstallation.config.declareBuildingConstructionPermit.box).modal("hide");670 equipmentInstallation.loadList();671 notifySuccess('æå','æå!');672 });673 } else {674 notifySuccess('æå','æ å é¤æ°æ®!');675 }676};677/**678 * @author: zch679 * æè¿°:åå°è¯ åå§å并ä¸èµå¼680 * @date:2018-09-28681 **/682equipmentInstallation.declareRealtyLandCertInit = function (item) {683 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).initForm(item);684 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm + " input[name='terminationDate']").val(formatDate(item.terminationDate));685 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm + " input[name='registrationDate']").val(formatDate(item.registrationDate));686 equipmentInstallation.showFile(equipmentInstallation.config.declareRealtyLandCert.fileId, AssessDBKey.DeclareRealtyLandCert, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");687 equipmentInstallation.fileUpload(equipmentInstallation.config.declareRealtyLandCert.fileId, AssessDBKey.DeclareRealtyLandCert, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");688 AssessCommon.initAreaInfo({689 provinceTarget: $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find("select[name='province']"),690 cityTarget: $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find("select[name='city']"),691 districtTarget: $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find("select[name='district']"),692 provinceValue: item.province,693 cityValue: item.city,694 districtValue: item.district695 });696 AssessCommon.loadDataDicByKey(AssessDicKey.projectDeclareLandCertificateType, item.type, function (html, data) {697 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find('select.type').empty().html(html).trigger('change');698 });699 AssessCommon.loadDataDicByKey(AssessDicKey.estate_total_land_use, item.purpose, function (html, data) {700 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find('select.purpose').empty().html(html).trigger('change');701 });702 AssessCommon.loadDataDicByKey(AssessDicKey.projectDeclareUseRightType, item.useRightType, function (html, data) {703 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).find('select.useRightType').empty().html(html).trigger('change');704 });705};706/**707 * @author: zch708 * æè¿°:åå°è¯ è§å¾709 * @date:2018-09-28710 **/711equipmentInstallation.declareRealtyLandCertView = function (id) {712 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).find("#" + commonDeclareApplyModel.config.land.handleId).remove();713 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).find(".panel-body").append(commonDeclareApplyModel.land.getHtml());714 DatepickerUtils.parse();715 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).find(".select2").each(function () {716 $(this).select2();717 });718 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).modal("show");719 $("#" + equipmentInstallation.config.declareRealtyLandCert.frm).clearAll();720 $.ajax({721 type: "get",722 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",723 data: {id: id},724 success: function (result) {725 if (result.ret) {726 var landId = result.data.landId;727 if (equipmentInstallation.isNotBlank(landId)) {728 $.ajax({729 url: getContextPath() + "/declareRealtyLandCert/getDeclareRealtyLandCertById",730 type: "get",731 dataType: "json",732 data: {id: landId},733 success: function (result) {734 if (result.ret) {735 var data = result.data;736 if (equipmentInstallation.isNotBlank(data)) {737 data.pidC = id ;738 equipmentInstallation.declareRealtyLandCertInit(data);739 }740 }741 },742 error: function (result) {743 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);744 }745 });746 } else {747 equipmentInstallation.getData(result.data.buildEquipmentId, function (item) {748 equipmentInstallation.declareRealtyLandCertInit({749 pidC: id, province: item.province,750 city: item.city,751 district: item.district752 });753 });754 }755 } else {756 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);757 }758 },759 error: function (result) {760 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);761 }762 });763};764/**765 * @author: zch766 * æè¿°:åå°è¯ æ´æ°767 * @date:2018-09-28768 **/769equipmentInstallation.declareRealtyLandCertSaveAndUpdate = function () {770 if (!$("#" + equipmentInstallation.config.declareRealtyLandCert.frm).valid()) {771 return false;772 }773 var data = formParams(equipmentInstallation.config.declareRealtyLandCert.frm);774 if (data.id){775 }else {776 data.planDetailsId = declareCommon.getPlanDetailsId();777 data.enable = declareCommon.branchData;778 }779 $.ajax({780 type: "POST",781 url: getContextPath() + "/declareRealtyLandCert/saveAndUpdateDeclareRealtyLandCert",782 data: {formData: JSON.stringify(data)} ,783 success: function (result) {784 if (result.ret) {785 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).modal("hide");786 var item = result.data;787 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)788 var fData = {};789 fData.landId = item;790 fData.id = data.pidC;791 equipmentInstallation.handleFather(fData);792 notifySuccess('æå','æå!');793 }794 } else {795 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);796 }797 },798 error: function (result) {799 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);800 }801 });802};803equipmentInstallation.declareRealtyLandCertRemove = function () {804 var data = formParams(equipmentInstallation.config.declareRealtyLandCert.frm);805 if (data.id) {806 var item = {dataId: data.id, centerId: data.pidC, type: "DeclareRealtyLandCert"};807 equipmentInstallation.deleteByType(item, function () {808 $('#' + equipmentInstallation.config.declareRealtyLandCert.box).modal("hide");809 equipmentInstallation.loadList();810 notifySuccess('æå','æå!');811 });812 } else {813 notifySuccess('æå','æ å é¤æ°æ®!');814 }815};816/**817 * @author: zch818 * æè¿°:ä¸å¨äº§819 * @date:2018-09-28820 **/821equipmentInstallation.declareRealtyRealEstateCertInit = function (item) {822 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).initForm(item);823 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm + " input[name='terminationDate']").val(formatDate(item.terminationDate));824 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm + " input[name='useEndDate']").val(formatDate(item.useEndDate));825 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm + " input[name='useStartDate']").val(formatDate(item.useStartDate));826 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm + " input[name='registrationTime']").val(formatDate(item.registrationTime));827 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm + " input[name='registrationDate']").val(formatDate(item.registrationDate));828 equipmentInstallation.showFile(equipmentInstallation.config.declareRealtyRealEstateCert.fileId, AssessDBKey.DeclareRealtyRealEstateCert, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");829 equipmentInstallation.fileUpload(equipmentInstallation.config.declareRealtyRealEstateCert.fileId, AssessDBKey.DeclareRealtyRealEstateCert, equipmentInstallation.isNotBlank(item.id) ? item.id : "0");830 AssessCommon.initAreaInfo({831 provinceTarget: $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find("select[name='province']"),832 cityTarget: $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find("select[name='city']"),833 districtTarget: $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find("select[name='district']"),834 provinceValue: item.province,835 cityValue: item.city,836 districtValue: item.district837 });838 AssessCommon.loadDataDicByKey(AssessDicKey.projectDeclareLandCertificateType, item.type, function (html, data) {839 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find('select.type').empty().html(html).trigger('change');840 });841 AssessCommon.loadDataDicByKey(AssessDicKey.estate_total_land_use, item.purpose, function (html, data) {842 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find('select.purpose').empty().html(html).trigger('change');843 });844 AssessCommon.loadDataDicByKey(AssessDicKey.projectDeclareUseRightType, item.useRightType, function (html, data) {845 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find('select.useRightType').empty().html(html).trigger('change');846 });847 AssessCommon.loadDataDicByKey(AssessDicKey.projectDeclareCommonSituation, item.publicSituation, function (html, data) {848 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).find('select.publicSituation').empty().html(html).trigger('change');849 });850};851equipmentInstallation.declareRealtyRealEstateCertView = function (id) {852 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).find("#" + commonDeclareApplyModel.config.realEstateCert.handleId).remove();853 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).find(".panel-body").append(commonDeclareApplyModel.realEstateCert.getHtml());854 DatepickerUtils.parse();855 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).find(".select2").each(function () {856 $(this).select2();857 });858 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).modal("show");859 $("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).clearAll();860 $.ajax({861 type: "get",862 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",863 data: {id: id},864 success: function (result) {865 if (result.ret) {866 var realEstateId = result.data.realEstateId;867 if (equipmentInstallation.isNotBlank(realEstateId)) {868 $.ajax({869 url: getContextPath() + "/declareRealtyRealEstateCert/getDeclareRealtyRealEstateCertById",870 type: "get",871 dataType: "json",872 data: {id: realEstateId},873 success: function (result) {874 if (result.ret) {875 if (equipmentInstallation.isNotBlank(result.data)) {876 var item = result.data ;877 item.pidC = id;878 equipmentInstallation.declareRealtyRealEstateCertInit(item);879 }880 }881 },882 error: function (result) {883 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);884 }885 });886 } else {887 equipmentInstallation.getData(result.data.buildEquipmentId, function (item) {888 equipmentInstallation.declareRealtyRealEstateCertInit({889 pidC: id, province: item.province,890 city: item.city,891 district: item.district892 });893 });894 }895 } else {896 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);897 }898 },899 error: function (result) {900 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);901 }902 });903};904equipmentInstallation.declareRealtyRealEstateCertSaveAndUpdate = function () {905 if (!$("#" + equipmentInstallation.config.declareRealtyRealEstateCert.frm).valid()) {906 return false;907 }908 var data = formParams(equipmentInstallation.config.declareRealtyRealEstateCert.frm);909 if (data.id){910 }else {911 data.planDetailsId = declareCommon.getPlanDetailsId();912 data.enable = declareCommon.branchData;913 }914 $.ajax({915 type: "POST",916 url: getContextPath() + "/declareRealtyRealEstateCert/saveAndUpdateDeclareRealtyRealEstateCert",917 data: {formData:JSON.stringify(data)},918 success: function (result) {919 if (result.ret) {920 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).modal("hide");921 var item = result.data;922 if (equipmentInstallation.isNotBlank(item)) {//ææ°å¢çåç±»ç»å®å°ç¶ç±»ä¸åº (ä¾æ®æ¯æ¯æ¬¡æ°å¢é½ä¼æä¿åçidè¿ååæ¥)923 var fData = {};924 fData.realEstateId = item;925 fData.id = data.pidC;926 equipmentInstallation.handleFather(fData);927 notifySuccess('æå','æå!');928 }929 } else {930 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);931 }932 },933 error: function (result) {934 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);935 }936 });937};938equipmentInstallation.declareRealtyRealEstateCertRemove = function () {939 var data = formParams(equipmentInstallation.config.declareRealtyRealEstateCert.frm);940 if (data.id) {941 var item = {dataId: data.id, centerId: data.pidC, type: "DeclareRealtyRealEstateCert"};942 equipmentInstallation.deleteByType(item, function () {943 $('#' + equipmentInstallation.config.declareRealtyRealEstateCert.box).modal("hide");944 equipmentInstallation.loadList();945 notifySuccess('æå','æå!');946 });947 } else {948 notifySuccess('æå','æ å é¤æ°æ®!');949 }950};951/**952 * ç»æµææ 953 */954equipmentInstallation.declareEconomicIndicatorsView = function (pid) {955 $.ajax({956 type: "get",957 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/getDeclareBuildEngineeringAndEquipmentCenterById",958 data: {id: pid},959 success: function (result) {960 if (result.ret) {961 var indicatorId = result.data.indicatorId;962 if (equipmentInstallation.isNotBlank(indicatorId)) {963 $('#' + equipmentInstallation.config.declareEconomicIndicators.frm).find("#" + commonDeclareApplyModel.config.economicIndicators.handleId).remove();964 $('#' + equipmentInstallation.config.declareEconomicIndicators.frm).find(".panel-body").append(commonDeclareApplyModel.economicIndicators.getHtml());965 DatepickerUtils.parse();966 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).clearAll();967 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).find('[name=pid]').val(indicatorId);968 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).find('.dynamic').remove();969 commonDeclareApplyModel.economicIndicators.initForm(indicatorId,function () {970 $('#' + equipmentInstallation.config.declareEconomicIndicators.box).modal("show");971 });972 } else {973 $.ajax({974 type: "POST",975 url: getContextPath() + "/declareBuildEconomicIndicatorsCenter/saveAndUpdateDeclareBuildEconomicIndicatorsCenter",976 data: {planDetailsId: declareCommon.getPlanDetailsId()},977 success: function (result) {978 if (result.ret) {979 var id = result.data;980 var fData = {};981 fData.indicatorId = id;982 fData.id = pid;983 equipmentInstallation.handleFather(fData);984 $('#' + equipmentInstallation.config.declareEconomicIndicators.frm).find("#" + commonDeclareApplyModel.config.economicIndicators.handleId).remove();985 $('#' + equipmentInstallation.config.declareEconomicIndicators.frm).find(".panel-body").append(commonDeclareApplyModel.economicIndicators.getHtml());986 DatepickerUtils.parse();987 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).clearAll();988 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).find('[name=pid]').val(id);989 $("#" + equipmentInstallation.config.declareEconomicIndicators.frm).find('.dynamic').remove();990 commonDeclareApplyModel.economicIndicators.initForm(id,function () {991 $('#' + equipmentInstallation.config.declareEconomicIndicators.box).modal("show");992 });993 } else {994 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);995 }996 },997 error: function (result) {998 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);999 }1000 });1001 }1002 }1003 },1004 error: function (result) {1005 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1006 }1007 });1008};1009equipmentInstallation.declareEconomicIndicatorsRemove = function () {1010 var pid = formParams(equipmentInstallation.config.declareEconomicIndicators.frm).pid;1011 function get(id, callback) {1012 $.ajax({1013 type: "get",1014 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/listDeclareBuildEngineeringAndEquipmentCenter",1015 data: {planDetailsId: declareCommon.getPlanDetailsId(), indicatorId: id},1016 success: function (result) {1017 if (result.ret) {1018 if (result.data) {1019 callback(result.data[0]);1020 }1021 } else {1022 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1023 }1024 },1025 error: function (result) {1026 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1027 }1028 });1029 }1030 $.ajax({1031 type: "POST",1032 url: getContextPath() + "/economicIndicators/getEntityListByPid",1033 data: {pid: pid},1034 success: function (result) {1035 if (result.ret) {1036 if (result.data.length >= 1) {1037 get(pid, function (data) {1038 var item = {dataId: pid, centerId: data.id, type: "DeclareBuildEconomicIndicatorsCenter"};1039 equipmentInstallation.deleteByType(item, function () {1040 $('#' + equipmentInstallation.config.declareEconomicIndicators.box).modal("hide");1041 equipmentInstallation.loadList();1042 notifySuccess('æå','æå!');1043 });1044 });1045 } else {1046 notifySuccess('æå','æ æ°æ®!');1047 }1048 } else {1049 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1050 }1051 },1052 error: function (result) {1053 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1054 }1055 });1056};1057equipmentInstallation.declareEconomicIndicatorsSaveAndUpdate = function () {1058 if (!$('#'+equipmentInstallation.config.declareEconomicIndicators.frm).valid()) {1059 return false;1060 }1061 try {1062 var item = formParams(equipmentInstallation.config.declareEconomicIndicators.frm) ;1063 var formData = commonDeclareApplyModel.economicIndicators.getFormData();1064 var data = {1065 formData: JSON.stringify(formData),1066 pid:item.pid1067 };1068 $.ajax({1069 beforeSend: function () {1070 Loading.progressShow();1071 },1072 url: getContextPath()+"/economicIndicators/saveEconomicIndicatorsList",1073 type: 'post',1074 data: data,1075 dataType: 'json',1076 success: function (result) {1077 Loading.progressHide();1078 if (result.ret) {1079 notifySuccess('æå','ä¿åæå');1080 equipmentInstallation.loadList();1081 } else {1082 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1083 }1084 }1085 });1086 } catch (result) {1087 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1088 }1089 $('#' + equipmentInstallation.config.declareEconomicIndicators.box).modal("hide");1090};1091//å¤å¶åæ°æ®1092equipmentInstallation.copyData = function () {1093 var rows = $("#" + equipmentInstallation.config.table).bootstrapTable('getSelections');1094 if (!rows || rows.length <= 0) {1095 notifyInfo('æ示',"请éæ©è¦copyçæ°æ®");1096 } else if (rows.length == 1) {1097 $.ajax({1098 url: getContextPath() + "/declareBuildEquipmentInstall/getDeclareBuildEquipmentInstallById",1099 type: "get",1100 dataType: "json",1101 data: {id: rows[0].id},1102 success: function (result) {1103 if (result.ret) {1104 if (result.data) {1105 $("#" + equipmentInstallation.config.copy).find("input[name='name']").val(result.data.name);1106 $("#" + equipmentInstallation.config.copy).find("input[name='id']").val(result.data.centerId);1107 $("#" + equipmentInstallation.config.table).bootstrapTable('uncheckAll');1108 }1109 }1110 },1111 error: function (result) {1112 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1113 }1114 });1115 } else {1116 notifyInfo('æ示',"åªè½éæ©ä¸è¡æ°æ®è¿è¡copy");1117 }1118};1119//æå¤å¶çä»è¡¨ç²è´´å°ææçåä¸1120equipmentInstallation.pasteAll = function () {1121 var item = $("#" + equipmentInstallation.config.table).bootstrapTable('getSelections');1122 if (item.length < 1) {1123 notifyInfo('æ示',"è³å°éæ©ä¸è¡");1124 return false;1125 }1126 var copyId = $("#" + equipmentInstallation.config.copy).find("input[name='id']").val();1127 if (copyId) {1128 var ids = "";1129 var select = true;1130 $.each(item, function (i, n) {1131 if (i == item.length - 1) {1132 ids += n.id1133 } else {1134 ids += n.id + ",";1135 }1136 //æ£æµæ¯å¦èªå·±å¤å¶èªå·±,è¿æ ·æ
åµæ¯ä¸è¢«å
许ç1137 if (copyId == n.id) {1138 select = false;1139 }1140 });1141 if (!select) {1142 notifyInfo('æ示',"èªå·±å¤å¶èªå·±,è¿æ ·æ
åµæ¯ä¸è¢«å
许ç");1143 return false;1144 }1145 if (select) {1146 $.ajax({1147 type: "post",1148 url: getContextPath() + "/declareBuildEngineeringAndEquipmentCenter/copyDeclareBuildEngineeringAndEquipmentCenter",1149 data: {ids: ids, copyId: copyId, type: "DeclareBuildEquipmentInstall"},1150 success: function (result) {1151 if (result.ret) {1152 notifySuccess('æå','æå');1153 equipmentInstallation.loadList();1154 $("#" + equipmentInstallation.config.copy).find("input").each(function () {1155 $(this).val('');1156 });1157 } else {1158 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1159 }1160 },1161 error: function (result) {1162 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1163 }1164 });1165 }1166 } else {1167 notifyInfo('æ示',"没æcopyä»æ°æ®");1168 return false;1169 }1170};1171equipmentInstallation.loadList = function () {1172 var cols = [];1173 cols.push({1174 checkbox: true,1175 formatter: {1176 disabled: false,//设置æ¯å¦å¯ç¨1177 checked: false//设置éä¸1178 }1179 });1180 cols.push({1181 field: 'area', title: 'åºå', formatter: function (value, row, index) {1182 var result = '';1183 if (row.provinceName) {1184 result = row.provinceName;1185 }1186 if (row.cityName) {1187 result += row.cityName;1188 }1189 if (row.districtName) {1190 result += row.districtName;1191 }1192 return result;1193 }1194 });1195 cols.push({field: 'provinceName', title: 'ç', visible: false});1196 cols.push({field: 'cityName', title: 'å¸', visible: false});1197 cols.push({field: 'districtName', title: 'å¿', visible: false});1198 cols.push({field: 'bookEquipmentFee', title: 'è´¦é¢è®¾å¤è´¹', visible: false});1199 cols.push({field: 'bookCapitalCost', title: 'è´¦é¢èµéææ¬', visible: false});1200 cols.push({field: 'bookInstallationFee', title: 'è´¦é¢å®è£
è´¹'});1201 cols.push({field: 'declarer', title: 'ç³æ¥äºº'});1202 cols.push({field: 'beLocated', title: 'åè½'});1203 cols.push({field: 'centerId', title: 'ä¸é´è¡¨id', visible: true});1204 cols.push({field: 'fileViewName', title: 'é件'});1205 cols.push({1206 field: 'id', title: 'å
³èä¿¡æ¯', formatter: function (value, row, index) {1207 var str = '<div class="dropdown">';1208 str += "<button class='btn btn-primary dropdown-toggle' data-toggle='dropdown' id='dropdownMenu2'>" + "<i class='fa fa-users'>" + "</i>" + "å
³èä¿¡æ¯" + "<span class='caret'>" + "</span>" + "</button>";1209 str += "<ul class='dropdown-menu' role='menu' aria-labelledby='dropdownMenu2'>";1210 if (row.declareBuildEngineeringAndEquipmentCenter.landId) {1211 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareRealtyLandCertView(" + row.centerId + ")'" + ">" + "åå°è¯" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1212 } else {1213 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareRealtyLandCertView(" + row.centerId + ")'" + ">" + "åå°è¯" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1214 }1215 if (row.declareBuildEngineeringAndEquipmentCenter.realEstateId) {1216 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareRealtyRealEstateCertView(" + row.centerId + ")'" + ">" + "ä¸å¨äº§" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1217 } else {1218 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareRealtyRealEstateCertView(" + row.centerId + ")'" + ">" + "ä¸å¨äº§" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1219 }1220 if (row.declareBuildEngineeringAndEquipmentCenter.buildingPermitId) {1221 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareBuildingPermitView(" + row.centerId + ")'" + ">" + "建设工ç¨è§å许å¯è¯" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1222 } else {1223 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareBuildingPermitView(" + row.centerId + ")'" + ">" + "建设工ç¨è§å许å¯è¯" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1224 }1225 if (row.declareBuildEngineeringAndEquipmentCenter.landUsePermitId) {1226 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareLandUsePermitView(" + row.centerId + ")'" + ">" + "建设ç¨å°è§å许å¯è¯" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1227 } else {1228 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareLandUsePermitView(" + row.centerId + ")'" + ">" + "建设ç¨å°è§å许å¯è¯" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1229 }1230 if (row.declareBuildEngineeringAndEquipmentCenter.buildingConstructionPermitId) {1231 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareBuildingConstructionPermitView(" + row.centerId + ")'" + ">" + "建çå·¥ç¨æ½å·¥è®¸å¯è¯" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1232 } else {1233 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareBuildingConstructionPermitView(" + row.centerId + ")'" + ">" + "建çå·¥ç¨æ½å·¥è®¸å¯è¯" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1234 }1235 if (row.declareBuildEngineeringAndEquipmentCenter.preSalePermitId) {1236 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declarePreSalePermitView(" + row.centerId + ")'" + ">" + "ååæ¿é¢å®è®¸å¯è¯" + "<i class='fa fa-check'></i>" + "</a>" + "</li>";1237 } else {1238 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declarePreSalePermitView(" + row.centerId + ")'" + ">" + "ååæ¿é¢å®è®¸å¯è¯" + "<i class='fa fa-remove'></i>" + "</a>" + "</li>";1239 }1240 if (row.declareBuildEngineeringAndEquipmentCenter) {1241 str += "<li role='presentation'>" + "<a role='menuitem' tabindex='-1' class='btn btn-default' onclick='equipmentInstallation.declareEconomicIndicatorsView(" + row.centerId + ")'" + ">" + "ç»æµè§åææ " + "<i class='fa fa-adjust'></i>" + "</a>" + "</li>";1242 }1243 str += "</ul>";1244 str += "</div>";1245 return str;1246 }1247 });1248 $("#" + equipmentInstallation.config.table).bootstrapTable('destroy');1249 TableInit(equipmentInstallation.config.table, getContextPath() + "/declareBuildEquipmentInstall/getDeclareBuildEquipmentInstallList", cols, {1250 planDetailsId: declareCommon.getPlanDetailsId(),1251 }, {1252 method: "get",1253 showColumns: false,1254 showRefresh: false,1255 search: false,1256 striped: true,1257 onLoadSuccess: function (data) {1258 $('.tooltips').tooltip();1259 }1260 });1261};1262/**1263 * @author: zch1264 * æè¿°:导å
¥1265 * @date:2018-09-281266 **/1267equipmentInstallation.inputFile = function () {1268 $.ajaxFileUpload({1269 type: "POST",1270 url: getContextPath() + "/declareBuildEquipmentInstall/importData",1271 data: {1272 planDetailsId: declareCommon.getPlanDetailsId(),1273 declareType : declareFunObj.getDeclareType("设å¤å®è£
")1274 },//è¦ä¼ å°åå°çåæ°ï¼æ²¡æå¯ä»¥ä¸å1275 secureuri: false,//æ¯å¦å¯ç¨å®å
¨æ交ï¼é»è®¤ä¸ºfalse1276 fileElementId: equipmentInstallation.config.excelUpload,//æ件éæ©æ¡çidå±æ§1277 dataType: 'json',//æå¡å¨è¿åçæ ¼å¼1278 async: false,1279 success: function (result) {1280 if (result.ret) {1281 equipmentInstallation.loadList();1282 notifyInfo("æ示",result.data);1283 }1284 },1285 error: function (result, status, e) {1286 Loading.progressHide();1287 AlertError("失败","è°ç¨æå¡ç«¯æ¹æ³å¤±è´¥ï¼å¤±è´¥åå :" + result.errmsg);1288 }1289 });1290};1291$(function () {1292 equipmentInstallation.loadList();...
ParseInstallation.spec.js
Source:ParseInstallation.spec.js
1'use strict';2// These tests check the Installations functionality of the REST API.3// Ported from installation_collection_test.go4const auth = require('../src/Auth');5const Config = require('../src/Config');6const Parse = require('parse/node').Parse;7const rest = require('../src/rest');8const request = require("request");9let config;10let database;11const defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;12const delay = function delay(delay) {13 return new Promise(resolve => setTimeout(resolve, delay));14}15const installationSchema = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation) };16describe('Installations', () => {17 beforeEach(() => {18 config = new Config('test');19 database = config.database;20 });21 it('creates an android installation with ids', (done) => {22 var installId = '12345678-abcd-abcd-abcd-123456789abc';23 var device = 'android';24 var input = {25 'installationId': installId,26 'deviceType': device27 };28 rest.create(config, auth.nobody(config), '_Installation', input)29 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))30 .then(results => {31 expect(results.length).toEqual(1);32 var obj = results[0];33 expect(obj.installationId).toEqual(installId);34 expect(obj.deviceType).toEqual(device);35 done();36 }).catch((error) => { console.log(error); jfail(error); done(); });37 });38 it('creates an ios installation with ids', (done) => {39 var t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';40 var device = 'ios';41 var input = {42 'deviceToken': t,43 'deviceType': device44 };45 rest.create(config, auth.nobody(config), '_Installation', input)46 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))47 .then(results => {48 expect(results.length).toEqual(1);49 var obj = results[0];50 expect(obj.deviceToken).toEqual(t);51 expect(obj.deviceType).toEqual(device);52 done();53 }).catch((error) => { console.log(error); jfail(error); done(); });54 });55 it('creates an embedded installation with ids', (done) => {56 var installId = '12345678-abcd-abcd-abcd-123456789abc';57 var device = 'embedded';58 var input = {59 'installationId': installId,60 'deviceType': device61 };62 rest.create(config, auth.nobody(config), '_Installation', input)63 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))64 .then(results => {65 expect(results.length).toEqual(1);66 var obj = results[0];67 expect(obj.installationId).toEqual(installId);68 expect(obj.deviceType).toEqual(device);69 done();70 }).catch((error) => { console.log(error); jfail(error); done(); });71 });72 it('creates an android installation with all fields', (done) => {73 var installId = '12345678-abcd-abcd-abcd-123456789abc';74 var device = 'android';75 var input = {76 'installationId': installId,77 'deviceType': device,78 'channels': ['foo', 'bar']79 };80 rest.create(config, auth.nobody(config), '_Installation', input)81 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))82 .then(results => {83 expect(results.length).toEqual(1);84 var obj = results[0];85 expect(obj.installationId).toEqual(installId);86 expect(obj.deviceType).toEqual(device);87 expect(typeof obj.channels).toEqual('object');88 expect(obj.channels.length).toEqual(2);89 expect(obj.channels[0]).toEqual('foo');90 expect(obj.channels[1]).toEqual('bar');91 done();92 }).catch((error) => { console.log(error); jfail(error); done(); });93 });94 it('creates an ios installation with all fields', (done) => {95 var t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';96 var device = 'ios';97 var input = {98 'deviceToken': t,99 'deviceType': device,100 'channels': ['foo', 'bar']101 };102 rest.create(config, auth.nobody(config), '_Installation', input)103 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))104 .then(results => {105 expect(results.length).toEqual(1);106 var obj = results[0];107 expect(obj.deviceToken).toEqual(t);108 expect(obj.deviceType).toEqual(device);109 expect(typeof obj.channels).toEqual('object');110 expect(obj.channels.length).toEqual(2);111 expect(obj.channels[0]).toEqual('foo');112 expect(obj.channels[1]).toEqual('bar');113 done();114 }).catch((error) => { console.log(error); jfail(error); done(); });115 });116 it('should properly fail queying installations', (done) => {117 var installId = '12345678-abcd-abcd-abcd-123456789abc';118 var device = 'android';119 var input = {120 'installationId': installId,121 'deviceType': device122 };123 rest.create(config, auth.nobody(config), '_Installation', input)124 .then(() => {125 const query = new Parse.Query(Parse.Installation);126 return query.find()127 }).then(() => {128 fail('Should not succeed!');129 done();130 }).catch((error) => {131 expect(error.code).toBe(119);132 expect(error.message).toBe('Clients aren\'t allowed to perform the find operation on the installation collection.')133 done();134 });135 });136 it('should properly queying installations with masterKey', (done) => {137 var installId = '12345678-abcd-abcd-abcd-123456789abc';138 var device = 'android';139 var input = {140 'installationId': installId,141 'deviceType': device142 };143 rest.create(config, auth.nobody(config), '_Installation', input)144 .then(() => {145 const query = new Parse.Query(Parse.Installation);146 return query.find({useMasterKey: true});147 }).then((results) => {148 expect(results.length).toEqual(1);149 var obj = results[0].toJSON();150 expect(obj.installationId).toEqual(installId);151 expect(obj.deviceType).toEqual(device);152 done();153 }).catch(() => {154 fail('Should not fail');155 done();156 });157 });158 it('fails with missing ids', (done) => {159 var input = {160 'deviceType': 'android',161 'channels': ['foo', 'bar']162 };163 rest.create(config, auth.nobody(config), '_Installation', input)164 .then(() => {165 fail('Should not have been able to create an Installation.');166 done();167 }).catch((error) => {168 expect(error.code).toEqual(135);169 done();170 });171 });172 it('fails for android with missing type', (done) => {173 var installId = '12345678-abcd-abcd-abcd-123456789abc';174 var input = {175 'installationId': installId,176 'channels': ['foo', 'bar']177 };178 rest.create(config, auth.nobody(config), '_Installation', input)179 .then(() => {180 fail('Should not have been able to create an Installation.');181 done();182 }).catch((error) => {183 expect(error.code).toEqual(135);184 done();185 });186 });187 it('creates an object with custom fields', (done) => {188 var t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';189 var input = {190 'deviceToken': t,191 'deviceType': 'ios',192 'channels': ['foo', 'bar'],193 'custom': 'allowed'194 };195 rest.create(config, auth.nobody(config), '_Installation', input)196 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))197 .then(results => {198 expect(results.length).toEqual(1);199 var obj = results[0];200 expect(obj.custom).toEqual('allowed');201 done();202 }).catch((error) => { console.log(error); });203 });204 // Note: did not port test 'TestObjectIDForIdentifiers'205 it('merging when installationId already exists', (done) => {206 var installId1 = '12345678-abcd-abcd-abcd-123456789abc';207 var t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';208 var input = {209 'deviceToken': t,210 'deviceType': 'ios',211 'installationId': installId1,212 'channels': ['foo', 'bar']213 };214 var firstObject;215 var secondObject;216 rest.create(config, auth.nobody(config), '_Installation', input)217 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))218 .then(results => {219 expect(results.length).toEqual(1);220 firstObject = results[0];221 delete input.deviceToken;222 delete input.channels;223 input['foo'] = 'bar';224 return rest.create(config, auth.nobody(config), '_Installation', input);225 })226 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))227 .then(results => {228 expect(results.length).toEqual(1);229 secondObject = results[0];230 expect(firstObject._id).toEqual(secondObject._id);231 expect(secondObject.channels.length).toEqual(2);232 expect(secondObject.foo).toEqual('bar');233 done();234 }).catch((error) => { console.log(error); });235 });236 it('merging when two objects both only have one id', (done) => {237 var installId = '12345678-abcd-abcd-abcd-123456789abc';238 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';239 var input1 = {240 'installationId': installId,241 'deviceType': 'ios'242 };243 var input2 = {244 'deviceToken': t,245 'deviceType': 'ios'246 };247 var input3 = {248 'deviceToken': t,249 'installationId': installId,250 'deviceType': 'ios'251 };252 var firstObject;253 var secondObject;254 rest.create(config, auth.nobody(config), '_Installation', input1)255 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))256 .then(results => {257 expect(results.length).toEqual(1);258 firstObject = results[0];259 return rest.create(config, auth.nobody(config), '_Installation', input2);260 })261 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))262 .then(results => {263 expect(results.length).toEqual(2);264 if (results[0]['_id'] == firstObject._id) {265 secondObject = results[1];266 } else {267 secondObject = results[0];268 }269 return rest.create(config, auth.nobody(config), '_Installation', input3);270 })271 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))272 .then(results => {273 expect(results.length).toEqual(1);274 expect(results[0]['_id']).toEqual(secondObject._id);275 done();276 }).catch((error) => {277 jfail(error);278 done();279 });280 });281 xit('creating multiple devices with same device token works', (done) => {282 var installId1 = '11111111-abcd-abcd-abcd-123456789abc';283 var installId2 = '22222222-abcd-abcd-abcd-123456789abc';284 var installId3 = '33333333-abcd-abcd-abcd-123456789abc';285 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';286 var input = {287 'installationId': installId1,288 'deviceType': 'ios',289 'deviceToken': t290 };291 rest.create(config, auth.nobody(config), '_Installation', input)292 .then(() => {293 input.installationId = installId2;294 return rest.create(config, auth.nobody(config), '_Installation', input);295 }).then(() => {296 input.installationId = installId3;297 return rest.create(config, auth.nobody(config), '_Installation', input);298 })299 .then(() => database.adapter.find('_Installation', {installationId: installId1}, installationSchema, {}))300 .then(results => {301 expect(results.length).toEqual(1);302 return database.adapter.find('_Installation', {installationId: installId2}, installationSchema, {});303 }).then(results => {304 expect(results.length).toEqual(1);305 return database.adapter.find('_Installation', {installationId: installId3}, installationSchema, {});306 }).then((results) => {307 expect(results.length).toEqual(1);308 done();309 }).catch((error) => { console.log(error); });310 });311 it('updating with new channels', (done) => {312 var input = {313 installationId: '12345678-abcd-abcd-abcd-123456789abc',314 deviceType: 'android',315 channels: ['foo', 'bar']316 };317 rest.create(config, auth.nobody(config), '_Installation', input)318 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))319 .then(results => {320 expect(results.length).toEqual(1);321 var objectId = results[0].objectId;322 var update = {323 'channels': ['baz']324 };325 return rest.update(config, auth.nobody(config), '_Installation', { objectId }, update);326 })327 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))328 .then(results => {329 expect(results.length).toEqual(1);330 expect(results[0].channels.length).toEqual(1);331 expect(results[0].channels[0]).toEqual('baz');332 done();333 }).catch(error => {334 jfail(error);335 done();336 });337 });338 it('update android fails with new installation id', (done) => {339 var installId1 = '12345678-abcd-abcd-abcd-123456789abc';340 var installId2 = '87654321-abcd-abcd-abcd-123456789abc';341 var input = {342 'installationId': installId1,343 'deviceType': 'android',344 'channels': ['foo', 'bar']345 };346 rest.create(config, auth.nobody(config), '_Installation', input)347 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))348 .then(results => {349 expect(results.length).toEqual(1);350 input = { 'installationId': installId2 };351 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);352 }).then(() => {353 fail('Updating the installation should have failed.');354 done();355 }).catch((error) => {356 expect(error.code).toEqual(136);357 done();358 });359 });360 it('update ios fails with new deviceToken and no installationId', (done) => {361 var a = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';362 var b = '91433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';363 var input = {364 'deviceToken': a,365 'deviceType': 'ios',366 'channels': ['foo', 'bar']367 };368 rest.create(config, auth.nobody(config), '_Installation', input)369 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))370 .then(results => {371 expect(results.length).toEqual(1);372 input = { 'deviceToken': b };373 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);374 }).then(() => {375 fail('Updating the installation should have failed.');376 }).catch((error) => {377 expect(error.code).toEqual(136);378 done();379 });380 });381 it('update ios updates device token', (done) => {382 var installId = '12345678-abcd-abcd-abcd-123456789abc';383 var t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';384 var u = '91433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306';385 var input = {386 'installationId': installId,387 'deviceType': 'ios',388 'deviceToken': t,389 'channels': ['foo', 'bar']390 };391 rest.create(config, auth.nobody(config), '_Installation', input)392 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))393 .then(results => {394 expect(results.length).toEqual(1);395 input = {396 'installationId': installId,397 'deviceToken': u,398 'deviceType': 'ios'399 };400 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);401 })402 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))403 .then(results => {404 expect(results.length).toEqual(1);405 expect(results[0].deviceToken).toEqual(u);406 done();407 }).catch(err => {408 jfail(err);409 done();410 })411 });412 it('update fails to change deviceType', (done) => {413 var installId = '12345678-abcd-abcd-abcd-123456789abc';414 var input = {415 'installationId': installId,416 'deviceType': 'android',417 'channels': ['foo', 'bar']418 };419 rest.create(config, auth.nobody(config), '_Installation', input)420 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))421 .then(results => {422 expect(results.length).toEqual(1);423 input = {424 'deviceType': 'ios'425 };426 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);427 }).then(() => {428 fail('Should not have been able to update Installation.');429 done();430 }).catch((error) => {431 expect(error.code).toEqual(136);432 done();433 });434 });435 it('update android with custom field', (done) => {436 var installId = '12345678-abcd-abcd-abcd-123456789abc';437 var input = {438 'installationId': installId,439 'deviceType': 'android',440 'channels': ['foo', 'bar']441 };442 rest.create(config, auth.nobody(config), '_Installation', input)443 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))444 .then(results => {445 expect(results.length).toEqual(1);446 input = {447 'custom': 'allowed'448 };449 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);450 })451 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))452 .then(results => {453 expect(results.length).toEqual(1);454 expect(results[0]['custom']).toEqual('allowed');455 done();456 });457 });458 it('update android device token with duplicate device token', (done) => {459 var installId1 = '11111111-abcd-abcd-abcd-123456789abc';460 var installId2 = '22222222-abcd-abcd-abcd-123456789abc';461 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';462 var input = {463 'installationId': installId1,464 'deviceToken': t,465 'deviceType': 'android'466 };467 var firstObject;468 var secondObject;469 rest.create(config, auth.nobody(config), '_Installation', input)470 .then(() => {471 input = {472 'installationId': installId2,473 'deviceType': 'android'474 };475 return rest.create(config, auth.nobody(config), '_Installation', input);476 })477 .then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId1}, {}))478 .then(results => {479 firstObject = results[0];480 expect(results.length).toEqual(1);481 return database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {});482 }).then(results => {483 expect(results.length).toEqual(1);484 secondObject = results[0];485 // Update second installation to conflict with first installation486 input = {487 'objectId': secondObject.objectId,488 'deviceToken': t489 };490 return rest.update(config, auth.nobody(config), '_Installation', { objectId: secondObject.objectId }, input);491 })492 .then(() => database.adapter.find('_Installation', installationSchema, {objectId: firstObject.objectId}, {}))493 .then(results => {494 // The first object should have been deleted495 expect(results.length).toEqual(0);496 done();497 }).catch(error => {498 jfail(error);499 done();500 });501 });502 it('update ios device token with duplicate device token', (done) => {503 var installId1 = '11111111-abcd-abcd-abcd-123456789abc';504 var installId2 = '22222222-abcd-abcd-abcd-123456789abc';505 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';506 var input = {507 'installationId': installId1,508 'deviceToken': t,509 'deviceType': 'ios'510 };511 var firstObject;512 var secondObject;513 rest.create(config, auth.nobody(config), '_Installation', input)514 .then(() => {515 input = {516 'installationId': installId2,517 'deviceType': 'ios'518 };519 return rest.create(config, auth.nobody(config), '_Installation', input);520 })521 .then(() => delay(100))522 .then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId1}, {}))523 .then((results) => {524 expect(results.length).toEqual(1);525 firstObject = results[0];526 })527 .then(() => delay(100))528 .then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {}))529 .then(results => {530 expect(results.length).toEqual(1);531 secondObject = results[0];532 // Update second installation to conflict with first installation id533 input = {534 'installationId': installId2,535 'deviceToken': t536 };537 return rest.update(config, auth.nobody(config), '_Installation', { objectId: secondObject.objectId }, input);538 })539 .then(() => delay(100))540 .then(() => database.adapter.find('_Installation', installationSchema, {objectId: firstObject.objectId}, {}))541 .then(results => {542 // The first object should have been deleted543 expect(results.length).toEqual(0);544 done();545 }).catch(error => {546 jfail(error);547 done();548 });549 });550 xit('update ios device token with duplicate token different app', (done) => {551 var installId1 = '11111111-abcd-abcd-abcd-123456789abc';552 var installId2 = '22222222-abcd-abcd-abcd-123456789abc';553 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';554 var input = {555 'installationId': installId1,556 'deviceToken': t,557 'deviceType': 'ios',558 'appIdentifier': 'foo'559 };560 rest.create(config, auth.nobody(config), '_Installation', input)561 .then(() => {562 input.installationId = installId2;563 input.appIdentifier = 'bar';564 return rest.create(config, auth.nobody(config), '_Installation', input);565 })566 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))567 .then(results => {568 // The first object should have been deleted during merge569 expect(results.length).toEqual(1);570 expect(results[0].installationId).toEqual(installId2);571 done();572 }).catch(error => {573 jfail(error);574 done();575 });576 });577 it('update ios token and channels', (done) => {578 var installId = '12345678-abcd-abcd-abcd-123456789abc';579 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';580 var input = {581 'installationId': installId,582 'deviceType': 'ios'583 };584 rest.create(config, auth.nobody(config), '_Installation', input)585 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))586 .then(results => {587 expect(results.length).toEqual(1);588 input = {589 'deviceToken': t,590 'channels': []591 };592 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);593 })594 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))595 .then(results => {596 expect(results.length).toEqual(1);597 expect(results[0].installationId).toEqual(installId);598 expect(results[0].deviceToken).toEqual(t);599 expect(results[0].channels.length).toEqual(0);600 done();601 }).catch(error => {602 jfail(error);603 done();604 });605 });606 it('update ios linking two existing objects', (done) => {607 var installId = '12345678-abcd-abcd-abcd-123456789abc';608 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';609 var input = {610 'installationId': installId,611 'deviceType': 'ios'612 };613 rest.create(config, auth.nobody(config), '_Installation', input)614 .then(() => {615 input = {616 'deviceToken': t,617 'deviceType': 'ios'618 };619 return rest.create(config, auth.nobody(config), '_Installation', input);620 })621 .then(() => database.adapter.find('_Installation', installationSchema, { deviceToken: t }, {}))622 .then(results => {623 expect(results.length).toEqual(1);624 input = {625 'deviceToken': t,626 'installationId': installId,627 'deviceType': 'ios'628 };629 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);630 })631 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))632 .then(results => {633 expect(results.length).toEqual(1);634 expect(results[0].installationId).toEqual(installId);635 expect(results[0].deviceToken).toEqual(t);636 expect(results[0].deviceType).toEqual('ios');637 done();638 }).catch(error => {639 jfail(error);640 done();641 });642 });643 it('update is linking two existing objects w/ increment', (done) => {644 var installId = '12345678-abcd-abcd-abcd-123456789abc';645 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';646 var input = {647 'installationId': installId,648 'deviceType': 'ios'649 };650 rest.create(config, auth.nobody(config), '_Installation', input)651 .then(() => {652 input = {653 'deviceToken': t,654 'deviceType': 'ios'655 };656 return rest.create(config, auth.nobody(config), '_Installation', input);657 })658 .then(() => database.adapter.find('_Installation', installationSchema, { deviceToken: t }, {}))659 .then(results => {660 expect(results.length).toEqual(1);661 input = {662 'deviceToken': t,663 'installationId': installId,664 'deviceType': 'ios',665 'score': {666 '__op': 'Increment',667 'amount': 1668 }669 };670 return rest.update(config, auth.nobody(config), '_Installation', { objectId: results[0].objectId }, input);671 })672 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))673 .then(results => {674 expect(results.length).toEqual(1);675 expect(results[0].installationId).toEqual(installId);676 expect(results[0].deviceToken).toEqual(t);677 expect(results[0].deviceType).toEqual('ios');678 expect(results[0].score).toEqual(1);679 done();680 }).catch(error => {681 jfail(error);682 done();683 });684 });685 it('update is linking two existing with installation id', (done) => {686 var installId = '12345678-abcd-abcd-abcd-123456789abc';687 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';688 var input = {689 'installationId': installId,690 'deviceType': 'ios'691 };692 var installObj;693 var tokenObj;694 rest.create(config, auth.nobody(config), '_Installation', input)695 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))696 .then(results => {697 expect(results.length).toEqual(1);698 installObj = results[0];699 input = {700 'deviceToken': t,701 'deviceType': 'ios'702 };703 return rest.create(config, auth.nobody(config), '_Installation', input);704 })705 .then(() => database.adapter.find('_Installation', installationSchema, { deviceToken: t }, {}))706 .then(results => {707 expect(results.length).toEqual(1);708 tokenObj = results[0];709 input = {710 'installationId': installId,711 'deviceToken': t,712 'deviceType': 'ios'713 };714 return rest.update(config, auth.nobody(config), '_Installation', { objectId: installObj.objectId }, input);715 })716 .then(() => database.adapter.find('_Installation', installationSchema, { objectId: tokenObj.objectId }, {}))717 .then(results => {718 expect(results.length).toEqual(1);719 expect(results[0].installationId).toEqual(installId);720 expect(results[0].deviceToken).toEqual(t);721 done();722 }).catch(error => {723 jfail(error);724 done();725 });726 });727 it('update is linking two existing with installation id w/ op', (done) => {728 var installId = '12345678-abcd-abcd-abcd-123456789abc';729 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';730 var input = {731 'installationId': installId,732 'deviceType': 'ios'733 };734 var installObj;735 var tokenObj;736 rest.create(config, auth.nobody(config), '_Installation', input)737 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))738 .then(results => {739 expect(results.length).toEqual(1);740 installObj = results[0];741 input = {742 'deviceToken': t,743 'deviceType': 'ios'744 };745 return rest.create(config, auth.nobody(config), '_Installation', input);746 })747 .then(() => database.adapter.find('_Installation', installationSchema, { deviceToken: t }, {}))748 .then(results => {749 expect(results.length).toEqual(1);750 tokenObj = results[0];751 input = {752 'installationId': installId,753 'deviceToken': t,754 'deviceType': 'ios',755 'score': {756 '__op': 'Increment',757 'amount': 1758 }759 };760 return rest.update(config, auth.nobody(config), '_Installation', { objectId: installObj.objectId }, input);761 })762 .then(() => database.adapter.find('_Installation', installationSchema, { objectId: tokenObj.objectId }, {}))763 .then(results => {764 expect(results.length).toEqual(1);765 expect(results[0].installationId).toEqual(installId);766 expect(results[0].deviceToken).toEqual(t);767 expect(results[0].score).toEqual(1);768 done();769 }).catch(error => {770 jfail(error);771 done();772 });773 });774 it('ios merge existing same token no installation id', (done) => {775 // Test creating installation when there is an existing object with the776 // same device token but no installation ID. This is possible when777 // developers import device tokens from another push provider; the import778 // process does not generate installation IDs. When they later integrate779 // the Parse SDK, their app is going to save the installation. This save780 // op will have a client-generated installation ID as well as a device781 // token. At this point, if the device token matches the originally-782 // imported installation, then we should reuse the existing installation783 // object in case the developer already added additional fields via Data784 // Browser or REST API (e.g. channel targeting info).785 var t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';786 var installId = '12345678-abcd-abcd-abcd-123456789abc';787 var input = {788 'deviceToken': t,789 'deviceType': 'ios'790 };791 rest.create(config, auth.nobody(config), '_Installation', input)792 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))793 .then(results => {794 expect(results.length).toEqual(1);795 input = {796 'installationId': installId,797 'deviceToken': t,798 'deviceType': 'ios'799 };800 return rest.create(config, auth.nobody(config), '_Installation', input);801 })802 .then(() => database.adapter.find('_Installation', installationSchema, {}, {}))803 .then(results => {804 expect(results.length).toEqual(1);805 expect(results[0].deviceToken).toEqual(t);806 expect(results[0].installationId).toEqual(installId);807 done();808 })809 .catch(error => {810 console.log(error);811 fail();812 done();813 });814 });815 it('allows you to get your own installation (regression test for #1718)', done => {816 const installId = '12345678-abcd-abcd-abcd-123456789abc';817 const device = 'android';818 const input = {819 'installationId': installId,820 'deviceType': device821 };822 rest.create(config, auth.nobody(config), '_Installation', input)823 .then(createResult => {824 const headers = {825 'X-Parse-Application-Id': 'test',826 'X-Parse-REST-API-Key': 'rest',827 };828 request.get({829 headers: headers,830 url: 'http://localhost:8378/1/installations/' + createResult.response.objectId,831 json: true,832 }, (error, response, body) => {833 expect(body.objectId).toEqual(createResult.response.objectId);834 done();835 });836 })837 .catch(error => {838 console.log(error);839 fail('failed');840 done();841 });842 });843 it('allows you to update installation from header (#2090)', done => {844 const installId = '12345678-abcd-abcd-abcd-123456789abc';845 const device = 'android';846 const input = {847 'installationId': installId,848 'deviceType': device849 };850 rest.create(config, auth.nobody(config), '_Installation', input)851 .then(() => {852 const headers = {853 'X-Parse-Application-Id': 'test',854 'X-Parse-REST-API-Key': 'rest',855 'X-Parse-Installation-Id': installId856 };857 request.post({858 headers: headers,859 url: 'http://localhost:8378/1/classes/_Installation',860 json: true,861 body: {862 date: new Date()863 }864 }, (error, response, body) => {865 expect(response.statusCode).toBe(200);866 expect(body.updatedAt).not.toBeUndefined();867 done();868 });869 })870 .catch(error => {871 console.log(error);872 fail('failed');873 done();874 });875 });876 it('allows you to update installation with masterKey', done => {877 const installId = '12345678-abcd-abcd-abcd-123456789abc';878 const device = 'android';879 const input = {880 'installationId': installId,881 'deviceType': device882 };883 rest.create(config, auth.nobody(config), '_Installation', input)884 .then(createResult => {885 const installationObj = Parse.Installation.createWithoutData(createResult.response.objectId);886 installationObj.set('customField', 'custom value');887 return installationObj.save(null, {useMasterKey: true});888 }).then(updateResult => {889 expect(updateResult).not.toBeUndefined();890 expect(updateResult.get('customField')).toEqual('custom value');891 done();892 }).catch(error => {893 console.log(error);894 fail('failed');895 done();896 });897 });898 it('should properly handle installation save #2780', done => {899 const installId = '12345678-abcd-abcd-abcd-123456789abc';900 const device = 'android';901 const input = {902 'installationId': installId,903 'deviceType': device904 };905 rest.create(config, auth.nobody(config), '_Installation', input).then(() => {906 const query = new Parse.Query(Parse.Installation);907 query.equalTo('installationId', installId);908 query.first({useMasterKey: true}).then((installation) => {909 return installation.save({910 key: 'value'911 }, {useMasterKey: true});912 }).then(() => {913 done();914 }, (err) => {915 jfail(err)916 done();917 });918 });919 });920 it('should properly reject updating installationId', done => {921 const installId = '12345678-abcd-abcd-abcd-123456789abc';922 const device = 'android';923 const input = {924 'installationId': installId,925 'deviceType': device926 };927 rest.create(config, auth.nobody(config), '_Installation', input).then(() => {928 const query = new Parse.Query(Parse.Installation);929 query.equalTo('installationId', installId);930 query.first({useMasterKey: true}).then((installation) => {931 return installation.save({932 key: 'value',933 installationId: '22222222-abcd-abcd-abcd-123456789abc'934 }, {useMasterKey: true});935 }).then(() => {936 fail('should not succeed');937 done();938 }, (err) => {939 expect(err.code).toBe(136);940 expect(err.message).toBe('installationId may not be changed in this operation');941 done();942 });943 });944 });945 // TODO: Look at additional tests from installation_collection_test.go:882946 // TODO: Do we need to support _tombstone disabling of installations?947 // TODO: Test deletion, badge increments...
get-installation-entry.test.ts
Source:get-installation-entry.test.ts
1/**2 * @license3 * Copyright 2019 Google LLC4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17import { AssertionError, expect } from 'chai';18import { SinonFakeTimers, SinonStub, stub, useFakeTimers } from 'sinon';19import * as createInstallationRequestModule from '../api/create-installation-request';20import { AppConfig } from '../interfaces/app-config';21import {22 InProgressInstallationEntry,23 RegisteredInstallationEntry,24 RequestStatus,25 UnregisteredInstallationEntry26} from '../interfaces/installation-entry';27import { getFakeAppConfig } from '../testing/fake-generators';28import '../testing/setup';29import { ERROR_FACTORY, ErrorCode } from '../util/errors';30import { sleep } from '../util/sleep';31import * as generateFidModule from './generate-fid';32import { getInstallationEntry } from './get-installation-entry';33import { get, set } from './idb-manager';34const FID = 'cry-of-the-black-birds';35describe('getInstallationEntry', () => {36 let clock: SinonFakeTimers;37 let appConfig: AppConfig;38 let createInstallationRequestSpy: SinonStub<39 [AppConfig, InProgressInstallationEntry],40 Promise<RegisteredInstallationEntry>41 >;42 beforeEach(() => {43 clock = useFakeTimers({ now: 1_000_000 });44 appConfig = getFakeAppConfig();45 createInstallationRequestSpy = stub(46 createInstallationRequestModule,47 'createInstallationRequest'48 ).callsFake(49 async (_, installationEntry): Promise<RegisteredInstallationEntry> => {50 await sleep(500); // Request would take some time51 const registeredInstallationEntry: RegisteredInstallationEntry = {52 // Returns new FID if client FID is invalid.53 fid: installationEntry.fid || FID,54 registrationStatus: RequestStatus.COMPLETED,55 refreshToken: 'refreshToken',56 authToken: {57 requestStatus: RequestStatus.COMPLETED,58 creationTime: Date.now(),59 token: 'token',60 expiresIn: 1_000_000_00061 }62 };63 return registeredInstallationEntry;64 }65 );66 });67 afterEach(() => {68 // Clean up all pending requests.69 clock.runAll();70 });71 it('saves the InstallationEntry in the database before returning it', async () => {72 const oldDbEntry = await get(appConfig);73 expect(oldDbEntry).to.be.undefined;74 const { installationEntry } = await getInstallationEntry(appConfig);75 const newDbEntry = await get(appConfig);76 expect(newDbEntry).to.deep.equal(installationEntry);77 });78 it('saves the InstallationEntry in the database if app is offline', async () => {79 stub(navigator, 'onLine').value(false);80 const oldDbEntry = await get(appConfig);81 expect(oldDbEntry).to.be.undefined;82 const { installationEntry } = await getInstallationEntry(appConfig);83 const newDbEntry = await get(appConfig);84 expect(newDbEntry).to.deep.equal(installationEntry);85 });86 it('saves the InstallationEntry in the database when registration completes', async () => {87 const {88 installationEntry,89 registrationPromise90 } = await getInstallationEntry(appConfig);91 expect(installationEntry.registrationStatus).to.equal(92 RequestStatus.IN_PROGRESS93 );94 expect(registrationPromise).to.be.an.instanceOf(Promise);95 const oldDbEntry = await get(appConfig);96 expect(oldDbEntry).to.deep.equal(installationEntry);97 clock.next(); // Finish registration request.98 await expect(registrationPromise).to.be.fulfilled;99 const newDbEntry = await get(appConfig);100 expect(newDbEntry!.registrationStatus).to.equal(RequestStatus.COMPLETED);101 });102 it('saves the InstallationEntry in the database when registration fails', async () => {103 createInstallationRequestSpy.callsFake(async () => {104 await sleep(500); // Request would take some time105 throw ERROR_FACTORY.create(ErrorCode.REQUEST_FAILED, {106 requestName: 'Create Installation',107 serverCode: 500,108 serverStatus: 'INTERNAL',109 serverMessage: 'Internal server error.'110 });111 });112 const {113 installationEntry,114 registrationPromise115 } = await getInstallationEntry(appConfig);116 expect(installationEntry.registrationStatus).to.equal(117 RequestStatus.IN_PROGRESS118 );119 expect(registrationPromise).to.be.an.instanceOf(Promise);120 const oldDbEntry = await get(appConfig);121 expect(oldDbEntry).to.deep.equal(installationEntry);122 clock.next(); // Finish registration request.123 await expect(registrationPromise).to.be.rejected;124 const newDbEntry = await get(appConfig);125 expect(newDbEntry!.registrationStatus).to.equal(RequestStatus.NOT_STARTED);126 });127 it('removes the InstallationEntry from the database when registration fails with 409', async () => {128 createInstallationRequestSpy.callsFake(async () => {129 await sleep(500); // Request would take some time130 throw ERROR_FACTORY.create(ErrorCode.REQUEST_FAILED, {131 requestName: 'Create Installation',132 serverCode: 409,133 serverStatus: 'INVALID_ARGUMENT',134 serverMessage: 'FID can not be used.'135 });136 });137 const {138 installationEntry,139 registrationPromise140 } = await getInstallationEntry(appConfig);141 expect(installationEntry.registrationStatus).to.equal(142 RequestStatus.IN_PROGRESS143 );144 const oldDbEntry = await get(appConfig);145 expect(oldDbEntry).to.deep.equal(installationEntry);146 clock.next(); // Finish registration request.147 await expect(registrationPromise).to.be.rejected;148 const newDbEntry = await get(appConfig);149 expect(newDbEntry).to.be.undefined;150 });151 it('returns the same FID on subsequent calls', async () => {152 const { installationEntry: entry1 } = await getInstallationEntry(appConfig);153 const { installationEntry: entry2 } = await getInstallationEntry(appConfig);154 expect(entry1.fid).to.equal(entry2.fid);155 });156 describe('when there is no InstallationEntry in database', () => {157 let generateInstallationEntrySpy: SinonStub<[], string>;158 beforeEach(() => {159 generateInstallationEntrySpy = stub(160 generateFidModule,161 'generateFid'162 ).returns(FID);163 });164 it('returns a new pending InstallationEntry and triggers createInstallation', async () => {165 const {166 installationEntry,167 registrationPromise168 } = await getInstallationEntry(appConfig);169 if (installationEntry.registrationStatus !== RequestStatus.IN_PROGRESS) {170 throw new AssertionError('InstallationEntry is not IN_PROGRESS.');171 }172 expect(registrationPromise).to.be.an.instanceOf(Promise);173 expect(installationEntry).to.deep.equal({174 fid: FID,175 registrationStatus: RequestStatus.IN_PROGRESS,176 // https://github.com/chaijs/chai/issues/644177 registrationTime: installationEntry.registrationTime178 });179 expect(generateInstallationEntrySpy).to.be.called;180 expect(createInstallationRequestSpy).to.be.called;181 });182 it('returns a new unregistered InstallationEntry if app is offline', async () => {183 stub(navigator, 'onLine').value(false);184 const { installationEntry } = await getInstallationEntry(appConfig);185 expect(installationEntry).to.deep.equal({186 fid: FID,187 registrationStatus: RequestStatus.NOT_STARTED188 });189 expect(generateInstallationEntrySpy).to.be.called;190 expect(createInstallationRequestSpy).not.to.be.called;191 });192 it('does not trigger createInstallation REST call on subsequent calls', async () => {193 await getInstallationEntry(appConfig);194 await getInstallationEntry(appConfig);195 expect(createInstallationRequestSpy).to.be.calledOnce;196 });197 it('returns a registrationPromise on subsequent calls before initial promise resolves', async () => {198 const { registrationPromise: promise1 } = await getInstallationEntry(199 appConfig200 );201 const { registrationPromise: promise2 } = await getInstallationEntry(202 appConfig203 );204 expect(createInstallationRequestSpy).to.be.calledOnce;205 expect(promise1).to.be.an.instanceOf(Promise);206 expect(promise2).to.be.an.instanceOf(Promise);207 });208 it('does not return a registrationPromise on subsequent calls after initial promise resolves', async () => {209 const { registrationPromise: promise1 } = await getInstallationEntry(210 appConfig211 );212 expect(promise1).to.be.an.instanceOf(Promise);213 clock.next(); // Finish registration request.214 await expect(promise1).to.be.fulfilled;215 const { registrationPromise: promise2 } = await getInstallationEntry(216 appConfig217 );218 expect(promise2).to.be.undefined;219 expect(createInstallationRequestSpy).to.be.calledOnce;220 });221 it('waits for the FID from the server if FID generation fails', async () => {222 clock.restore();223 clock = useFakeTimers({224 now: 1_000_000,225 shouldAdvanceTime: true /* Needed to allow the createInstallation request to complete. */226 });227 // FID generation fails.228 generateInstallationEntrySpy.returns(generateFidModule.INVALID_FID);229 const getInstallationEntryPromise = getInstallationEntry(appConfig);230 const {231 installationEntry,232 registrationPromise233 } = await getInstallationEntryPromise;234 expect(installationEntry.fid).to.equal(FID);235 expect(registrationPromise).to.be.undefined;236 });237 });238 describe('when there is an unregistered InstallationEntry in the database', () => {239 beforeEach(async () => {240 const unregisteredInstallationEntry: UnregisteredInstallationEntry = {241 fid: FID,242 registrationStatus: RequestStatus.NOT_STARTED243 };244 await set(appConfig, unregisteredInstallationEntry);245 });246 it('returns a pending InstallationEntry and triggers createInstallation', async () => {247 const {248 installationEntry,249 registrationPromise250 } = await getInstallationEntry(appConfig);251 if (installationEntry.registrationStatus !== RequestStatus.IN_PROGRESS) {252 throw new AssertionError('InstallationEntry is not IN_PROGRESS.');253 }254 expect(registrationPromise).to.be.an.instanceOf(Promise);255 expect(installationEntry).to.deep.equal({256 fid: FID,257 registrationStatus: RequestStatus.IN_PROGRESS,258 // https://github.com/chaijs/chai/issues/644259 registrationTime: installationEntry.registrationTime260 });261 expect(createInstallationRequestSpy).to.be.calledOnce;262 });263 it('returns the same InstallationEntry if the app is offline', async () => {264 stub(navigator, 'onLine').value(false);265 const { installationEntry } = await getInstallationEntry(appConfig);266 expect(installationEntry).to.deep.equal({267 fid: FID,268 registrationStatus: RequestStatus.NOT_STARTED269 });270 expect(createInstallationRequestSpy).not.to.be.called;271 });272 });273 describe('when there is a pending InstallationEntry in the database', () => {274 beforeEach(async () => {275 const inProgressInstallationEntry: InProgressInstallationEntry = {276 fid: FID,277 registrationStatus: RequestStatus.IN_PROGRESS,278 registrationTime: 1_000_000279 };280 await set(appConfig, inProgressInstallationEntry);281 });282 it("returns the same InstallationEntry if the request hasn't timed out", async () => {283 clock.now = 1_001_000; // One second after the request was initiated.284 const { installationEntry } = await getInstallationEntry(appConfig);285 expect(installationEntry).to.deep.equal({286 fid: FID,287 registrationStatus: RequestStatus.IN_PROGRESS,288 registrationTime: 1_000_000289 });290 expect(createInstallationRequestSpy).not.to.be.called;291 });292 it('updates the InstallationEntry and triggers createInstallation if the request fails', async () => {293 clock.restore();294 clock = useFakeTimers({295 now: 1_001_000 /* One second after the request was initiated. */,296 shouldAdvanceTime: true /* Needed to allow the createInstallation request to complete. */297 });298 const installationEntryPromise = getInstallationEntry(appConfig);299 // The pending request fails after a while.300 clock.tick(3000);301 await set(appConfig, {302 fid: FID,303 registrationStatus: RequestStatus.NOT_STARTED304 });305 const { registrationPromise } = await installationEntryPromise;306 // Let the new getInstallationEntry process start.307 await sleep(250);308 const tokenDetails = (await get(309 appConfig310 )) as InProgressInstallationEntry;311 expect(tokenDetails.registrationTime).to.be.at.least(312 /* When the first pending request failed. */ 1_004_000313 );314 expect(tokenDetails).to.deep.equal({315 fid: FID,316 registrationStatus: RequestStatus.IN_PROGRESS,317 // Ignore registrationTime as we already checked it.318 registrationTime: tokenDetails.registrationTime319 });320 expect(registrationPromise).to.be.an.instanceOf(Promise);321 await registrationPromise;322 expect(createInstallationRequestSpy).to.be.calledOnce;323 });324 it('updates the InstallationEntry if the request fails and the app is offline', async () => {325 stub(navigator, 'onLine').value(false);326 clock.restore();327 clock = useFakeTimers({328 now: 1_001_000 /* One second after the request was initiated. */,329 shouldAdvanceTime: true /* Needed to allow the createInstallation request to complete. */330 });331 const installationEntryPromise = getInstallationEntry(appConfig);332 // The pending request fails after a while.333 clock.tick(3000);334 await set(appConfig, {335 fid: FID,336 registrationStatus: RequestStatus.NOT_STARTED337 });338 const { registrationPromise } = await installationEntryPromise;339 // Let the new getInstallationEntry process start.340 await sleep(250);341 expect(await get(appConfig)).to.deep.equal({342 fid: FID,343 registrationStatus: RequestStatus.NOT_STARTED344 });345 expect(registrationPromise).to.be.an.instanceOf(Promise);346 await expect(registrationPromise).to.be.rejectedWith(347 'Application offline'348 );349 expect(createInstallationRequestSpy).not.to.be.called;350 });351 it('returns a new pending InstallationEntry and triggers createInstallation if the request had already timed out', async () => {352 clock.now = 1_015_000; // Fifteen seconds after the request was initiated.353 const { installationEntry } = await getInstallationEntry(appConfig);354 expect(installationEntry).to.deep.equal({355 fid: FID,356 registrationStatus: RequestStatus.IN_PROGRESS,357 registrationTime: 1_015_000358 });359 expect(createInstallationRequestSpy).to.be.calledOnce;360 });361 it('returns a new unregistered InstallationEntry if the request had already timed out and the app is offline', async () => {362 stub(navigator, 'onLine').value(false);363 clock.now = 1_015_000; // Fifteen seconds after the request was initiated.364 const { installationEntry } = await getInstallationEntry(appConfig);365 expect(installationEntry).to.deep.equal({366 fid: FID,367 registrationStatus: RequestStatus.NOT_STARTED368 });369 expect(createInstallationRequestSpy).not.to.be.called;370 });371 });372 describe('when there is a registered InstallationEntry in the database', () => {373 beforeEach(async () => {374 const registeredInstallationEntry: RegisteredInstallationEntry = {375 fid: FID,376 registrationStatus: RequestStatus.COMPLETED,377 refreshToken: 'refreshToken',378 authToken: { requestStatus: RequestStatus.NOT_STARTED }379 };380 await set(appConfig, registeredInstallationEntry);381 });382 it('returns the InstallationEntry from the database', async () => {383 const { installationEntry } = await getInstallationEntry(appConfig);384 expect(installationEntry).to.deep.equal({385 fid: FID,386 registrationStatus: RequestStatus.COMPLETED,387 refreshToken: 'refreshToken',388 authToken: { requestStatus: RequestStatus.NOT_STARTED }389 });390 expect(createInstallationRequestSpy).not.to.be.called;391 });392 });...
update.js
Source:update.js
1/**2 * Méthode qui retourne si l'installation existe3 * @param {*} url l'url de l'isntallation4 * @returns true elle existe, false elle n'exise pas5 */6async function nom_existe(url, type, nom_request, style_request) {7 let reponse = await fetch(url)8 .then((response) => response.json()9 .then(res => ({status: response.status, data: res})))10 .then((apiResponse) => {11 return apiResponse;12 })13 .catch((error) => {14 console.error('Erreur:', error);15 });1617 if (reponse.status == 200) {18 if ((type === 'glissade' && reponse.data.nom != nom_request) || (type === 'patinoire' && reponse.data.nom_pat != nom_request) || (type === 'piscine' && (reponse.data.nom != nom_request || reponse.data.type != style_request))) {19 return true;20 }21 } 22 return false;23}2425/**26 * Méthode qui valide le formulaire27 * @param {*} json_installation JSON contenant les informations du formulaire28 * @param {*} installation type d'installation29 * @returns 30 */31async function validateForm(json_installation, installation, nom_request, style_request) {32 var validated;33 var url;3435 if (installation === 'glissade') {36 var nom = (json_installation.nom != null && json_installation.nom != "" && json_installation.nom.length <= 255)37 if (!nom) {38 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de la glissade")39 }4041 url = '/api/glissade/' + json_installation.nom;42 var reponse = await nom_existe(url, 'glissade', nom_request, style_request);43 if (reponse) {44 alert("Le nom de la glissade existe déjà ")45 }4647 var nom_arr = (json_installation.arrondissement.nom_arr != null && json_installation.arrondissement.nom_arr != "" && json_installation.arrondissement.nom_arr.length <= 255)48 if (!nom_arr) {49 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de l'arrondissement")50 }5152 var cle = (json_installation.arrondissement.cle != null && json_installation.arrondissement.cle != "" && json_installation.arrondissement.cle.length <= 5)53 if (!cle) {54 alert("Vous devez entrer entre 1 et 5 caractères pour la clé de l'arrondissement")55 }5657 var ISO8601 = new RegExp(/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/)58 var date_maj = (ISO8601.test(json_installation.arrondissement.date_maj))59 if (!date_maj) {60 alert("Vous devez entrer une date respectant le format ISO8601, par exemple: 2021-10-18 13:45:13")61 }6263 var ouvert = Number.isInteger(json_installation.ouvert) && (json_installation.ouvert == 0 || json_installation.ouvert == 1)64 if (!ouvert) {65 alert("Votre champ ouvert doit être 0 ou 1 uniquement")66 }6768 var deblaye = Number.isInteger(json_installation.deblaye) && (json_installation.deblaye == 0 || json_installation.deblaye == 1)69 if (!deblaye) {70 alert("Votre champ deblaye doit être 0 ou 1 uniquement")71 }7273 var condition = (json_installation.condition != null && json_installation.condition != "" && json_installation.condition.length <= 255)74 if (!condition) {75 alert("Vous devez entrer entre 1 et 255 caractères pour la condition de la glissade")76 }7778 validated = nom && nom_arr && cle && date_maj && ouvert && deblaye && condition7980 } else if (installation === 'patinoire') {81 var nom_pat = (json_installation.nom_pat != null && json_installation.nom_pat != "" && json_installation.nom_pat.length <= 255)82 if (!nom_pat) {83 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de la patinoire")84 }8586 url = '/api/patinoire/' + json_installation.nom_pat;87 var reponse = await nom_existe(url, 'patinoire', nom_request, style_request);88 if (reponse) {89 alert("Le nom de la patinoire existe déjà ")90 }9192 var nom_arr = (json_installation.nom_arr != null && json_installation.nom_arr != "" && json_installation.nom_arr.length <= 255)93 if (!nom_arr) {94 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de l'arrondissement")95 }9697 validated = nom_pat && nom_arr9899 } else if (installation === 'piscine') {100 var id_uev = Number.isInteger(json_installation.id_uev)101 if (!id_uev) {102 alert("Vous devez entrer un entier valide pour l'id_uev de la piscine")103 }104105 var style = (json_installation.style != null && json_installation.style != "" && json_installation.style.length <= 255)106 if (!style) {107 alert("Vous devez entrer entre 1 et 255 caractères pour le type de la piscine")108 }109110 var nom = (json_installation.nom != null && json_installation.nom != "" && json_installation.nom.length <= 255)111 if (!nom) {112 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de la piscine")113 }114115 url = '/api/piscine/' + json_installation.style + '/' + json_installation.nom;116 var reponse = await nom_existe(url, 'piscine', nom_request, style_request);117 if (reponse) {118 alert("Le nom de la pisicne existe déjà ")119 }120121 var arrondisse = (json_installation.arrondisse != null && json_installation.arrondisse != "" && json_installation.arrondisse.length <= 255)122 if (!arrondisse) {123 alert("Vous devez entrer entre 1 et 255 caractères pour le nom de l'arrondissement")124 }125126 var point_x = Number.isInteger(parseInt(json_installation.point_x))127 if (!point_x) {128 alert('Vous devez entrer un point_x de cette façon-ci: 304846,2071 ou 5039975909, par exemple')129 }130131 var point_y = Number.isInteger(parseInt(json_installation.point_y))132 if (!point_y) {133 alert('Vous devez entrer un point_y de cette façon-ci: 304846,2071 ou 5039975909, par exemple')134 }135136 var longitude_latitude = new RegExp(/^-?\d{2}\.\d{0,6}$/)137 var longitude = (longitude_latitude.test(json_installation.longitude))138 if (!longitude) {139 alert("Vous devez entrer une valeur valide, par exemple: -73.49941 ou 45.640521")140 }141142 var latitude = (longitude_latitude.test(json_installation.latitude))143 if (!latitude) {144 alert("Vous devez entrer une valeur valide, par exemple: -73.49941 ou 45.640521")145 }146147 validated = id_uev && style && nom && arrondisse && point_x && point_y && longitude && latitude148 }149150 return validated;151}152153154let formulaire = document.querySelector("form");155formulaire.id = "recherche";156157/**158 * Handler pour l'envoit du formulaire159 * @param {SubmitEvent} event160 */161document.getElementById("recherche").addEventListener("submit", async function(event) {162 var url_fetch = url163 var json_installation = new Object();164165 if (installation === 'glissade') {166 var arrondissement = new Object();167 json_installation.nom = document.getElementById("nom").value;168 arrondissement.nom_arr = document.getElementById("nom_arr").value169 arrondissement.cle = document.getElementById("cle").value;170 arrondissement.date_maj = document.getElementById("date_maj").value;171 json_installation.arrondissement = arrondissement;172 json_installation.ouvert = parseInt(document.getElementById("ouvert").value);173 json_installation.deblaye = parseInt(document.getElementById("deblaye").value);174 json_installation.condition = document.getElementById("condition").value;175176 url = url + document.getElementById("nom").value177 url_fetch = url_fetch + nom_request178 } else if (installation === 'patinoire') {179 json_installation.nom_pat = document.getElementById("nom_pat").value;180 json_installation.nom_arr = document.getElementById("nom_arr").value;181182 url = url + document.getElementById("nom_pat").value183 url_fetch = url_fetch + nom_request184 } else if (installation === 'piscine') {185 json_installation.id_uev = parseInt(document.getElementById("id_uev").value);186 json_installation.style = document.getElementById("style").value;187 json_installation.nom = document.getElementById("nom").value;188 json_installation.arrondisse = document.getElementById("arrondisse").value;189 json_installation.adresse = document.getElementById("adresse").value;190 json_installation.propriete = document.getElementById("propriete").value;191 json_installation.gestion = document.getElementById("gestion").value;192 json_installation.point_x = document.getElementById("point_x").value;193 json_installation.point_y = document.getElementById("point_y").value;194 json_installation.equipeme = document.getElementById("equipeme").value;195 json_installation.longitude = parseFloat(document.getElementById("longitude").value);196 json_installation.latitude = parseFloat(document.getElementById("latitude").value);197198 url = url + document.getElementById("style").value + '/' + document.getElementById("nom").value199 url_fetch = url_fetch + style_request + '/' + nom_request200 }201 event.preventDefault()202 var validated = await validateForm(json_installation, installation, nom_request, style_request);203204 if (validated) {205 await fetch(url_fetch, {206 method:'PUT',207 headers: { "Content-Type": "application/json" },208 body: JSON.stringify(json_installation, installation)209 })210 .then(response => {211 alert("L'installation a été modifiée avec succès")212 window.location.replace('/')213 })214 }
...
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyInstallation = require('argosy-installation')4var argosyService = require('argosy-service')5var argosyConsole = require('argosy-console')6var argosyWeb = require('argosy-web')7var service = argosy()8service.pipe(argosyInstallation()).pipe(service)9service.accept({10}).process(function (msg, respond) {11 respond(null, {12 })13})14service.pipe(argosyConsole()).pipe(process.stdout)15service.pipe(argosyWeb()).listen(3000)16var argosyInstallation = require('argosy-installation')17### Installation#(options)18var installation = argosyInstallation({19})20### Installation#(options, manifest)21var installation = argosyInstallation({22}, [23 {24 }25### Installation#(manifest)26var installation = argosyInstallation([27 {28 }29### Installation#pipe(stream)30var installation = argosyInstallation()31installation.pipe(service)32### Installation#accept(pattern, options)33var installation = argosyInstallation()34installation.accept({35})36### Installation#process(pattern, handler)37var installation = argosyInstallation()38installation.process({39}, function (msg, respond) {40 respond(null, {41 })42})43### Installation#unaccept(pattern)44var installation = argosyInstallation()45installation.unaccept({46})47### Installation#unprocess(pattern)48var installation = argosyInstallation()49installation.unprocess({
Using AI Code Generation
1var argosy = require('argosy')2var argosyService = require('argosy-service')3var argosyService = require('argosy-service')4var argosy = require('argosy')5var service = argosyService({6 service: {7 hello: function (name, cb) {8 cb(null, 'hello ' + name)9 }10 }11})12var bus = argosy()13bus.pipe(service).pipe(bus)14service.on('ready', function () {15 console.log('service is ready')16})17var argosy = require('argosy')18var argosyService = require('argosy-service')19var bus = argosy()20bus.pipe(argosyService({21 service: {22 hello: function (name, cb) {23 cb(null, 'hello ' + name)24 }25 }26})).pipe(bus)27bus.on('ready', function () {28 bus({ hello: 'world' }, function (err, response) {29 console.log(response)30 })31})32var argosy = require('argosy')33var argosyService = require('argosy-service')34var argosyService = require('argosy-service')35var argosy = require('argosy')36var service = argosyService({37 service: {38 hello: function (name, cb) {39 cb(null, 'hello ' + name)40 }41 }42})43var bus = argosy()44bus.pipe(service).pipe(bus)45service.on('ready', function () {46 console.log('service is ready')47})48var argosy = require('argosy')49var argosyService = require('argosy-service')50var bus = argosy()51bus.pipe(argosyService({52 service: {53 hello: function (name, cb) {54 cb(null, 'hello ' + name)55 }56 }57})).pipe(bus)58bus.on('ready', function () {59 bus({ hello: 'world' }, function (err, response) {60 console.log(response)61 })62})
Using AI Code Generation
1var argosy = require('argosy')2var service = argosy()3service.accept({role: 'math', cmd: 'sum'}, function (msg, cb) {4 cb(null, {answer: msg.left + msg.right})5})6service.on('error', function (err) {7 console.log(err)8})9service.listen(function (err, port) {10 if (err) {11 console.log(err)12 } else {13 console.log('listening on port ' + port)14 }15})16var argosy = require('argosy')17var service = argosy()18service.accept({role: 'math', cmd: 'sum'}, function (msg, cb) {19 cb(null, {answer: msg.left + msg.right})20})21service.on('error', function (err) {22 console.log(err)23})24service.connect(function (err, port) {25 if (err) {26 console.log(err)27 } else {28 console.log('connected on port ' + port)29 }30})31var argosy = require('argosy')32var service = argosy()33service.accept({role: 'math', cmd: 'sum'}, function (msg, cb) {34 cb(null, {answer: msg.left + msg.right})35})36service.on('error', function (err) {37 console.log(err)38})39service.connect(8000, function (err, port) {40 if (err) {41 console.log(err)42 } else {43 console.log('connected on port ' + port)44 }45})46var argosy = require('argosy')47var service = argosy()48service.accept({role: 'math', cmd: 'sum'}, function (msg, cb) {49 cb(null, {answer: msg.left + msg.right})50})51service.on('error', function (err) {52 console.log(err)53})54 if (err) {55 console.log(err)56 } else {57 console.log('connected on port ' + port)58 }59})
Using AI Code Generation
1var argosy = require('argosy')2var argosyService = require('argosy-service')3var argosyPattern = require('argosy-pattern')4var argosyServiceInstallation = require('argosy-service-installation')5var argosyServiceInstallationPattern = require('argosy-service-installation-pattern')6var argosyServiceInstallationService = require('argosy-service-installation-service')7var argosyServiceInstallationClient = require('argosy-service-installation-client')8var argosyServiceInstallationClientPattern = require('argosy-service-installation-client-pattern')9var argosy = require('argosy')10var argosyService = require('argosy-service')11var argosyPattern = require('argosy-pattern')12var argosyServiceInstallation = require('argosy-service-installation')13var argosyServiceInstallationPattern = require('argosy-service-installation-pattern')14var argosyServiceInstallationService = require('argosy-service-installation-service')15var argosyServiceInstallationClient = require('argosy-service-installation-client')16var argosyServiceInstallationClientPattern = require('argosy-service-installation-client-pattern')17var argosy = require('argosy')18var argosyService = require('argosy-service')19var argosyPattern = require('argosy-pattern')20var argosyServiceInstallation = require('argosy-service-installation')21var argosyServiceInstallationPattern = require('argosy-service-installation-pattern')22var argosyServiceInstallationService = require('argosy-service-installation-service')23var argosyServiceInstallationClient = require('argosy-service-installation-client')24var argosyServiceInstallationClientPattern = require('argosy-service-installation-client-pattern')25var argosy = require('argosy')26var argosyService = require('argosy-service')27var argosyPattern = require('argosy-pattern')28var argosyServiceInstallation = require('argosy-service-installation')29var argosyServiceInstallationPattern = require('argosy-service-installation-pattern')
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyP = argosyPattern(argosy())4var argosy = require('argosy')5var argosyPattern = require('argosy-pattern')6var argosyP = argosyPattern(argosy())7var argosy = require('argosy')8var argosyPattern = require('argosy-pattern')9var argosyP = argosyPattern(argosy())10var argosy = require('argosy')11var argosyPattern = require('argosy-pattern')12var argosyP = argosyPattern(argosy())13var argosy = require('argosy')14var argosyPattern = require('argosy-pattern')15var argosyP = argosyPattern(argosy())16var argosy = require('argosy')17var argosyPattern = require('argosy-pattern')18var argosyP = argosyPattern(argosy())19var argosy = require('argosy')20var argosyPattern = require('argosy-pattern')21var argosyP = argosyPattern(argosy())22var argosy = require('argosy')23var argosyPattern = require('argosy-pattern')24var argosyP = argosyPattern(argosy())25var argosy = require('argosy')26var argosyPattern = require('argosy-pattern')27var argosyP = argosyPattern(argosy())28var argosy = require('argosy')29var argosyPattern = require('argosy-pattern')30var argosyP = argosyPattern(argosy())
Using AI Code Generation
1var argos = require('argos');2argos.install('test', function(err) {3 if (err) {4 console.log('error installing argos');5 console.log(err);6 } else {7 console.log('argos installed');8 }9});
Using AI Code Generation
1var argos = require('argos');2argos.install('org.example.myapp', '1.0', function(err, app) {3 app.launch();4});5var argos = require('argos');6argos.launch('org.example.myapp', function(err, app) {7 app.launch();8});9var argos = require('argos');10argos.uninstall('org.example.myapp', function(err, app) {11});12var argos = require('argos');13argos.list(function(err, apps) {14});15var argos = require('argos');16argos.find('org.example.myapp', function(err, app) {17 app.launch();18});19var argos = require('argos');20argos.isInstalled('org.example.myapp', function(err, installed) {21});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!