How to use onSuccess method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

factories.js

Source:factories.js Github

copy

Full Screen

...22 this.latest = function ($scope, onSuccess, onFail) {23 $scope.busyModeOn();24 $http.get($scope.SYNERGY.server.buildURL("specifications", {"mode": "latest", limit: 10}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {25 $timeout(function () {26 onSuccess(result);27 }, 0);28 }).error(function (data, status, headers, config) {29 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);30 $timeout(function () {31 onFail(data, status);32 }, 100);33 });34 };35 /**36 * Loads all specifications for given version37 * @param {type} $scope38 * @param {String} version39 * @param {Function} onSuccess40 * @param {Function} onFail41 * @returns {undefined}42 */43 this.get = function ($scope, version, onSuccess, onFail) {44 version = (version.length > 0) ? {"version": version} : {};45 $scope.busyModeOn();46 $http.get($scope.SYNERGY.server.buildURL("specifications", version), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {47 $timeout(function () {48 onSuccess(result);49 }, 0);50 }).error(function (data, status, headers, config) {51 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);52 $timeout(function () {53 onFail(data, status);54 }, 100);55 });56 };57 /**58 * Loads specifications matching given filter59 * @param {type} $scope60 * @param {String} filter61 * @param {Function} onSuccess62 * @param {Function} onFail63 * @returns {undefined}64 */65 this.filter = function ($scope, filter, onSuccess, onFail) {66 $scope.busyModeOn();67 $http.get($scope.SYNERGY.server.buildURL("specifications", {"query": filter, "mode": "filter"}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {68 $timeout(function () {69 onSuccess(result);70 }, 0);71 }).error(function (data, status, headers, config) {72 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);73 $timeout(function () {74 onFail(data, status);75 }, 100);76 });77 };78 }79 return new SpecificationsFct($http, $timeout);80 }]).factory("versionsHttp", ["$http", "$timeout", function ($http, $timeout) {81 function VersionsFct($http, $timeout) {82 /**83 * Retrieves list of versions (visible ones)84 * @param {Function} onSuccess85 * @param {Function} onFail86 */87 this.get = function ($scope, useCache, onSuccess, onFail) {88 $scope.busyModeOn();89 $http.get($scope.SYNERGY.server.buildURL("versions", {}), {"cache": useCache, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {90 $timeout(function () {91 onSuccess(result);92 }, 0);93 }).error(function (data, status, headers, config) {94 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);95 $timeout(function () {96 onFail(data, status);97 }, 100);98 });99 };100 /**101 * Retrieves all versions, even inactive ones102 */103 this.getAll = function ($scope, onSuccess, onFail) {104 $scope.busyModeOn();105 $http.get($scope.SYNERGY.server.buildURL("versions", {"all": 1}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {106 $timeout(function () {107 onSuccess(result);108 }, 0);109 }).error(function (data, status, headers, config) {110 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);111 $timeout(function () {112 onFail(data, status);113 }, 100);114 });115 };116 }117 return new VersionsFct($http, $timeout);118 }]).factory("specificationLengthHttp", ["$http", "$timeout", function ($http, $timeout) {119 function SpecificationLengthHttp($http, $timeout) {120 /**121 * Returns number of test cases of given specifications122 * @param {Object} query object with array property called "ids" and array contains spec IDs123 * @param {Function} onSuccess124 * @param {Function} onFail125 */126 this.get = function ($scope, query, onSuccess, onFail) {127 window.document.body.style.cursor = "wait";128 $scope.busyModeOn();129 $http.post($scope.SYNERGY.server.buildURL("versionLength", {}), JSON.stringify(query)).success(function (result) {130 $timeout(function () {131 onSuccess(result);132 }, 0);133 }).error(function (data, status, headers, config) {134 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);135 $timeout(function () {136 onFail(data, status);137 }, 100);138 });139 };140 }141 return new SpecificationLengthHttp($http, $timeout);142 }]).factory("versionHttp", ["$http", "$timeout", function ($http, $timeout) {143 function VersionFct($http, $timeout) {144 /**145 * Updates version146 * @param {type} $scope147 * @param {Synergy.model.Version} version object with 2 properties: id and name148 * @param {Function} onSuccess149 * @param {Function} onFail150 */151 this.edit = function ($scope, version, onSuccess, onFail) {152 window.document.body.style.cursor = "wait";153 $scope.busyModeOn();154 $http.put($scope.SYNERGY.server.buildURL("version", {}), JSON.stringify(version)).success(function (result) {155 $timeout(function () {156 onSuccess(result);157 }, 0);158 }).error(function (data, status, headers, config) {159 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);160 $timeout(function () {161 onFail(data, status);162 }, 100);163 });164 };165 /**166 * Removes version167 * @param {type} $scope168 * @param {Number} versionId version ID169 * @param {Function} onSuccess170 * @param {Function} onFail171 */172 this.remove = function ($scope, versionId, onSuccess, onFail) {173 window.document.body.style.cursor = "wait";174 $scope.busyModeOn();175 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("version", {"id": versionId})}).success(function (result) {176 $timeout(function () {177 onSuccess(result);178 }, 0);179 }).error(function (data, status, headers, config) {180 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);181 $timeout(function () {182 onFail(data, status);183 }, 100);184 });185 };186 /**187 * Creates version188 * @param {type} $scope189 * @param {Synergy.model.Version} version new version to be created with property "name"190 * @param {Function} onSuccess191 * @param {Function} onFail192 */193 this.create = function ($scope, version, onSuccess, onFail) {194 window.document.body.style.cursor = "wait";195 $scope.busyModeOn();196 $http.post($scope.SYNERGY.server.buildURL("version", {}), JSON.stringify(version)).success(function (result) {197 $timeout(function () {198 onSuccess(result);199 }, 0);200 }).error(function (data, status, headers, config) {201 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);202 $timeout(function () {203 onFail(data, status);204 }, 100);205 });206 };207 }208 return new VersionFct($http, $timeout);209 }]).factory("userHttp", ["$http", "$timeout", function ($http, $timeout) {210 function UserFct($http, $timeout) {211 /**212 * Updates user213 * @param {type} $scope214 * @param {Synergy.model.User} user215 * @param {Function} onSuccess216 * @param {Function} onFail217 */218 this.edit = function ($scope, user, onSuccess, onFail) {219 window.document.body.style.cursor = "wait";220 $scope.busyModeOn();221 $http.put($scope.SYNERGY.server.buildURL("user", {"action": "editUser"}), JSON.stringify(user)).success(function (result) {222 $timeout(function () {223 onSuccess(result);224 }, 0);225 }).error(function (data, status, headers, config) {226 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);227 $timeout(function () {228 onFail(data, status);229 }, 100);230 });231 };232 /**233 * Retrieves user234 * @param {String} username user"s username235 * @param {Function} onSuccess236 * @param {Function} onFail237 */238 this.get = function ($scope, username, onSuccess, onFail) {239 $scope.busyModeOn();240 $http.get($scope.SYNERGY.server.buildURL("user", {"user": username}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {241 $timeout(function () {242 onSuccess(result);243 }, 0);244 }).error(function (data, status, headers, config) {245 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);246 $timeout(function () {247 onFail(data, status);248 }, 100);249 });250 };251 /**252 * Creates user253 * @param {type} $scope254 * @param {Synergy.model.User} user user255 * @param {Function} onSuccess256 * @param {Function} onFail257 */258 this.create = function ($scope, user, onSuccess, onFail) {259 window.document.body.style.cursor = "wait";260 $scope.busyModeOn();261 $http.post($scope.SYNERGY.server.buildURL("user", {}), JSON.stringify(user)).success(function (result) {262 $timeout(function () {263 onSuccess(result);264 }, 0);265 }).error(function (data, status, headers, config) {266 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);267 $timeout(function () {268 onFail(data, status);269 }, 100);270 });271 };272 /**273 * Toggles state of user"s favorite specification274 * @param {type} $scope275 * @param {Synergy.model.Specification} specification276 * @param {Function} onSuccess277 * @param {Function} onFail278 */279 this.toggleFavorite = function ($scope, specification, onSuccess, onFail) {280 window.document.body.style.cursor = "wait";281 $scope.busyModeOn();282 $http.put($scope.SYNERGY.server.buildURL("user", {"action": "toggleFavorite"}), JSON.stringify(specification)).success(function (result) {283 $timeout(function () {284 onSuccess(result);285 }, 0);286 }).error(function (data, status, headers, config) {287 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);288 $timeout(function () {289 onFail(data, status);290 }, 100);291 });292 };293 /**294 * Removes user295 * @param {type} $scope296 * @param {String} username297 * @param {Function} onSuccess298 * @param {Function} onFail299 */300 this.remove = function ($scope, username, onSuccess, onFail) {301 window.document.body.style.cursor = "wait";302 $scope.busyModeOn();303 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("user", {"username": username})}).success(function (result) {304 $timeout(function () {305 onSuccess(result);306 }, 0);307 }).error(function (data, status, headers, config) {308 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);309 $timeout(function () {310 onFail(data, status);311 }, 100);312 });313 };314 this.resetProfileImg = function ($scope, userId, onSuccess, onFail) {315 window.document.body.style.cursor = "wait";316 $scope.busyModeOn();317 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("profile_img", {"id": userId})}).success(function (result) {318 $timeout(function () {319 onSuccess(result);320 }, 0);321 }).error(function (data, status, headers, config) {322 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);323 $timeout(function () {324 onFail(data, status);325 }, 100);326 });327 };328 }329 return new UserFct($http, $timeout);330 }]).factory("specificationHttp", ["$http", "$timeout", function ($http, $timeout) {331 function SpecificationFct($http, $timeout) {332 /**333 * Deletes specification334 * @param {type} $scope335 * @param {Number} specificationId specification id336 * @param {Function} onSuccess337 * @param {Function} onFail338 * @returns {undefined}339 */340 this.remove = function ($scope, specificationId, onSuccess, onFail) {341 window.document.body.style.cursor = "wait";342 $scope.busyModeOn();343 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("specification", {"id": specificationId})}).success(function (result, status) {344 $timeout(function () {345 onSuccess(result, status);346 }, 0);347 }).error(function (data, status, headers, config) {348 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);349 $timeout(function () {350 onFail(data, status);351 }, 100);352 });353 };354 /**355 * Sends request for onwership to server356 * @param {type} $scope357 * @param {Synergy.model.OwnershipRequest} request358 * @param {type} onSuccess359 * @param {type} onFail360 * @returns {undefined}361 */362 this.requestOwnership = function ($scope, request, onSuccess, onFail) {363 window.document.body.style.cursor = "wait";364 $scope.busyModeOn();365 $http.post($scope.SYNERGY.server.buildURL("specification_request", {}), JSON.stringify(request)).success(function (result) {366 $timeout(function () {367 onSuccess(result);368 }, 0);369 }).error(function (data, status, headers, config) {370 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);371 $timeout(function () {372 onFail(data, status);373 }, 100);374 });375 };376 /**377 * Updates specification378 * @param {type} $scope379 * @param {Synergy.model.Specification} specification380 * @param {Function} onSuccess381 * @param {Function} onFail382 * @returns {undefined}383 */384 this.edit = function ($scope, specification, isMinorEdit, keepSimpleNameTrack, onSuccess, onFail) {385 window.document.body.style.cursor = "wait";386 $scope.busyModeOn();387 $http.put($scope.SYNERGY.server.buildURL("specification", {"id": specification.id, "minorEdit": isMinorEdit, "keepSimpleName": keepSimpleNameTrack}), JSON.stringify(specification)).success(function (result) {388 $timeout(function () {389 onSuccess(result);390 }, 0);391 }).error(function (data, status, headers, config) {392 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);393 $timeout(function () {394 onFail(data, status);395 }, 100);396 });397 };398 /**399 * Creates specification400 * @param {type} $scope401 * @param {Synergy.model.Specification} specification402 * @param {Function} onSuccess403 * @param {Function} onFail404 * @returns {undefined}405 */406 this.create = function ($scope, specification, onSuccess, onFail) {407 window.document.body.style.cursor = "wait";408 $scope.busyModeOn();409 $http.post($scope.SYNERGY.server.buildURL("specification", {"mode": "create"}), JSON.stringify(specification)).success(function (result) {410 $timeout(function () {411 onSuccess(result);412 }, 0);413 }).error(function (data, status, headers, config) {414 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);415 $timeout(function () {416 onFail(data, status);417 }, 100);418 });419 };420 /**421 * Returns full specification (for continuous view 2)422 * @param {type} $scope423 * @param {Number} specificationId specification id424 * @param {Function} onSuccess425 * @param {Function} onFail426 * @returns {undefined}427 */428 this.getFull = function ($scope, useCache, specificationId, onSuccess, onFail) {429 $scope.busyModeOn();430 $http.get($scope.SYNERGY.server.buildURL("specification", {"view": "cont", "id": specificationId}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {431 $timeout(function () {432 onSuccess(result);433 }, 0);434 }).error(function (data, status, headers, config) {435 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);436 $timeout(function () {437 onFail(data, status);438 }, 100);439 });440 };441 /**442 * Returns full specification based on simple name and version443 */444 this.getFullAlias = function ($scope, useCache, simpleName, simpleVersion, onSuccess, onFail) {445 $scope.busyModeOn();446 $http.get($scope.SYNERGY.server.buildURL("specification", {"view": "contAlias", "id": -1, "simpleName": simpleName, "simpleVersion": simpleVersion}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {447 $timeout(function () {448 onSuccess(result);449 }, 0);450 }).error(function (data, status, headers, config) {451 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);452 $timeout(function () {453 onFail(data, status);454 }, 100);455 });456 };457 /**458 * Returns basic specification info (for view 1)459 * @param {type} $scope460 * @param {Number} specificationId specification id461 * @param {Function} onSuccess462 * @param {Function} onFail463 * @returns {undefined}464 */465 this.get = function ($scope, useCache, specificationId, onSuccess, onFail) {466 $scope.busyModeOn();467 $http.get($scope.SYNERGY.server.buildURL("specification", {"id": specificationId}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {468 $timeout(function () {469 onSuccess(result);470 }, 0);471 }).error(function (data, status, headers, config) {472 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);473 $timeout(function () {474 onFail(data, status);475 }, 100);476 });477 };478 /**479 * Clones specification480 * @param {type} $scope481 * @param {Number} specificationId specification id482 * @param {String} newName name of new cloned specification483 * @param {String} clonedVersion version to be cloned of (target version)484 * @param {Function} onSuccess485 * @param {Function} onFail486 * @returns {undefined}487 */488 this.clone = function ($scope, specificationId, newName, clonedVersion, onSuccess, onFail) {489 window.document.body.style.cursor = "wait";490 var spec = {491 "newName": newName,492 "version": clonedVersion493 };494 $scope.busyModeOn();495 $http.post($scope.SYNERGY.server.buildURL("specification", {"mode": "clone", "id": specificationId}), JSON.stringify(spec)).success(function (result) {496 $timeout(function () {497 onSuccess(result);498 }, 0);499 }).error(function (data, status, headers, config) {500 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);501 $timeout(function () {502 onFail(data, status);503 }, 100);504 });505 };506 }507 return new SpecificationFct($http, $timeout);508 }]).factory("suiteHttp", ["$http", "$timeout", function ($http, $timeout) {509 function SuiteFct($http, $timeout) {510 /**511 * Deletes suites512 * @param {type} $scope513 * @param {Number} suiteId suite id514 * @param {Function} onSuccess515 * @param {Function} onFail516 * @returns {undefined}517 */518 this.remove = function ($scope, suiteId, onSuccess, onFail) {519 window.document.body.style.cursor = "wait";520 $scope.busyModeOn();521 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("suite", {"id": suiteId})}).success(function (result) {522 $timeout(function () {523 onSuccess(result);524 }, 0);525 }).error(function (data, status, headers, config) {526 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);527 $timeout(function () {528 onFail(data, status);529 }, 100);530 });531 };532 /**533 * Returns suite534 * @param {type} $scope535 * @param {Number} suiteId suite id536 * @param {Function} onSuccess537 * @param {Function} onFail538 * @returns {undefined}539 */540 this.get = function ($scope, useCache, suiteId, onSuccess, onFail) {541 $scope.busyModeOn();542 $http.get($scope.SYNERGY.server.buildURL("suite", {"id": suiteId}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {543 $timeout(function () {544 onSuccess(result);545 }, 0);546 }).error(function (data, status, headers, config) {547 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);548 $timeout(function () {549 onFail(data, status);550 }, 100);551 });552 };553 /**554 * Removes given case from suite555 * @param {type} $scope556 * @param {Number} suiteId suiteID to be affected557 * @param {Number} caseId caseID to be removed from suite558 * @param {Function} onSuccess559 * @param {Function} onFail560 * @returns {undefined}561 */562 this.removeCase = function ($scope, suiteId, caseId, onSuccess, onFail) {563 window.document.body.style.cursor = "wait";564 $scope.busyModeOn();565 $http.put($scope.SYNERGY.server.buildURL("suite", {"id": suiteId, "caseId": caseId, "action": "deleteCase"})).success(function (result) {566 $timeout(function () {567 onSuccess(result);568 }, 0);569 }).error(function (data, status, headers, config) {570 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);571 $timeout(function () {572 onFail(data, status);573 }, 100);574 });575 };576 /**577 * Adds given case from suite578 * @param {type} $scope579 * @param {Number} suiteId suiteID to be affected580 * @param {Number} caseId caseID to be added to suite581 * @param {Function} onSuccess582 * @param {Function} onFail583 * @returns {undefined}584 */585 this.addCase = function ($scope, suiteId, caseId, onSuccess, onFail) {586 window.document.body.style.cursor = "wait";587 $scope.busyModeOn();588 $http.put($scope.SYNERGY.server.buildURL("suite", {"id": suiteId, "caseId": caseId, "action": "addCase"})).success(function (result) {589 $timeout(function () {590 onSuccess(result);591 }, 0);592 }).error(function (data, status, headers, config) {593 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);594 $timeout(function () {595 onFail(data, status);596 }, 100);597 });598 };599 /**600 * Updates suite601 * @param {type} $scope602 * @param {Synergy.model.Suite} suite603 * @param {Function} onSuccess604 * @param {Function} onFail605 * @returns {undefined}606 */607 this.edit = function ($scope, suite, isMinorEdit, onSuccess, onFail) {608 window.document.body.style.cursor = "wait";609 $scope.busyModeOn();610 $http.put($scope.SYNERGY.server.buildURL("suite", {"id": suite.id, "minorEdit": isMinorEdit}), JSON.stringify(suite)).success(function (result) {611 $timeout(function () {612 onSuccess(result);613 }, 0);614 }).error(function (data, status, headers, config) {615 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);616 $timeout(function () {617 onFail(data, status);618 }, 100);619 });620 };621 /**622 * Creates suite623 * @param {type} $scope624 * @param {Synergy.model.Suite} suite625 * @param {Function} onSuccess626 * @param {Function} onFail627 * @returns {undefined}628 */629 this.create = function ($scope, suite, onSuccess, onFail) {630 window.document.body.style.cursor = "wait";631 $scope.busyModeOn();632 $http.post($scope.SYNERGY.server.buildURL("suite", {"id": suite.id}), JSON.stringify(suite)).success(function (result) {633 $timeout(function () {634 onSuccess(result);635 }, 0);636 }).error(function (data, status, headers, config) {637 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);638 $timeout(function () {639 onFail(data, status);640 }, 100);641 });642 };643 }644 return new SuiteFct($http, $timeout);645 }]).factory("casesHttp", ["$http", "$timeout", function ($http, $timeout) {646 function CasesFct($http, $timeout) {647 /**648 * Returns cases with titles matching to given parameter649 * @param {type} $scope650 * @param {String} filter 651 * @param {Function} onSuccess652 * @param {Function} onFail653 * @returns {undefined}654 */655 this.getMatching = function ($scope, filter, onSuccess, onFail) {656 $scope.busyModeOn();657 $http.get($scope.SYNERGY.server.buildURL("cases", {"case": filter}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {658 $timeout(function () {659 onSuccess(result);660 }, 0);661 }).error(function (data, status, headers, config) {662 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);663 $timeout(function () {664 onFail(data, status);665 }, 100);666 });667 };668 }669 return new CasesFct($http, $timeout);670 }]).factory("caseHttp", ["$http", "$timeout", function ($http, $timeout) {671 function CaseFct($http, $timeout) {672 /**673 * Returns case in context of given suite674 * @param {type} $scope675 * @param {Number} caseId676 * @param {Number} suiteId677 * @param {Function} onSuccess678 * @param {Function} onFail679 * @returns {undefined}680 */681 this.get = function ($scope, useCache, caseId, suiteId, onSuccess, onFail) {682 $scope.busyModeOn();683 $http.get($scope.SYNERGY.server.buildURL("case", {"id": caseId, "suite": suiteId}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {684 $timeout(function () {685 onSuccess(result);686 }, 0);687 }).error(function (data, status, headers, config) {688 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);689 $timeout(function () {690 onFail(data, status);691 }, 100);692 });693 };694 /**695 * Creates case696 * @param {type} $scope697 * @param {Synergy.model.TestCase} testCase698 * @param {Function} onSuccess699 * @param {Function} onFail700 * @returns {undefined}701 */702 this.create = function ($scope, testCase, onSuccess, onFail) {703 window.document.body.style.cursor = "wait";704 $scope.busyModeOn();705 $http.post($scope.SYNERGY.server.buildURL("case", {}), JSON.stringify(testCase)).success(function (result) {706 $timeout(function () {707 onSuccess(result);708 }, 0);709 }).error(function (data, status, headers, config) {710 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);711 $timeout(function () {712 onFail(data, status);713 }, 100);714 });715 };716 /**717 * Updates case718 * @param {type} $scope719 * @param {Number} mode if 0, this test case will be cloned and modifications will be applied only to this suite, if 1 all suites will be affected720 * @param {Synergy.model.TestCase} testCase721 * @param {Function} onSuccess722 * @param {Function} onFail723 * @returns {undefined}724 */725 this.edit = function ($scope, mode, testCase, isMinorEdit, onSuccess, onFail) {726 window.document.body.style.cursor = "wait";727 $scope.busyModeOn();728 $http.put($scope.SYNERGY.server.buildURL("case", {"id": testCase.id, "action": "editCase", "mode": mode, "minorEdit": isMinorEdit}), JSON.stringify(testCase)).success(function (result) {729 $timeout(function () {730 onSuccess(result);731 }, 0);732 }).error(function (data, status, headers, config) {733 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);734 $timeout(function () {735 onFail(data, status);736 }, 100);737 });738 };739 }740 return new CaseFct($http, $timeout);741 }]).factory("runsHttp", ["$http", "$timeout", function ($http, $timeout) {742 function RunsFct($http, $timeout) {743 /**744 * Returns latest test runs745 * @param {type} $scope746 * @param {Number} limit number of runs to be returned747 * @param {Function} onSuccess748 * @param {Function} onFail749 * @returns {undefined}750 */751 this.getLatest = function ($scope, limit, onSuccess, onFail) {752 $scope.busyModeOn();753 $http.get($scope.SYNERGY.server.buildURL("runs", {"mode": "latest", "limit": limit}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {754 $timeout(function () {755 onSuccess(result);756 }, 0);757 }).error(function (data, status, headers, config) {758 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);759 window.console.log("____" + typeof onFail);760 $timeout(function () {761 onFail(data, status);762 }, 100);763 });764 };765 /**766 * Returns paginated test runs767 * @param {type} $scope768 * @param {Number} page page number (first page is 1)769 * @param {Function} onSuccess770 * @param {Function} onFail771 * @returns {undefined}772 */773 this.get = function ($scope, page, onSuccess, onFail, cache) {774 cache = (typeof cache === "undefined") ? false : cache;775 $scope.busyModeOn();776 $http.get($scope.SYNERGY.server.buildURL("runs", {"page": page}), {"timeout": $scope.SYNERGY.httpTimeout, "cache": cache}).success(function (result) {777 $timeout(function () {778 onSuccess(result);779 }, 0);780 }).error(function (data, status, headers, config) {781 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);782 $timeout(function () {783 onFail(data, status);784 }, 100);785 });786 };787 }788 return new RunsFct($http, $timeout);789 }]).factory("runHttp", ["$http", "$timeout", function ($http, $timeout) {790 function RunFct($http, $timeout) {791 /**792 * Returns test run (full info)793 * @param {type} $scope794 * @param {Number} runId test run ID795 * @param {Function} onSuccess796 * @param {Function} onFail797 * @returns {undefined}798 */799 this.get = function ($scope, runId, onSuccess, onFail) {800 this._get($scope, runId, onSuccess, onFail, "full");801 };802 this._get = function ($scope, runId, onSuccess, onFail, mode) {803 $scope.busyModeOn();804 $http.get($scope.SYNERGY.server.buildURL("run", {"id": runId, "mode": mode}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {805 $timeout(function () {806 onSuccess(result);807 }, 0);808 }).error(function (data, status, headers, config) {809 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);810 $timeout(function () {811 onFail(data, status);812 }, 100);813 });814 };815 this.getBlobs = function ($scope, runId, onSuccess, onFail) {816 this._get($scope, runId, onSuccess, onFail, "blob");817 };818 /**819 * Returns specifications for given test run 820 * @param {type} $scope821 * @param {Number} runId test run ID822 * @param {Function} onSuccess823 * @param {Function} onFail824 * @returns {undefined}825 */826 this.getSpecifications = function ($scope, runId, onSuccess, onFail) {827 $scope.busyModeOn();828 $http.get($scope.SYNERGY.server.buildURL("run_specifications", {"testRunId": runId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {829 $timeout(function () {830 onSuccess(result);831 }, 0);832 }).error(function (data, status, headers, config) {833 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);834 $timeout(function () {835 onFail(data, status);836 }, 100);837 });838 };839 /**840 * Sends request to send mail notifications to all assignees with incomplete assignment841 */842 this.sendNotifications = function ($scope, runId, onSuccess, onFail) {843 $scope.busyModeOn();844 $http.get($scope.SYNERGY.server.buildURL("run_notifications", {"id": runId, "mode": "full"}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {845 $timeout(function () {846 onSuccess(result);847 }, 0);848 }).error(function (data, status, headers, config) {849 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);850 $timeout(function () {851 onFail(data, status);852 }, 100);853 });854 };855 /**856 * Returns test run like simple get(), but assignments are grouped by specification and user in instances of User instead of TestAssignment857 * @param {type} $scope858 * @param {type} runId859 * @param {type} onSuccess860 * @param {type} onFail861 * @returns {undefined}862 */863 this.getUserCentric = function ($scope, runId, onSuccess, onFail) {864 this._get($scope, runId, onSuccess, onFail, "peruser");865 };866 /**867 * Returns overview of test run (basic info)868 * @param {type} $scope869 * @param {Number} runId test run ID870 * @param {Function} onSuccess871 * @param {Function} onFail872 * @returns {undefined}873 */874 this.getOverview = function ($scope, useCache, runId, onSuccess, onFail) {875 this._get($scope, runId, onSuccess, onFail, "simple");876 };877 /**878 * Deletes test run879 * @param {type} $scope880 * @param {Number} runId test run ID881 * @param {Function} onSuccess882 * @param {Function} onFail883 * @returns {undefined}884 */885 this.remove = function ($scope, runId, onSuccess, onFail) {886 window.document.body.style.cursor = "wait";887 $scope.busyModeOn();888 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("run", {"id": runId})}).success(function (result) {889 $timeout(function () {890 onSuccess(result);891 }, 0);892 }).error(function (data, status, headers, config) {893 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);894 $timeout(function () {895 onFail(data, status);896 }, 100);897 });898 };899 /**900 * Modifies test run901 * @param {type} $scope902 * @param {Synergy.model.TestRun} run test run903 * @param {Function} onSuccess904 * @param {Function} onFail905 * @returns {undefined}906 */907 this.edit = function ($scope, run, onSuccess, onFail) {908 window.document.body.style.cursor = "wait";909 $scope.busyModeOn();910 $http.put($scope.SYNERGY.server.buildURL("run", {"id": run.id}), JSON.stringify(run)).success(function (result) {911 $timeout(function () {912 onSuccess(result);913 }, 0);914 }).error(function (data, status, headers, config) {915 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);916 $timeout(function () {917 onFail(data, status);918 }, 100);919 });920 };921 /**922 * Sends request to toggle on/off test run freeze923 * @param {type} $scope924 * @param {type} runId925 * @param {Number} freeze if 1, run will be frozen, if 0 it will be unfrozen926 * @param {type} onSuccess927 * @param {type} onFail928 * @returns {undefined}929 */930 this.freezeRun = function ($scope, runId, freeze, onSuccess, onFail) {931 window.document.body.style.cursor = "wait";932 $scope.busyModeOn();933 $http.put($scope.SYNERGY.server.buildURL("run", {"id": runId, "mode": "freeze", "freeze": freeze}), JSON.stringify({})).success(function (result) {934 $timeout(function () {935 onSuccess(result);936 }, 0);937 }).error(function (data, status, headers, config) {938 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);939 $timeout(function () {940 onFail(data, status);941 }, 100);942 });943 };944 /**945 * Creates test run946 * @param {type} $scope947 * @param {Synergy.model.TestRun} run test run948 * @param {Function} onSuccess949 * @param {Function} onFail950 * @returns {undefined}951 */952 this.create = function ($scope, run, onSuccess, onFail) {953 window.document.body.style.cursor = "wait";954 $scope.busyModeOn();955 $http.post($scope.SYNERGY.server.buildURL("run", {}), JSON.stringify(run)).success(function (result) {956 $timeout(function () {957 onSuccess(result);958 }, 0);959 }).error(function (data, status, headers, config) {960 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);961 $timeout(function () {962 onFail(data, status);963 }, 100);964 });965 };966 }967 return new RunFct($http, $timeout);968 }]).factory("assignmentHttp", ["$http", "$timeout", function ($http, $timeout) {969 function AssignmentFct($http, $timeout) {970 /**971 * Returns test assignment972 * @param {type} $scope973 * @param {Number} assignmentId assignment ID974 * @param {Function} onSuccess975 * @param {Function} onFail976 * @returns {undefined}977 */978 this.get = function ($scope, assignmentId, onSuccess, onFail) {979 $scope.busyModeOn();980 $http.get($scope.SYNERGY.server.buildURL("assignment", {"id": assignmentId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {981 $timeout(function () {982 onSuccess(result);983 }, 0);984 }).error(function (data, status, headers, config) {985 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);986 $timeout(function () {987 onFail(data, status);988 }, 100);989 });990 };991 /**992 * Checks if similar (same) assignment already exists. Unlike any other method in these factories, this method returns promise (to test different approach)993 * @param {type} $scope994 * @param {Synergy.model.TestAssignment} assignment995 * @returns {Promise} $promise996 */997 this.checkExists = function ($scope, assignment) {998 $scope.busyModeOn();999 return $http.post($scope.SYNERGY.server.buildURL("assignment_exists", {}), JSON.stringify(assignment), {"timeout": $scope.SYNERGY.httpTimeout});1000 };1001 /**1002 * Returns assignment name and its comments1003 */1004 this.getComments = function ($scope, assignmentId, onSuccess, onFail) {1005 $scope.busyModeOn();1006 $http.get($scope.SYNERGY.server.buildURL("assignment_comments", {"id": assignmentId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1007 $timeout(function () {1008 onSuccess(result);1009 }, 0);1010 }).error(function (data, status, headers, config) {1011 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1012 $timeout(function () {1013 onFail(data, status);1014 }, 100);1015 });1016 };1017 /**1018 * Removes test assignment1019 * @param {type} $scope1020 * @param {Number} assignmentId assignment ID1021 * @param {Function} onSuccess1022 * @param {Function} onFail1023 * @returns {undefined}1024 */1025 this.remove = function ($scope, assignmentId, onSuccess, onFail) {1026 window.document.body.style.cursor = "wait";1027 $scope.busyModeOn();1028 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("assignment", {"id": assignmentId})}).success(function (result) {1029 $timeout(function () {1030 onSuccess(result);1031 }, 0);1032 }).error(function (data, status, headers, config) {1033 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1034 $timeout(function () {1035 onFail(data, status);1036 }, 100);1037 });1038 };1039 /**1040 * Removes test assignment with explanation1041 * @param {type} $scope1042 * @param {Number} assignmentId assignment ID1043 * @param {Function} onSuccess1044 * @param {Function} onFail1045 * @returns {undefined}1046 */1047 this.removeByLeader = function ($scope, assignmentId, explanation, onSuccess, onFail) {1048 window.document.body.style.cursor = "wait";1049 $scope.busyModeOn();1050 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("assignment", {"id": assignmentId}), headers: {"Synergy-comment": encodeURIComponent(explanation)}}).success(function (result) {1051 $timeout(function () {1052 onSuccess(result);1053 }, 0);1054 }).error(function (data, status, headers, config) {1055 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1056 $timeout(function () {1057 onFail(data, status);1058 }, 100);1059 });1060 };1061 /**1062 * Starts test assignment1063 * @param {type} $scope1064 * @param {Number} assignmentId assignment ID1065 * @param {Function} onSuccess1066 * @param {Function} onFail1067 * @returns {undefined}1068 */1069 this.start = function ($scope, assignmentId, onSuccess, onFail) {1070 $scope.busyModeOn();1071 $http.get($scope.SYNERGY.server.buildURL("assignment", {"mode": "start", "id": assignmentId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1072 $timeout(function () {1073 onSuccess(result);1074 }, 0);1075 }).error(function (data, status, headers, config) {1076 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1077 $timeout(function () {1078 onFail(data, status);1079 }, 100);1080 });1081 };1082 /**1083 * Loads possible comments1084 * @param {type} $scope1085 * @param {type} onSuccess1086 * @param {type} onFail1087 * @returns {undefined}1088 */1089 this.getCommentTypes = function ($scope, onSuccess, onFail) {1090 $scope.busyModeOn();1091 $http.get($scope.SYNERGY.server.buildURL("comments", {}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1092 $timeout(function () {1093 onSuccess(result);1094 }, 0);1095 }).error(function (data, status, headers, config) {1096 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1097 $timeout(function () {1098 onFail(data, status);1099 }, 100);1100 });1101 };1102 /**1103 * Restarts test assignment1104 * @param {type} $scope1105 * @param {Number} assignmentId assignment ID1106 * @param {Function} onSuccess1107 * @param {Function} onFail1108 * @returns {undefined}1109 */1110 this.restart = function ($scope, assignmentId, onSuccess, onFail) {1111 $scope.busyModeOn();1112 $http.defaults.headers.common["Synergy-Timestamp"] = encodeURIComponent(new Date().toMysqlFormat());1113 $http.get($scope.SYNERGY.server.buildURL("assignment", {"mode": "restart", "id": assignmentId, "datetime": new Date().toMysqlFormat()}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1114 $timeout(function () {1115 onSuccess(result);1116 }, 0);1117 }).error(function (data, status, headers, config) {1118 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1119 $timeout(function () {1120 onFail(data, status);1121 }, 100);1122 });1123 };1124 /**1125 * Alters issues on closed assignment1126 * @param {type} $scope1127 * @param {type} assignmentId1128 * @param {type} data1129 * @param {type} onSuccess1130 * @param {type} onFail1131 * @returns {undefined}1132 */1133 this.alterBugs = function ($scope, assignmentId, data, onSuccess, onFail) {1134 window.document.body.style.cursor = "wait";1135 $scope.busyModeOn();1136 $http.defaults.headers.common["Synergy-Timestamp"] = encodeURIComponent(new Date().toMysqlFormat());1137 $http.put($scope.SYNERGY.server.buildURL("assignment_bugs", {"id": assignmentId, "datetime": new Date().toMysqlFormat()}), JSON.stringify(data)).success(function (result) {1138 $timeout(function () {1139 onSuccess(result);1140 }, 0);1141 }).error(function (data, status, headers, config) {1142 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1143 $timeout(function () {1144 onFail(data, status);1145 }, 100);1146 });1147 };1148 /**1149 * Submits test assignment results1150 * @param {type} $scope1151 * @param {Number} assignmentId assignment ID1152 * @param {Object} results1153 * @param {Function} onSuccess1154 * @param {Function} onFail1155 * @returns {undefined}1156 */1157 this.submitResults = function ($scope, assignmentId, results, onSuccess, onFail) {1158 window.document.body.style.cursor = "wait";1159 $scope.busyModeOn();1160 $http.defaults.headers.common["Synergy-Timestamp"] = encodeURIComponent(new Date().toMysqlFormat());1161 $http.put($scope.SYNERGY.server.buildURL("assignment", {"id": assignmentId, "datetime": new Date().toMysqlFormat()}), JSON.stringify(results)).success(function (result) {1162 $timeout(function () {1163 onSuccess(result);1164 }, 0);1165 }).error(function (data, status, headers, config) {1166 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1167 $timeout(function () {1168 onFail(data, status);1169 }, 100);1170 });1171 };1172 /**1173 * Sends request to resolve given comments1174 * @param {type} $scope1175 * @param {Array} comments array of objects with single property "id"1176 * @param {type} onSuccess1177 * @param {type} onFail1178 * @returns {undefined}1179 */1180 this.resolveComments = function ($scope, comments, onSuccess, onFail) {1181 window.document.body.style.cursor = "wait";1182 $scope.busyModeOn();1183 $http.put($scope.SYNERGY.server.buildURL("assignment_comments", {}), JSON.stringify(comments)).success(function (result) {1184 $timeout(function () {1185 onSuccess(result);1186 }, 0);1187 }).error(function (data, status, headers, config) {1188 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1189 $timeout(function () {1190 onFail(data, status);1191 }, 100);1192 });1193 };1194 /**1195 * Creates test assignment1196 * @param {type} $scope1197 * @param {Synergy.model.TestAssignment} assignment1198 * @param {Function} onSuccess1199 * @param {Function} onFail1200 * @returns {undefined}1201 */1202 this.create = function ($scope, assignment, onSuccess, onFail) {1203 window.document.body.style.cursor = "wait";1204 $scope.busyModeOn();1205 $http.post($scope.SYNERGY.server.buildURL("assignment", {}), JSON.stringify(assignment)).success(function (result) {1206 $timeout(function () {1207 onSuccess(result);1208 }, 0);1209 }).error(function (data, status, headers, config) {1210 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1211 $timeout(function () {1212 onFail(data, status);1213 }, 100);1214 });1215 };1216 /**1217 * Creates a volunteerr test assignment1218 * @param {type} $scope1219 * @param {Synergy.model.TestAssignment} assignment1220 * @param {Function} onSuccess1221 * @param {Function} onFail1222 * @returns {undefined}1223 */1224 this.createVolunteer = function ($scope, assignment, onSuccess, onFail) {1225 window.document.body.style.cursor = "wait";1226 $scope.busyModeOn();1227 $http.post($scope.SYNERGY.server.buildURL("assignment", {"volunteer": true}), JSON.stringify(assignment)).success(function (result) {1228 $timeout(function () {1229 onSuccess(result);1230 }, 0);1231 }).error(function (data, status, headers, config) {1232 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1233 $timeout(function () {1234 onFail(data, status);1235 }, 100);1236 });1237 };1238 }1239 return new AssignmentFct($http, $timeout);1240 }]).factory("usersHttp", ["$http", "$timeout", function ($http, $timeout) {1241 function UsersFct($http, $timeout) {1242 /**1243 * Returns paginated list of users1244 * @param {type} $scope1245 * @param {Number} page page number, starts with 11246 * @param {Function} onSuccess1247 * @param {Function} onFail1248 * @returns {undefined}1249 */1250 this.get = function ($scope, page, onSuccess, onFail) {1251 $scope.busyModeOn();1252 $http.get($scope.SYNERGY.server.buildURL("users", {"page": page}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1253 $timeout(function () {1254 onSuccess(result);1255 }, 0);1256 }).error(function (data, status, headers, config) {1257 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1258 $timeout(function () {1259 onFail(data, status);1260 }, 100);1261 });1262 };1263 this.retireUsersWithRole = function ($scope, roleName, onSuccess, onFail) {1264 $scope.busyModeOn();1265 $http({method: "PUT", url: $scope.SYNERGY.server.buildURL("users", {"role": roleName})}).success(function (result) {1266 $timeout(function () {1267 onSuccess(result);1268 }, 0);1269 }).error(function (data, status, headers, config) {1270 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1271 $timeout(function () {1272 onFail(data, status);1273 }, 100);1274 });1275 };1276 /**1277 * Requests user imports1278 * @param {type} $scope1279 * @param {type} sourceUrl url from which users should be imported1280 * @param {type} onSuccess1281 * @param {type} onFail1282 * @returns {undefined}1283 */1284 this.importUsers = function ($scope, sourceUrl, onSuccess, onFail) {1285 $scope.busyModeOn();1286 $http.post($scope.SYNERGY.server.buildURL("users", {}), JSON.stringify({url: sourceUrl})).success(function (result) {1287 $timeout(function () {1288 onSuccess(result);1289 }, 0);1290 }).error(function (data, status, headers, config) {1291 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1292 $timeout(function () {1293 onFail(data, status);1294 }, 100);1295 });1296 };1297 /**1298 * Returns all users in single page1299 * @param {type} $scope1300 * @param {Function} onSuccess1301 * @param {Function} onFail1302 * @returns {undefined}1303 */1304 this.getAll = function ($scope, onSuccess, onFail) {1305 $scope.busyModeOn();1306 $http.get($scope.SYNERGY.server.buildURL("users", {}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1307 $timeout(function () {1308 onSuccess(result);1309 }, 0);1310 }).error(function (data, status, headers, config) {1311 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1312 $timeout(function () {1313 onFail(data, status);1314 }, 100);1315 });1316 };1317 /**1318 * Returns users matching given username1319 * @param {type} $scope1320 * @param {String} username username1321 * @param {Function} onSuccess1322 * @param {Function} onFail1323 * @returns {undefined}1324 */1325 this.getMatching = function ($scope, username, onSuccess, onFail) {1326 $scope.busyModeOn();1327 $http.get($scope.SYNERGY.server.buildURL("users", {"user": username}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1328 $timeout(function () {1329 onSuccess(result);1330 }, 0);1331 }).error(function (data, status, headers, config) {1332 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1333 $timeout(function () {1334 onFail(data, status);1335 }, 100);1336 });1337 };1338 }1339 return new UsersFct($http, $timeout);1340 }]).factory("attachmentHttp", ["$http", "$timeout", function ($http, $timeout) {1341 function AttachmentFct($http, $timeout) {1342 this.getAttachmentsForSpecification = function ($scope, specificationId, onSuccess, onFail) {1343 window.document.body.style.cursor = "wait";1344 $scope.busyModeOn();1345 $http({method: "GET", url: $scope.SYNERGY.server.buildURL("attachments", {"id": specificationId})}).success(function (result) {1346 $timeout(function () {1347 onSuccess(result);1348 }, 0);1349 }).error(function (data, status, headers, config) {1350 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1351 $timeout(function () {1352 onFail(data, status);1353 }, 100);1354 });1355 };1356 /**1357 * Deletes test run attachment1358 * @param {type} $scope1359 * @param {Number} attachmentId attachment ID1360 * @param {Function} onSuccess1361 * @param {Function} onFail1362 * @returns {undefined}1363 */1364 this.removeRunAttachment = function ($scope, attachmentId, onSuccess, onFail) {1365 window.document.body.style.cursor = "wait";1366 $scope.busyModeOn();1367 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("run_attachment", {"id": attachmentId})}).success(function (result) {1368 $timeout(function () {1369 onSuccess(result);1370 }, 0);1371 }).error(function (data, status, headers, config) {1372 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1373 $timeout(function () {1374 onFail(data, status);1375 }, 100);1376 });1377 };1378 /**1379 * Deletes specification attachment1380 * @param {type} $scope1381 * @param {Number} attachmentId attachment ID1382 * @param {Function} onSuccess1383 * @param {Function} onFail1384 * @returns {undefined}1385 */1386 this.removeSpecAttachment = function ($scope, attachmentId, specificationId, onSuccess, onFail) {1387 window.document.body.style.cursor = "wait";1388 $scope.busyModeOn();1389 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("attachment", {"id": attachmentId, "specificationId": specificationId})}).success(function (result) {1390 $timeout(function () {1391 onSuccess(result);1392 }, 0);1393 }).error(function (data, status, headers, config) {1394 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1395 $timeout(function () {1396 onFail(data, status);1397 }, 100);1398 });1399 };1400 }1401 return new AttachmentFct($http, $timeout);1402 }]).factory("labelHttp", ["$http", "$timeout", function ($http, $timeout) {1403 function LabelFct($http, $timeout) {1404 /**1405 * Returns all cases with given label (paginated, first page is 1)1406 * @param {type} $scope1407 * @param {String} label1408 * @param {Number} page1409 * @param {Function} onSuccess1410 * @param {Function} onFail1411 * @returns {undefined}1412 */1413 this.findCases = function ($scope, label, page, onSuccess, onFail) {1414 $scope.busyModeOn();1415 $http.get($scope.SYNERGY.server.buildURL("label", {"page": page, "label": encodeURIComponent(label)}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1416 $timeout(function () {1417 onSuccess(result);1418 }, 0);1419 }).error(function (data, status, headers, config) {1420 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1421 $timeout(function () {1422 onFail(data, status);1423 }, 100);1424 });1425 };1426 /**1427 * Adds label to test case1428 * @param {type} $scope1429 * @param {type} label {"label": "", "testCaseId": 1}1430 * @param {type} onSuccess1431 * @param {type} onFail1432 * @returns {undefined}1433 */1434 this.create = function ($scope, label, onSuccess, onFail) {1435 window.document.body.style.cursor = "wait";1436 $scope.busyModeOn();1437 $http.post($scope.SYNERGY.server.buildURL("label", {}), JSON.stringify(label)).success(function (result) {1438 $timeout(function () {1439 onSuccess(result);1440 }, 0);1441 }).error(function (data, status, headers, config) {1442 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1443 $timeout(function () {1444 onFail(data, status);1445 }, 100);1446 });1447 };1448 /**1449 * Removes label from test case1450 * @param {type} $scope1451 * @param {type} label {"label": "", "testCaseId": 1}1452 * @param {type} onSuccess1453 * @param {type} onFail1454 * @returns {undefined}1455 */1456 this.remove = function ($scope, label, onSuccess, onFail) {1457 window.document.body.style.cursor = "wait";1458 $scope.busyModeOn();1459 $http.put($scope.SYNERGY.server.buildURL("label", {}), JSON.stringify(label)).success(function (result) {1460 $timeout(function () {1461 onSuccess(result);1462 }, 0);1463 }).error(function (data, status, headers, config) {1464 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1465 $timeout(function () {1466 onFail(data, status);1467 }, 100);1468 });1469 };1470 }1471 return new LabelFct($http, $timeout);1472 }]).factory("labelsHttp", ["$http", "$timeout", function ($http, $timeout) {1473 function LabelsFct($http, $timeout) {1474 /**1475 * Returns all matching labels (paginated, first page is 1)1476 * @param {type} $scope1477 * @param {String} label1478 * @param {Function} onSuccess1479 * @param {Function} onFail1480 * @returns {undefined}1481 */1482 this.getMatching = function ($scope, label, onSuccess, onFail) {1483 $scope.busyModeOn();1484 $http.get($scope.SYNERGY.server.buildURL("labels", {"label": label}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1485 $timeout(function () {1486 onSuccess(result);1487 }, 0);1488 }).error(function (data, status, headers, config) {1489 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1490 $timeout(function () {1491 onFail(data, status);1492 }, 100);1493 });1494 };1495 /**1496 * Returns all labels1497 * @param {type} $scope 1498 * @param {Function} onSuccess1499 * @param {Function} onFail1500 * @returns {undefined}1501 */1502 this.getAll = function ($scope, onSuccess, onFail) {1503 $scope.busyModeOn();1504 $http.get($scope.SYNERGY.server.buildURL("labels", {"all": 1}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1505 $timeout(function () {1506 onSuccess(result);1507 }, 0);1508 }).error(function (data, status, headers, config) {1509 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1510 $timeout(function () {1511 onFail(data, status);1512 }, 100);1513 });1514 };1515 /**1516 * Adds labels to each test case in given suite1517 * @param {type} $scope1518 * @param {Number} suiteId1519 * @param {String} label1520 * @param {type} onSuccess1521 * @param {type} onFail1522 * @returns {undefined}1523 */1524 this.createForSuite = function ($scope, suiteId, label, onSuccess, onFail) {1525 window.document.body.style.cursor = "wait";1526 $scope.busyModeOn();1527 $http.post($scope.SYNERGY.server.buildURL("labels", {"id": suiteId}), JSON.stringify({"label": label})).success(function (result) {1528 $timeout(function () {1529 onSuccess(result);1530 }, 0);1531 }).error(function (data, status, headers, config) {1532 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1533 $timeout(function () {1534 onFail(data, status);1535 }, 100);1536 });1537 };1538 /**1539 * Removes labels to each test case in given suite1540 * @param {type} $scope1541 * @param {Number} suiteId1542 * @param {String} label1543 * @param {type} onSuccess1544 * @param {type} onFail1545 * @returns {undefined}1546 */1547 this.removeFromSuite = function ($scope, suiteId, label, onSuccess, onFail) {1548 window.document.body.style.cursor = "wait";1549 $scope.busyModeOn();1550 $http.put($scope.SYNERGY.server.buildURL("labels", {"id": suiteId}), JSON.stringify({"label": label})).success(function (result) {1551 $timeout(function () {1552 onSuccess(result);1553 }, 0);1554 }).error(function (data, status, headers, config) {1555 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1556 $timeout(function () {1557 onFail(data, status);1558 }, 100);1559 });1560 };1561 }1562 return new LabelsFct($http, $timeout);1563 }]).factory("imageHttp", ["$http", "$timeout", function ($http, $timeout) {1564 function ImageFct($http, $timeout) {1565 this.getImagesForCase = function ($scope, caseId, suiteId, onSuccess, onFail) {1566 window.document.body.style.cursor = "wait";1567 $scope.busyModeOn();1568 $http({method: "GET", url: $scope.SYNERGY.server.buildURL("images", {"id": caseId, "suiteId": suiteId})}).success(function (result) {1569 $timeout(function () {1570 onSuccess(result);1571 }, 0);1572 }).error(function (data, status, headers, config) {1573 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1574 $timeout(function () {1575 onFail(data, status);1576 }, 100);1577 });1578 };1579 /**1580 * Removes image1581 * @param {type} $scope1582 * @param {Number} imageId image id1583 * @param {Function} onSuccess1584 * @param {Function} onFail1585 * @returns {undefined}1586 */1587 this.remove = function ($scope, imageId, suiteId, onSuccess, onFail) {1588 window.document.body.style.cursor = "wait";1589 $scope.busyModeOn();1590 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("image", {"id": imageId, "suiteId": suiteId})}).success(function (result) {1591 $timeout(function () {1592 onSuccess(result);1593 }, 0);1594 }).error(function (data, status, headers, config) {1595 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1596 $timeout(function () {1597 onFail(data, status);1598 }, 100);1599 });1600 };1601 }1602 return new ImageFct($http, $timeout);1603 }]).factory("tribeHttp", ["$http", "$timeout", function ($http, $timeout) {1604 function TribeFct($http, $timeout) {1605 /**1606 * Returns tribe1607 * @param {type} $scope1608 * @param {Number} tribeId image id1609 * @param {Function} onSuccess1610 * @param {Function} onFail1611 * @returns {undefined}1612 */1613 this.get = function ($scope, useCache, tribeId, onSuccess, onFail) {1614 $scope.busyModeOn();1615 $http.get($scope.SYNERGY.server.buildURL("tribe", {"id": tribeId}), {"cache": useCache, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1616 $timeout(function () {1617 onSuccess(result);1618 }, 0);1619 }).error(function (data, status, headers, config) {1620 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1621 $timeout(function () {1622 onFail(data, status);1623 }, 100);1624 });1625 };1626 /**1627 * Removes user from tribe1628 * @param {type} $scope1629 * @param {String} username1630 * @param {Number} tribeId1631 * @param {Function} onSuccess1632 * @param {Function} onFail1633 * @returns {undefined}1634 */1635 this.revokeMembership = function ($scope, username, tribeId, onSuccess, onFail) {1636 window.document.body.style.cursor = "wait";1637 $scope.busyModeOn();1638 $http.put($scope.SYNERGY.server.buildURL("tribe", {"id": tribeId, "username": username, "action": "removeMember"})).success(function (result) {1639 $timeout(function () {1640 onSuccess(result);1641 }, 0);1642 }).error(function (data, status, headers, config) {1643 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1644 $timeout(function () {1645 onFail(data, status);1646 }, 100);1647 });1648 };1649 /**1650 * Adds user to tribe1651 * @param {type} $scope1652 * @param {Object} user1653 * @param {Number} tribeId1654 * @param {Function} onSuccess1655 * @param {Function} onFail1656 * @returns {undefined}1657 */1658 this.newMembership = function ($scope, user, tribeId, onSuccess, onFail) {1659 window.document.body.style.cursor = "wait";1660 $scope.busyModeOn();1661 $http.put($scope.SYNERGY.server.buildURL("tribe", {"id": tribeId, "action": "addMember"}), JSON.stringify(user)).success(function (result) {1662 $timeout(function () {1663 onSuccess(result);1664 }, 0);1665 }).error(function (data, status, headers, config) {1666 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1667 $timeout(function () {1668 onFail(data, status);1669 }, 100);1670 });1671 };1672 /**1673 * Creates a new tribe1674 * @param {type} $scope1675 * @param {Synergy.model.Tribe} tribe1676 * @param {Function} onSuccess1677 * @param {Function} onFail1678 * @returns {undefined}1679 */1680 this.create = function ($scope, tribe, onSuccess, onFail) {1681 window.document.body.style.cursor = "wait";1682 $scope.busyModeOn();1683 $http.post($scope.SYNERGY.server.buildURL("tribe", {}), JSON.stringify(tribe)).success(function (result) {1684 $timeout(function () {1685 onSuccess(result);1686 }, 0);1687 }).error(function (data, status, headers, config) {1688 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1689 $timeout(function () {1690 onFail(data, status);1691 }, 100);1692 });1693 };1694 /**1695 * Removes tribe1696 * @param {type} $scope1697 * @param {Number} tribeId1698 * @param {Function} onSuccess1699 * @param {Function} onFail1700 * @returns {undefined}1701 */1702 this.remove = function ($scope, tribeId, onSuccess, onFail) {1703 window.document.body.style.cursor = "wait";1704 $scope.busyModeOn();1705 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("tribe", {"id": tribeId})}).success(function (result) {1706 $timeout(function () {1707 onSuccess(result);1708 }, 0);1709 }).error(function (data, status, headers, config) {1710 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1711 $timeout(function () {1712 onFail(data, status);1713 }, 100);1714 });1715 };1716 /**1717 * Updates tribe1718 * @param {type} $scope1719 * @param {Synergy.model.Tribe} tribe1720 * @param {Function} onSuccess1721 * @param {Function} onFail1722 * @returns {undefined}1723 */1724 this.edit = function ($scope, tribe, onSuccess, onFail) {1725 window.document.body.style.cursor = "wait";1726 $scope.busyModeOn();1727 $http.put($scope.SYNERGY.server.buildURL("tribe", {"id": tribe.id, "action": "editTribe"}), JSON.stringify(tribe)).success(function (result) {1728 $timeout(function () {1729 onSuccess(result);1730 }, 0);1731 }).error(function (data, status, headers, config) {1732 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1733 $timeout(function () {1734 onFail(data, status);1735 }, 100);1736 });1737 };1738 /**1739 * Adds specification to tribe1740 * @param {type} $scope1741 * @param {type} tribeId1742 * @param {type} specificationId1743 * @param {type} onSuccess1744 * @param {type} onFail1745 * @returns {undefined}1746 */1747 this.addSpecification = function ($scope, tribeId, specificationId, onSuccess, onFail) {1748 window.document.body.style.cursor = "wait";1749 $scope.busyModeOn();1750 $http.post($scope.SYNERGY.server.buildURL("tribe_specification", {"id": tribeId, "specificationId": specificationId}), JSON.stringify({})).success(function (result) {1751 $timeout(function () {1752 onSuccess(result, specificationId);1753 }, 0);1754 }).error(function (data, status, headers, config) {1755 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1756 $timeout(function () {1757 onFail(data, status);1758 }, 100);1759 });1760 };1761 /**1762 * Removes specification from tribe1763 * @param {type} $scope1764 * @param {type} tribeId1765 * @param {type} specificationId1766 * @param {type} onSuccess1767 * @param {type} onFail1768 * @returns {undefined}1769 */1770 this.removeSpecification = function ($scope, tribeId, specificationId, onSuccess, onFail) {1771 window.document.body.style.cursor = "wait";1772 $scope.busyModeOn();1773 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("tribe_specification", {"id": tribeId, "specificationId": specificationId})}).success(function (result) {1774 $timeout(function () {1775 onSuccess(result, parseInt(specificationId, 10));1776 }, 0);1777 }).error(function (data, status, headers, config) {1778 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1779 $timeout(function () {1780 onFail(data, status);1781 }, 100);1782 });1783 };1784 }1785 return new TribeFct($http, $timeout);1786 }]).factory("platformsHttp", ["$http", "$timeout", function ($http, $timeout) {1787 function PlatformsFct($http, $timeout) {1788 /**1789 * Returns platforms1790 * @param {type} $scope1791 * @param {Function} onSuccess1792 * @param {Function} onFail1793 * @returns {undefined}1794 */1795 this.get = function ($scope, onSuccess, onFail, cache) {1796 cache = (typeof cache === "undefined") ? false : cache;1797 $scope.busyModeOn();1798 $http.get($scope.SYNERGY.server.buildURL("platforms", {}), {"timeout": $scope.SYNERGY.httpTimeout, "cache": cache}).success(function (result) {1799 $timeout(function () {1800 onSuccess(result);1801 }, 0);1802 }).error(function (data, status, headers, config) {1803 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1804 $timeout(function () {1805 onFail(data, status);1806 }, 100);1807 });1808 };1809 /**1810 * Returns platforms that matches to given parameter1811 * @param {type} $scope1812 * @param {String} filter 1813 * @param {Function} onSuccess1814 * @param {Function} onFail1815 * @returns {undefined}1816 */1817 this.getMatching = function ($scope, filter, onSuccess, onFail) {1818 $scope.busyModeOn();1819 $http.get($scope.SYNERGY.server.buildURL("platforms", {"query": filter, "mode": "filter"}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1820 $timeout(function () {1821 onSuccess(result);1822 }, 0);1823 }).error(function (data, status, headers, config) {1824 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1825 $timeout(function () {1826 onFail(data, status);1827 }, 100);1828 });1829 };1830 }1831 return new PlatformsFct($http, $timeout);1832 }]).factory("platformHttp", ["$http", "$timeout", function ($http, $timeout) {1833 function PlatformFct($http, $timeout) {1834 /**1835 * Removes platform1836 * @param {type} $scope1837 * @param {Number} platformId description1838 * @param {Function} onSuccess1839 * @param {Function} onFail1840 * @returns {undefined}1841 */1842 this.remove = function ($scope, platformId, onSuccess, onFail) {1843 window.document.body.style.cursor = "wait";1844 $scope.busyModeOn();1845 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("platform", {"id": platformId})}).success(function (result) {1846 $timeout(function () {1847 onSuccess(result);1848 }, 0);1849 }).error(function (data, status, headers, config) {1850 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1851 $timeout(function () {1852 onFail(data, status);1853 }, 100);1854 });1855 };1856 /**1857 * Updates platform1858 * @param {type} $scope1859 * @param {Synergy.model.Platform} platform1860 * @param {Function} onSuccess1861 * @param {Function} onFail1862 * @returns {undefined}1863 */1864 this.edit = function ($scope, platform, onSuccess, onFail) {1865 window.document.body.style.cursor = "wait";1866 $scope.busyModeOn();1867 $http.put($scope.SYNERGY.server.buildURL("platform", {"id": platform.id}), JSON.stringify(platform)).success(function (result) {1868 $timeout(function () {1869 onSuccess(result);1870 }, 0);1871 }).error(function (data, status, headers, config) {1872 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1873 $timeout(function () {1874 onFail(data, status);1875 }, 100);1876 });1877 };1878 /**1879 * Creates platform1880 * @param {type} $scope1881 * @param {Synergy.model.Platform} platform1882 * @param {Function} onSuccess1883 * @param {Function} onFail1884 * @returns {undefined}1885 */1886 this.create = function ($scope, platform, onSuccess, onFail) {1887 window.document.body.style.cursor = "wait";1888 $scope.busyModeOn();1889 $http.post($scope.SYNERGY.server.buildURL("platform", {}), JSON.stringify(platform)).success(function (result) {1890 $timeout(function () {1891 onSuccess(result);1892 }, 0);1893 }).error(function (data, status, headers, config) {1894 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1895 $timeout(function () {1896 onFail(data, status);1897 }, 100);1898 });1899 };1900 }1901 return new PlatformFct($http, $timeout);1902 }]).factory("tribesHttp", ["$http", "$timeout", function ($http, $timeout) {1903 function TribesFct($http, $timeout) {1904 /**1905 * Returns list of tribes1906 * @param {type} $scope1907 * @param {Function} onSuccess1908 * @param {Function} onFail1909 * @returns {undefined}1910 */1911 this.get = function ($scope, onSuccess, onFail, cache) {1912 $scope.busyModeOn();1913 cache = (typeof cache === "undefined") ? false : cache;1914 $http.get($scope.SYNERGY.server.buildURL("tribes", {}), {"timeout": $scope.SYNERGY.httpTimeout, "cache": cache}).success(function (result) {1915 $timeout(function () {1916 onSuccess(result);1917 }, 0);1918 }).error(function (data, status, headers, config) {1919 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1920 $timeout(function () {1921 onFail(data, status);1922 }, 100);1923 });1924 };1925 /**1926 * Returns tribes with full information (users, specifications)1927 * @param {type} $scope1928 * @param {type} username Username of user that requested given data. Only tribes with leader that is the same as username will be returned1929 * @param {type} onSuccess1930 * @param {type} onFail1931 * @returns {undefined}1932 */1933 this.getDetailed = function ($scope, username, onSuccess, onFail) {1934 $scope.busyModeOn();1935 $http.get($scope.SYNERGY.server.buildURL("tribes", {"mode": "full", "leader": username}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1936 $timeout(function () {1937 onSuccess(result);1938 }, 0);1939 }).error(function (data, status, headers, config) {1940 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1941 $timeout(function () {1942 onFail(data, status);1943 }, 100);1944 });1945 };1946 /**1947 * Returns tribes with full information (users, specifications)1948 * @param {type} $scope1949 * @param {type} username Username of user that requested given data. Only tribes with leader that is the same as username will be returned1950 * @param {type} testRunId test run id1951 * @param {type} onSuccess1952 * @param {type} onFail1953 * @returns {undefined}1954 */1955 this.getTribesForRun = function ($scope, username, testRunId, onSuccess, onFail) {1956 $scope.busyModeOn();1957 $http.get($scope.SYNERGY.server.buildURL("run_tribes", {"leader": username, "testRunId": testRunId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {1958 $timeout(function () {1959 onSuccess(result);1960 }, 0);1961 }).error(function (data, status, headers, config) {1962 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1963 $timeout(function () {1964 onFail(data, status);1965 }, 100);1966 });1967 };1968 /**1969 * Imports tribes from given URL1970 * @param {type} $scope1971 * @param {String} sourceUrl import URL1972 * @param {type} onSuccess1973 * @param {type} onFail1974 * @returns {undefined}1975 */1976 this.importTribes = function ($scope, sourceUrl, onSuccess, onFail) {1977 $scope.busyModeOn();1978 $http.post($scope.SYNERGY.server.buildURL("tribes", {}), JSON.stringify({url: sourceUrl})).success(function (result) {1979 $timeout(function () {1980 onSuccess(result);1981 }, 0);1982 }).error(function (data, status, headers, config) {1983 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);1984 $timeout(function () {1985 onFail(data, status);1986 }, 100);1987 });1988 };1989 }1990 return new TribesFct($http, $timeout);1991 }]).factory("sessionHttp", ["$http", "$timeout", function ($http, $timeout) {1992 function SessionFct($http, $timeout) {1993 /**1994 * Returns session information1995 * @param {type} $scope1996 * @param {Function} onSuccess1997 * @param {Function} onFail1998 * @returns {undefined}1999 */2000 this.get = function ($scope, onSuccess, onFail) {2001 $scope.busyModeOn();2002 $http.get($scope.SYNERGY.server.buildURL("session", {"login": 1}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2003 $timeout(function () {2004 onSuccess(result);2005 }, 0);2006 }).error(function (data, status, headers, config) {2007 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2008 $timeout(function () {2009 onFail(data, status);2010 }, 100);2011 });2012 };2013 this.info = function ($scope, onSuccess, onFail) {2014 $scope.busyModeOn();2015 $http.get($scope.SYNERGY.server.buildURL("session", {}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2016 $timeout(function () {2017 onSuccess(result);2018 }, 0);2019 }).error(function (data, status, headers, config) {2020 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2021 $timeout(function () {2022 onFail(data, status);2023 }, 100);2024 });2025 };2026 this.infoConditional = function ($scope, onSuccess, onFail) {2027 $scope.busyModeOn();2028 $http.get($scope.SYNERGY.server.buildURL("session", {"return": 1}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2029 $timeout(function () {2030 onSuccess(result);2031 }, 0);2032 }).error(function (data, status, headers, config) {2033 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2034 $timeout(function () {2035 onFail(data, status);2036 }, 100);2037 });2038 };2039 this.infoConditionalPromise = function (url) {2040 return $http.get(url, {"cache": false});2041 };2042 this.infoConditionalCookie = function ($scope, onSuccess, onFail) {2043 $scope.busyModeOn();2044 $http.get($scope.SYNERGY.server.buildURL("session", {"return": 2}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2045 $timeout(function () {2046 onSuccess(result);2047 }, 0);2048 }).error(function (data, status, headers, config) {2049 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2050 $timeout(function () {2051 onFail(data, status);2052 }, 100);2053 });2054 };2055 /**2056 * Submits credentials to server2057 * @param {type} $scope2058 * @param {Object} credentials2059 * @param {Function} onSuccess2060 * @param {Function} onFail2061 * @returns {undefined}2062 */2063 this.login = function ($scope, credentials, onSuccess, onFail) {2064 window.document.body.style.cursor = "wait";2065 $scope.busyModeOn();2066 $http.post($scope.SYNERGY.server.buildURL("session", {}), "username=" + credentials.username + "&password=" + credentials.password, {2067 headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}2068 }).success(function (result) {2069 $timeout(function () {2070 onSuccess(result);2071 }, 0);2072 }).error(function (data, status, headers, config) {2073 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2074 $timeout(function () {2075 onFail(data, status);2076 }, 100);2077 });2078 };2079 this.resetPassword = function ($scope, username, onSuccess, onFail) {2080 window.document.body.style.cursor = "wait";2081 $scope.busyModeOn();2082 $http.put($scope.SYNERGY.server.buildURL("session", {}), JSON.stringify({username: username}))2083 .success(function (result) {2084 $timeout(function () {2085 onSuccess(result);2086 }, 0);2087 }).error(function (data, status, headers, config) {2088 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2089 $timeout(function () {2090 onFail(data, status);2091 }, 100);2092 });2093 };2094 /**2095 * Destroys session at server2096 * @param {type} $scope2097 * @param {Function} onSuccess2098 * @param {Function} onFail2099 * @returns {undefined}2100 */2101 this.logout = function ($scope, onSuccess, onFail) {2102 window.document.body.style.cursor = "wait";2103 $scope.busyModeOn();2104 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("session", {})}).success(function (result) {2105 $timeout(function () {2106 onSuccess(result);2107 }, 0);2108 }).error(function (data, status, headers, config) {2109 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2110 $timeout(function () {2111 onFail(data, status);2112 }, 100);2113 });2114 };2115 }2116 return new SessionFct($http, $timeout);2117 }]).factory("settingsHttp", ["$http", "$timeout", function ($http, $timeout) {2118 function SettingsFct($http, $timeout) {2119 /**2120 * Returns server"s settings2121 * @param {type} $scope2122 * @param {Function} onSuccess2123 * @param {Function} onFail2124 * @returns {undefined}2125 */2126 this.get = function ($scope, onSuccess, onFail) {2127 $scope.busyModeOn();2128 $http.get($scope.SYNERGY.server.buildURL("configuration", {}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2129 $timeout(function () {2130 onSuccess(result);2131 }, 0);2132 }).error(function (data, status, headers, config) {2133 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2134 $timeout(function () {2135 onFail(data, status);2136 }, 100);2137 });2138 };2139 /**2140 * Edits server settings2141 * @param {type} $scope2142 * @param {Object} configuration description2143 * @param {Function} onSuccess2144 * @param {Function} onFail2145 * @returns {undefined}2146 */2147 this.edit = function ($scope, configuration, onSuccess, onFail) {2148 window.document.body.style.cursor = "wait";2149 $scope.busyModeOn();2150 $http.put($scope.SYNERGY.server.buildURL("configuration", {}), JSON.stringify(configuration)).success(function (result) {2151 $timeout(function () {2152 onSuccess(result);2153 }, 0);2154 }).error(function (data, status, headers, config) {2155 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2156 $timeout(function () {2157 onFail(data, status);2158 }, 100);2159 });2160 };2161 }2162 return new SettingsFct($http, $timeout);2163 }]).factory("calendarHttp", ["$http", "$timeout", function ($http, $timeout) {2164 function CalendarFct($http, $timeout) {2165 /**2166 * Returns events from server (test runs etc.)2167 * @param {type} $scope2168 * @param {Function} onSuccess2169 * @param {Function} onFail2170 * @returns {undefined}2171 */2172 this.getEvents = function ($scope, onSuccess, onFail) {2173 $scope.busyModeOn();2174 $http.get($scope.SYNERGY.server.buildURL("events", {}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2175 $timeout(function () {2176 onSuccess(result);2177 }, 0);2178 }).error(function (data, status, headers, config) {2179 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2180 $timeout(function () {2181 onFail(data, status);2182 }, 100);2183 });2184 };2185 }2186 return new CalendarFct($http, $timeout);2187 }]).factory("aboutHttp", ["$http", "$timeout", function ($http, $timeout) {2188 function AboutFct($http, $timeout) {2189 /**2190 * Retrieves list of statistics about Synergy2191 * @param {Function} onSuccess2192 * @param {Function} onFail2193 */2194 this.get = function ($scope, onSuccess, onFail) {2195 $scope.busyModeOn();2196 $http.get($scope.SYNERGY.server.buildURL("about", {}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2197 $timeout(function () {2198 onSuccess(result);2199 }, 0);2200 }).error(function (data, status, headers, config) {2201 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2202 $timeout(function () {2203 onFail(data, status);2204 }, 100);2205 });2206 };2207 }2208 return new AboutFct($http, $timeout);2209 }]).factory("searchHttp", ["$http", "$timeout", function ($http, $timeout) {2210 function SearchFct($http, $timeout) {2211 /**2212 * Retrieves list of search results2213 * @param {Function} onSuccess2214 * @param {Function} onFail2215 */2216 this.get = function ($scope, term, onSuccess, onFail) {2217 $scope.busyModeOn();2218 $http.get($scope.SYNERGY.server.buildURL("search", {"search": encodeURIComponent(term)}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2219 $timeout(function () {2220 onSuccess(result);2221 }, 0);2222 }).error(function (data, status, headers, config) {2223 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2224 $timeout(function () {2225 onFail(data, status);2226 }, 100);2227 });2228 };2229 /**2230 * Retrieves list of search results that contains only up to 15 specifications2231 */2232 this.getFewSpecifications = function ($scope, term, onSuccess, onFail) {2233 $scope.busyModeOn();2234 $http.get($scope.SYNERGY.server.buildURL("search", {"search": encodeURIComponent(term), "specifications": 15, "suites": 0}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2235 $timeout(function () {2236 onSuccess(result);2237 }, 0);2238 }).error(function (data, status, headers, config) {2239 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2240 $timeout(function () {2241 onFail(data, status);2242 }, 100);2243 });2244 };2245 }2246 return new SearchFct($http, $timeout);2247 }]).factory("productsHttp", ["$http", "$timeout", function ($http, $timeout) {2248 function ProductsFct($http, $timeout) {2249 /**2250 * Retrieves list of products2251 * @param {Function} onSuccess2252 * @param {Function} onFail2253 */2254 this.get = function ($scope, onSuccess, onFail) {2255 $scope.busyModeOn();2256 $http.get($scope.SYNERGY.server.buildURL("products", {}), {"cache": true, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2257 $timeout(function () {2258 onSuccess(result);2259 }, 0);2260 }).error(function (data, status, headers, config) {2261 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2262 $timeout(function () {2263 onFail(data, status);2264 }, 100);2265 });2266 };2267 }2268 return new ProductsFct($http, $timeout);2269 }]).factory("assignmentsHttp", ["$http", "$timeout", function ($http, $timeout) {2270 function AssignmentsFct($http, $timeout) {2271 this.createForTribes = function ($scope, data, onSuccess, onFail) {2272 window.document.body.style.cursor = "wait";2273 $scope.busyModeOn();2274 $http.post($scope.SYNERGY.server.buildURL("tribe_assignments", {}), JSON.stringify(data)).success(function (result) {2275 $timeout(function () {2276 onSuccess(result);2277 }, 0);2278 }).error(function (data, status, headers, config) {2279 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2280 $timeout(function () {2281 onFail(data, status);2282 }, 100);2283 });2284 };2285 this.createForUsers = function ($scope, data, onSuccess, onFail) {2286 window.document.body.style.cursor = "wait";2287 $scope.busyModeOn();2288 $http.post($scope.SYNERGY.server.buildURL("assignments", {"mode": "user"}), JSON.stringify(data)).success(function (result) {2289 $timeout(function () {2290 onSuccess(result);2291 }, 0);2292 }).error(function (data, status, headers, config) {2293 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2294 $timeout(function () {2295 onFail(data, status);2296 }, 100);2297 });2298 };2299 /**2300 * Returns test assignment2301 * @param {type} $scope2302 * @param {Number} assignmentId assignment ID2303 * @param {Function} onSuccess2304 * @param {Function} onFail2305 * @returns {undefined}2306 */2307 this.create = function ($scope, data, onSuccess, onFail) {2308 window.document.body.style.cursor = "wait";2309 $scope.busyModeOn();2310 $http.post($scope.SYNERGY.server.buildURL("assignments", {"mode": "matrix"}), JSON.stringify(data)).success(function (result) {2311 $timeout(function () {2312 onSuccess(result);2313 }, 0);2314 }).error(function (data, status, headers, config) {2315 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2316 $timeout(function () {2317 onFail(data, status);2318 }, 100);2319 });2320 };2321 }2322 return new AssignmentsFct($http, $timeout);2323 }]).factory("logHttp", ["$http", "$timeout", function ($http, $timeout) {2324 function LogFct($http, $timeout) {2325 /**2326 * loads error log (need to be signed in)2327 * @param {type} $scope2328 * @param {Function} onSuccess2329 * @param {Function} onFail2330 * @returns {undefined}2331 */2332 this.get = function ($scope, onSuccess, onFail) {2333 $scope.busyModeOn();2334 $http.get($scope.SYNERGY.server.buildURL("log", {})).success(function (result) {2335 $timeout(function () {2336 onSuccess(result);2337 }, 0);2338 }).error(function (data, status, headers, config) {2339 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2340 $timeout(function () {2341 onFail(data, status);2342 }, 100);2343 });2344 };2345 /**2346 * Clears log2347 */2348 this.remove = function ($scope, onSuccess, onFail) {2349 window.document.body.style.cursor = "wait";2350 $scope.busyModeOn();2351 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("log", {})}).success(function (result) {2352 $timeout(function () {2353 onSuccess(result);2354 }, 0);2355 }).error(function (data, status, headers, config) {2356 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2357 $timeout(function () {2358 onFail(data, status);2359 }, 100);2360 });2361 };2362 }2363 return new LogFct($http, $timeout);2364 }]).factory("databaseHttp", ["$http", "$timeout", function ($http, $timeout) {2365 function DatabaseFct($http, $timeout) {2366 /**2367 * Retrieves array of tables names2368 */2369 this.getTables = function ($scope, onSuccess, onFail) {2370 $scope.busyModeOn();2371 $http.get($scope.SYNERGY.server.buildURL("db", {"what": "tables"}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2372 $timeout(function () {2373 onSuccess(result);2374 }, 0);2375 }).error(function (data, status, headers, config) {2376 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2377 $timeout(function () {2378 onFail(data, status);2379 }, 100);2380 });2381 };2382 /**2383 * Retrieves list of columns in given table2384 * @param {type} $scope2385 * @param {String} table table name2386 * @param {type} onSuccess2387 * @param {type} onFail2388 * @returns {undefined}2389 */2390 this.getColumns = function ($scope, table, onSuccess, onFail) {2391 $scope.busyModeOn();2392 $http.get($scope.SYNERGY.server.buildURL("db", {"what": "table", "table": table}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2393 $timeout(function () {2394 onSuccess(result);2395 }, 0);2396 }).error(function (data, status, headers, config) {2397 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2398 $timeout(function () {2399 onFail(data, status);2400 }, 100);2401 });2402 };2403 /**2404 * Retrieves records from given table2405 * @param {type} $scope2406 * @param {type} table table name2407 * @param {type} limit number of records to be retrieved2408 * @param {type} order type of sorting (DESC or ASC)2409 * @param {type} orderBy by which column it should be sorted2410 * @param {type} onSuccess 2411 * @param {type} onFail2412 */2413 this.listTable = function ($scope, table, limit, order, orderBy, onSuccess, onFail) {2414 $scope.busyModeOn();2415 $http.get($scope.SYNERGY.server.buildURL("db", {"what": "list", "table": table, "limit": limit, "order": order, "orderBy": orderBy}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2416 $timeout(function () {2417 onSuccess(result);2418 }, 0);2419 }).error(function (data, status, headers, config) {2420 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2421 $timeout(function () {2422 onFail(data, status);2423 }, 100);2424 });2425 };2426 }2427 return new DatabaseFct($http, $timeout);2428 }]).factory("jobHttp", ["$http", "$timeout", function ($http, $timeout) {2429 function JobFct($http, $timeout) {2430 /**2431 * Loads information about job"s status from ci server2432 * @param {type} $scope2433 * @param {string} jobUrl2434 * @param {Function} onSuccess2435 * @param {Function} onFail2436 * @returns {undefined}2437 */2438 this.resolve = function ($scope, job, onSuccess, onFail) {2439 $http({2440 method: "JSONP",2441 url: job.jobUrl + "JSON_CALLBACK",2442 cache: false2443 }).success(function (data) {2444 data.id = job.id; // so ID from Synergy is preserved2445 onSuccess(data);2446 }).error(function (data) {2447 onFail({2448 result: "ABORTED",2449 fullDisplayName: "Job not found",2450 id: job.id,2451 url: job.jobUrl2452 });2453 }2454 );2455 };2456 /**2457 * Adds job to specification2458 * @param {type} $scope2459 * @param {Synergy.model.Job} job2460 * @param {type} onSuccess2461 * @param {type} onFail2462 * @returns {undefined}2463 */2464 this.create = function ($scope, job, onSuccess, onFail) {2465 $scope.busyModeOn();2466 window.document.body.style.cursor = "wait";2467 $http.post($scope.SYNERGY.server.buildURL("job", {}), JSON.stringify(job)).success(function (result) {2468 $timeout(function () {2469 onSuccess(result);2470 }, 0);2471 }).error(function (data, status, headers, config) {2472 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2473 $timeout(function () {2474 onFail(data, status);2475 }, 100);2476 });2477 };2478 /**2479 * Removes job from specification2480 * @param {type} $scope2481 * @param {type} jobId2482 * @param {type} onSuccess2483 * @param {type} onFail2484 * @returns {undefined}2485 */2486 this.remove = function ($scope, jobId, specificationId, onSuccess, onFail) {2487 window.document.body.style.cursor = "wait";2488 $scope.busyModeOn();2489 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("job", {"id": jobId, "specificationId": specificationId})}).success(function (result) {2490 $timeout(function () {2491 onSuccess(result);2492 }, 0);2493 }).error(function (data, status, headers, config) {2494 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2495 $timeout(function () {2496 onFail(data, status);2497 }, 100);2498 });2499 };2500 }2501 return new JobFct($http, $timeout);2502 }]).factory("issueHttp", ["$http", "$timeout", function ($http, $timeout) {2503 function IssueFct($http, $timeout) {2504 /**2505 * Adds given issue to test case2506 * @param {type} $scope2507 * @param {Number} caseId2508 * @param {Object} issue2509 * @param {Function} onSuccess2510 * @param {Function} onFail2511 * @returns {undefined}2512 */2513 this.create = function ($scope, issue, onSuccess, onFail) {2514 window.document.body.style.cursor = "wait";2515 $scope.busyModeOn();2516 $http.post($scope.SYNERGY.server.buildURL("issue", {}), JSON.stringify(issue)).success(function (result) {2517 $timeout(function () {2518 onSuccess(result);2519 }, 0);2520 }).error(function (data, status, headers, config) {2521 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2522 $timeout(function () {2523 onFail(data, status);2524 }, 100);2525 });2526 };2527 /**2528 * Removes issue from test case2529 * @param {type} $scope2530 * @param {type} issue {testCaseId:1, id: 1}2531 * @param {type} onSuccess2532 * @param {type} onFail2533 * @returns {undefined}2534 */2535 this.remove = function ($scope, issue, onSuccess, onFail) {2536 window.document.body.style.cursor = "wait";2537 $scope.busyModeOn();2538 $http.put($scope.SYNERGY.server.buildURL("issue", {}), JSON.stringify(issue)).success(function (result) {2539 $timeout(function () {2540 onSuccess(result);2541 }, 0);2542 }).error(function (data, status, headers, config) {2543 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2544 $timeout(function () {2545 onFail(data, status);2546 }, 100);2547 });2548 };2549 }2550 return new IssueFct($http, $timeout);2551 }]).factory("revisionsHttp", ["$http", "$timeout", function ($http, $timeout) {2552 function RevisionsFct($http, $timeout) {2553 /**2554 * Returns list of revisions2555 * @param {type} $scope2556 * @param {type} specificationId2557 * @param {type} onSuccess2558 * @param {type} onFail2559 * @returns {undefined}2560 */2561 this.listRevisions = function ($scope, specificationId, onSuccess, onFail) {2562 $scope.busyModeOn();2563 $http.get($scope.SYNERGY.server.buildURL("revisions", {"id": specificationId, "mode": "list"}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2564 $timeout(function () {2565 onSuccess(result);2566 }, 0);2567 }).error(function (data, status, headers, config) {2568 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2569 $timeout(function () {2570 onFail(data, status);2571 }, 100);2572 });2573 };2574 /**2575 * Returns two particular revisions2576 * @param {type} $scope2577 * @param {type} idA revisionA id2578 * @param {type} idB revisionB id2579 * @param {type} specificationId2580 * @param {type} onSuccess2581 * @param {type} onFail2582 * @returns {undefined}2583 */2584 this.getRevisions = function ($scope, idA, idB, specificationId, onSuccess, onFail) {2585 $scope.busyModeOn();2586 $http.get($scope.SYNERGY.server.buildURL("revisions", {"specification": specificationId, "id1": idA, "id2": idB, "mode": "compare"}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2587 $timeout(function () {2588 onSuccess(result);2589 }, 0);2590 }).error(function (data, status, headers, config) {2591 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2592 $timeout(function () {2593 onFail(data, status);2594 }, 100);2595 });2596 };2597 }2598 return new RevisionsFct($http, $timeout);2599 }]).factory("sanitizerHttp", ["$http", "$timeout", function ($http, $timeout) {2600 function SanitizerFct($http, $timeout) {2601 /**2602 * Sanitizes given text2603 * @param {type} $scope2604 * @param {String} data text to be sanitized2605 * @param {type} onSuccess2606 * @param {type} onFail2607 * @returns {undefined}2608 */2609 this.getSanitizedInput = function ($scope, data, onSuccess, onFail) {2610 $scope.busyModeOn();2611 $http.post($scope.SYNERGY.server.buildURL("sanitizer", {}), JSON.stringify({"data": data}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2612 $timeout(function () {2613 onSuccess(result);2614 }, 0);2615 }).error(function (data, status, headers, config) {2616 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2617 $timeout(function () {2618 onFail(data, status);2619 }, 100);2620 });2621 };2622 }2623 return new SanitizerFct($http, $timeout);2624 }]).factory("statisticsHttp", ["$http", "$timeout", function ($http, $timeout) {2625 function StatisticsFct($http, $timeout) {2626 this.get = function ($scope, testRunId, onSuccess, onFail) {2627 window.document.body.style.cursor = "wait";2628 $scope.busyModeOn();2629 $http.get($scope.SYNERGY.server.buildURL("statistics", {"id": testRunId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2630 $timeout(function () {2631 onSuccess(result);2632 }, 0);2633 }).error(function (data, status, headers, config) {2634 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2635 $timeout(function () {2636 onFail(data, status);2637 }, 100);2638 });2639 };2640 this.getPeriod = function ($scope, testRunId, period, onSuccess, onFail) {2641 window.document.body.style.cursor = "wait";2642 $scope.busyModeOn();2643 $http.post($scope.SYNERGY.server.buildURL("statistics_filter", {"id": testRunId}), JSON.stringify(period)).success(function (result) {2644 $timeout(function () {2645 onSuccess(result);2646 }, 0);2647 }).error(function (data, status, headers, config) {2648 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2649 $timeout(function () {2650 onFail(data, status);2651 }, 100);2652 });2653 };2654 this.getArchive = function ($scope, testRunId, fallBackUrl, onSuccess, onFail) {2655 window.document.body.style.cursor = "wait";2656 $scope.busyModeOn();2657 var url = (fallBackUrl) ? $scope.SYNERGY.server.buildURL("statistics_fallback", {}) + "run" + testRunId + "/statistics.json" : $scope.SYNERGY.server.buildURL("statistics_archived", {}) + "run" + testRunId + "/statistics.json";2658 url += "?d=" + Date.now();2659 $http.get(url, {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2660 $timeout(function () {2661 onSuccess(result);2662 }, 0);2663 }).error(function (data, status, headers, config) {2664 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2665 $timeout(function () {2666 onFail(data, status);2667 }, 100);2668 });2669 };2670 }2671 return new StatisticsFct($http, $timeout);2672 }]).factory("reviewHttp", ["$http", "$timeout", function ($http, $timeout) {2673 function ReviewFct($http, $timeout) {2674 /**2675 * Submits review assignment results2676 * @param {type} $scope2677 * @param {Number} assignmentId assignment ID2678 * @param {Synergy.model.ReviewAssignment} results2679 * @param {Function} onSuccess2680 * @param {Function} onFail2681 * @returns {undefined}2682 */2683 this.submitResults = function ($scope, assignmentId, results, onSuccess, onFail) {2684 window.document.body.style.cursor = "wait";2685 $scope.busyModeOn();2686 $http.defaults.headers.common["Synergy-Timestamp"] = encodeURIComponent(new Date().toMysqlFormat());2687 $http.put($scope.SYNERGY.server.buildURL("review_assignment", {"id": assignmentId, "datetime": new Date().toMysqlFormat()}), JSON.stringify(results)).success(function (result) {2688 $timeout(function () {2689 onSuccess(result);2690 }, 0);2691 }).error(function (data, status, headers, config) {2692 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2693 $timeout(function () {2694 onFail(data, status);2695 }, 100);2696 });2697 };2698 /**2699 * Creates a volunteer review assignment2700 * @param {type} $scope2701 * @param {Synergy.model.ReviewAssignment} assignment2702 * @param {Function} onSuccess2703 * @param {Function} onFail2704 * @returns {undefined}2705 */2706 this.createVolunteer = function ($scope, assignment, onSuccess, onFail) {2707 window.document.body.style.cursor = "wait";2708 $scope.busyModeOn();2709 $http.post($scope.SYNERGY.server.buildURL("review_assignment", {"volunteer": true}), JSON.stringify(assignment)).success(function (result) {2710 $timeout(function () {2711 onSuccess(result);2712 }, 0);2713 }).error(function (data, status, headers, config) {2714 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2715 $timeout(function () {2716 onFail(data, status);2717 }, 100);2718 });2719 };2720 /**2721 * Removes test assignment2722 * @param {type} $scope2723 * @param {Number} assignmentId assignment ID2724 * @param {Function} onSuccess2725 * @param {Function} onFail2726 * @returns {undefined}2727 */2728 this.remove = function ($scope, assignmentId, onSuccess, onFail) {2729 window.document.body.style.cursor = "wait";2730 $scope.busyModeOn();2731 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("review_assignment", {"id": assignmentId})}).success(function (result) {2732 $timeout(function () {2733 onSuccess(result);2734 }, 0);2735 }).error(function (data, status, headers, config) {2736 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2737 $timeout(function () {2738 onFail(data, status);2739 }, 100);2740 });2741 };2742 this.get = function ($scope, id, mode, onSuccess, onFail) {2743 $scope.busyModeOn();2744 $http.defaults.headers.common["Synergy-Timestamp"] = encodeURIComponent(new Date().toMysqlFormat());2745 $http.get($scope.SYNERGY.server.buildURL("review_assignment", {"id": id, "mode": mode, "datetime": new Date().toMysqlFormat()}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2746 $timeout(function () {2747 onSuccess(result);2748 }, 0);2749 }).error(function (data, status, headers, config) {2750 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2751 $timeout(function () {2752 onFail(data, status);2753 }, 100);2754 });2755 };2756 this.list = function ($scope, onSuccess, onFail) {2757 $scope.busyModeOn();2758 $http.get($scope.SYNERGY.server.buildURL("reviews", {}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2759 $timeout(function () {2760 onSuccess(result);2761 }, 0);2762 }).error(function (data, status, headers, config) {2763 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2764 $timeout(function () {2765 onFail(data, status);2766 }, 100);2767 });2768 };2769 this.listNotStarted = function ($scope, testRunId, onSuccess, onFail) {2770 $scope.busyModeOn();2771 $http.get($scope.SYNERGY.server.buildURL("reviews", {"id": testRunId}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2772 $timeout(function () {2773 onSuccess(result);2774 }, 0);2775 }).error(function (data, status, headers, config) {2776 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2777 $timeout(function () {2778 onFail(data, status);2779 }, 100);2780 });2781 };2782 this.importFromUrl = function ($scope, url, onSuccess, onFail) {2783 window.document.body.style.cursor = "wait";2784 $scope.busyModeOn();2785 $http.post($scope.SYNERGY.server.buildURL("reviews", {}), JSON.stringify({"url": url})).success(function (result) {2786 $timeout(function () {2787 onSuccess(result);2788 }, 0);2789 }).error(function (data, status, headers, config) {2790 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2791 $timeout(function () {2792 onFail(data, status);2793 }, 100);2794 });2795 };2796 this.create = function ($scope, newReview, onSuccess, onFail) {2797 $scope.busyModeOn();2798 $http.post($scope.SYNERGY.server.buildURL("review", {}), JSON.stringify(newReview)).success(function (result) {2799 $timeout(function () {2800 onSuccess(result);2801 }, 0);2802 }).error(function (data, status, headers, config) {2803 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2804 $timeout(function () {2805 onFail(data, status);2806 }, 100);2807 });2808 };2809 }2810 return new ReviewFct($http, $timeout);2811 }]).factory("projectsHttp", ["$http", "$timeout", function ($http, $timeout) {2812 function ProjectsFct($http, $timeout) {2813 /**2814 * Retrieves all projects2815 */2816 this.getAll = function ($scope, onSuccess, onFail) {2817 $scope.busyModeOn();2818 $http.get($scope.SYNERGY.server.buildURL("projects", {}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2819 $timeout(function () {2820 onSuccess(result);2821 }, 0);2822 }).error(function (data, status, headers, config) {2823 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2824 $timeout(function () {2825 onFail(data, status);2826 }, 100);2827 });2828 };2829 }2830 return new ProjectsFct($http, $timeout);2831 }]).factory("projectHttp", ["$http", "$timeout", function ($http, $timeout) {2832 function ProjectFct($http, $timeout) {2833 /**2834 * Updates project2835 * @param {type} $scope2836 * @param {Synergy.model.Project} project object with 2 properties: id and name2837 * @param {Function} onSuccess2838 * @param {Function} onFail2839 */2840 this.edit = function ($scope, project, onSuccess, onFail) {2841 window.document.body.style.cursor = "wait";2842 $scope.busyModeOn();2843 $http.put($scope.SYNERGY.server.buildURL("project", {}), JSON.stringify(project)).success(function (result) {2844 $timeout(function () {2845 onSuccess(result);2846 }, 0);2847 }).error(function (data, status, headers, config) {2848 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2849 $timeout(function () {2850 onFail(data, status);2851 }, 100);2852 });2853 };2854 /**2855 * Removes project2856 * @param {type} $scope2857 * @param {Number} projectId project ID2858 * @param {Function} onSuccess2859 * @param {Function} onFail2860 */2861 this.remove = function ($scope, projectId, onSuccess, onFail) {2862 window.document.body.style.cursor = "wait";2863 $scope.busyModeOn();2864 $http({method: "DELETE", url: $scope.SYNERGY.server.buildURL("project", {"id": projectId})}).success(function (result) {2865 $timeout(function () {2866 onSuccess(result);2867 }, 0);2868 }).error(function (data, status, headers, config) {2869 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2870 $timeout(function () {2871 onFail(data, status);2872 }, 100);2873 });2874 };2875 /**2876 * Creates project2877 * @param {type} $scope2878 * @param {Synergy.model.Project} project new project to be created with property "name"2879 * @param {Function} onSuccess2880 * @param {Function} onFail2881 */2882 this.create = function ($scope, project, onSuccess, onFail) {2883 window.document.body.style.cursor = "wait";2884 $scope.busyModeOn();2885 $http.post($scope.SYNERGY.server.buildURL("project", {}), JSON.stringify(project)).success(function (result) {2886 $timeout(function () {2887 onSuccess(result);2888 }, 0);2889 }).error(function (data, status, headers, config) {2890 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2891 $timeout(function () {2892 onFail(data, status);2893 }, 100);2894 });2895 };2896 this.get = function ($scope, id, onSuccess, onFail) {2897 $scope.busyModeOn();2898 $http.get($scope.SYNERGY.server.buildURL("project", {"id": id}), {"cache": false, "timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {2899 $timeout(function () {2900 onSuccess(result);2901 }, 0);2902 }).error(function (data, status, headers, config) {2903 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2904 $timeout(function () {2905 onFail(data, status);2906 }, 100);2907 });2908 };2909 }2910 return new ProjectFct($http, $timeout);2911 }]).factory("registerHttp", ["$http", "$timeout", function ($http, $timeout) {2912 function RegisterFct($http, $timeout) {2913 this.doRegister = function ($scope, registration, onSuccess, onFail) {2914 window.document.body.style.cursor = "wait";2915 $scope.busyModeOn();2916 $http.post($scope.SYNERGY.server.buildURL("register", {}), JSON.stringify(registration)).success(function (result) {2917 $timeout(function () {2918 onSuccess(result);2919 }, 0);2920 }).error(function (data, status, headers, config) {2921 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);2922 $timeout(function () {2923 onFail(data, status);2924 }, 100);2925 });2926 };2927 }2928 return new RegisterFct($http, $timeout);2929 }]).factory("sessionService", [function () {2930 var _session = null;2931 return {2932 setSession: function (s) {2933 _session = s;2934 },2935 clearSession: function () {2936 _session = null;2937 },2938 getToken: function () {2939 if (_session !== null && _session.hasOwnProperty("token")) {2940 return _session.token;2941 }2942 return null;2943 }2944 };2945 }]).factory("SynergyApp", [function () { // need for http interceptor2946 var synergyApp = null;2947 return {2948 setApp: function (s) {2949 synergyApp = s;2950 },2951 getApp: function () {2952 return synergyApp;2953 }2954 };2955 }]).factory("SessionRenewalFactory", ["SynergyApp", "$http", function (SynergyApp, $http) {2956 var originalResponse = null;2957 var intervalId = -1;2958 var TOKEN_LENGTH = 32;2959 var token = null;2960 var counter = 0;2961 var sessionRenewalHttp = {};//$injector.get("sessionRenewalHttp");2962 function getToken() {2963 var text = "";2964 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";2965 for (var i = 0; i < TOKEN_LENGTH; i++) {2966 text += possible.charAt(Math.floor(Math.random() * possible.length));2967 }2968 return text + new Date().getTime();2969 }2970 function reset() {2971 window.clearInterval(intervalId);2972 counter = 0;2973 token = null;2974 intervalId = -1;2975 originalResponse = null;2976 }2977 function checkForNewLogin() {2978 counter++;2979 sessionRenewalHttp.get(SynergyApp.getApp().server.buildURL("sso", {"token": token}), function () {2980 reset();2981 }, function () {2982 if (counter > 100) {2983 reset();2984 }2985 });2986 }2987 function getRedirectUrl() {2988 var url = window.location.href.substring(0, window.location.href.indexOf("#"));2989 url = url.endsWith(".html") ? url.substring(0, url.lastIndexOf("/") + 1) : url;2990 token = getToken();2991 url += "login.html?token=" + token;2992 if (SynergyApp.getApp().useSSO) {2993 return SynergyApp.getApp().getLoginRedirectUrl(SynergyApp.getApp().ssoLoginUrl, url);2994 } else {2995 // todo fix, std login page is synergy/client/app/#/login, which is not visible for server though...2996 throw new Error("Not implemented");2997 }2998 }2999 return {3000 openLoginDialog: function (response) {3001 originalResponse = response;3002 $("#myModalLabel").text("Please login");3003 $("#modal-body").html("<a href='" + getRedirectUrl() + "' target='_blank'>Click to login</a>");3004 if (!$("#myModal").hasClass("in")) {3005 $("#myModal").modal("toggle");3006 }3007 intervalId = window.setInterval(checkForNewLogin, 2000);3008 }3009 };3010 }]).factory("sessionRenewalHttp", ["$http", "$timeout", function ($http, $timeout) {3011 function SessionRenewalHttp($http, $timeout) {3012 /**3013 * Sanitizes given text3014 * @param {type} $scope3015 * @param {String} data text to be sanitized3016 * @param {type} onSuccess3017 * @param {type} onFail3018 * @returns {undefined}3019 */3020 this.test = function ($scope, onSuccess, onFail) {3021 $scope.busyModeOn();3022 $http.put($scope.SYNERGY.server.buildURL("refresh", {}), {"timeout": $scope.SYNERGY.httpTimeout}).success(function (result) {3023 $timeout(function () {3024 onSuccess(result);3025 }, 0);3026 }).error(function (data, status, headers, config) {3027 $scope.SYNERGY.logger.logHTTPError(data, status, headers, config);3028 $timeout(function () {3029 onFail(data, status);3030 }, 100);3031 });3032 };3033 this.get = function (url, token, onSuccess, onFail) {3034 $http.get(url).success(function (result) {3035 $timeout(function () {3036 onSuccess(result);3037 }, 0);3038 }).error(function (data, status, headers, config) {3039 $timeout(function () {3040 onFail(data, status);3041 }, 10);3042 });3043 };3044 }3045 return new SessionRenewalHttp($http, $timeout);3046 }]).factory("specificationCache", [function () {3047 var currentSpecification = null;3048 var currentProject = null;3049 function getSuiteEstimation(suite) {3050 var time = 0;...

Full Screen

Full Screen

cloud.js

Source:cloud.js Github

copy

Full Screen

1/*2 cloud.js3 a backend API for SNAP!4 written by Bernat Romagosa5 inspired by the original cloud API by Jens Mönig6 Copyright (C) 2018 by Bernat Romagosa7 Copyright (C) 2015 by Jens Mönig8 This file is part of Snap!.9 Snap! is free software: you can redistribute it and/or modify10 it under the terms of the GNU Affero General Public License as11 published by the Free Software Foundation, either version 3 of12 the License, or (at your option) any later version.13 This program is distributed in the hope that it will be useful,14 but WITHOUT ANY WARRANTY; without even the implied warranty of15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 GNU Affero General Public License for more details.17 You should have received a copy of the GNU Affero General Public License18 along with this program. If not, see <http://www.gnu.org/licenses/>.19*/20// Global settings /////////////////////////////////////////////////////21// cloud.js should be able to exist indepent of Snap!22// (The module date is included for simplicity, but is not needed elsewhere.)23/*global modules, hex_sha512*/24modules = modules || {};25modules.cloud = '2021-February-04';26// Global stuff27var Cloud;28// Cloud /////////////////////////////////////////////////////////////29function Cloud() {30 this.init();31}32Cloud.prototype.init = function () {33 this.apiBasePath = '/api/v1';34 this.url = this.determineCloudDomain() + this.apiBasePath;35 this.username = null;36 this.disabled = false;37};38Cloud.prototype.disable = function () {39 this.disabled = true;40 this.username = null;41};42// Projects larger than this are rejected.43Cloud.MAX_FILE_SIZE = 10 * 1024 * 1024;44Cloud.prototype.knownDomains = {45 'Snap!Cloud' : 'https://snap.berkeley.edu',46 'Snap!Cloud (cs10)' : 'https://snap-cloud.cs10.org',47 'Snap!Cloud (staging)': 'https://snap-staging.cs10.org',48 'localhost': 'http://localhost:8080',49 'localhost (secure)': 'https://localhost:4431'50};51Cloud.prototype.defaultDomain = Cloud.prototype.knownDomains['Snap!Cloud'];52Cloud.prototype.determineCloudDomain = function () {53 // We dynamically determine the domain of the cloud server.54 // This allows for easy mirrors and development servers.55 // The domain is determined by:56 // 1. <meta name='snap-cloud-domain' location="X"> in snap.html.57 // 2. The current page's domain58 var currentDomain = window.location.host, // host includes the port.59 metaTag = document.head.querySelector("[name='snap-cloud-domain']"),60 cloudDomain = this.defaultDomain,61 domainMap = this.knownDomains;62 if (metaTag) { return metaTag.getAttribute('location'); }63 Object.keys(domainMap).some(function (name) {64 var server = domainMap[name];65 if (Cloud.isMatchingDomain(currentDomain, server)) {66 cloudDomain = server;67 return true;68 }69 return false;70 });71 return cloudDomain;72};73Cloud.isMatchingDomain = function (client, server) {74 // A matching domain means that the client-server are not subject to75 // 3rd party cookie restrictions.76 // see https://tools.ietf.org/html/rfc6265#section-5.1.377 // This matches a domain at end of a subdomain URL.78 var position = server.indexOf(client);79 switch (position) {80 case -1:81 return false;82 case 0:83 return client === server;84 default:85 return /[\.\/]/.test(server[position - 1]) &&86 server.length === position + client.length;87 }88};89// Dictionary handling90Cloud.prototype.parseDict = function (src) {91 var dict = {};92 if (!src) {return dict; }93 src.split("&").forEach(function (entry) {94 var pair = entry.split("="),95 key = decodeURIComponent(pair[0]),96 val = decodeURIComponent(pair[1]);97 dict[key] = val;98 });99 return dict;100};101Cloud.prototype.encodeDict = function (dict) {102 var str = '',103 pair,104 key;105 if (!dict) {return null; }106 for (key in dict) {107 if (dict.hasOwnProperty(key)) {108 pair = encodeURIComponent(key)109 + '='110 + encodeURIComponent(dict[key]);111 if (str.length > 0) {112 str += '&';113 }114 str += pair;115 }116 }117 return str;118};119// Error handling120Cloud.genericErrorMessage =121 'There was an error while trying to access\n' +122 'a Snap!Cloud service. Please try again later.';123Cloud.prototype.genericError = function () {124 throw new Error(Cloud.genericErrorMessage);125};126// Low level functionality127Cloud.prototype.request = function (128 method,129 path,130 onSuccess,131 onError,132 errorMsg,133 wantsRawResponse,134 body) {135 if (this.disabled) { return; }136 var request = new XMLHttpRequest(),137 myself = this,138 fullPath = this.url +139 (path.indexOf('%username') > -1 ?140 path.replace('%username', encodeURIComponent(this.username)) :141 path);142 try {143 request.open(144 method,145 fullPath,146 true147 );148 request.setRequestHeader(149 'Content-Type',150 'application/json; charset=utf-8'151 );152 request.withCredentials = true;153 request.onreadystatechange = function () {154 if (request.readyState === 4) {155 if (request.responseText) {156 var response =157 (!wantsRawResponse ||158 (request.responseText.indexOf('{"errors"') === 0)) ?159 JSON.parse(request.responseText) :160 request.responseText;161 if (response.errors) {162 onError.call(163 null,164 response.errors[0],165 errorMsg166 );167 } else {168 if (onSuccess) {169 onSuccess.call(null, response.message || response);170 }171 }172 } else {173 if (onError) {174 onError.call(175 null,176 errorMsg || Cloud.genericErrorMessage,177 myself.url178 );179 } else {180 myself.genericError();181 }182 }183 }184 };185 request.send(body);186 } catch (err) {187 onError.call(this, err.toString(), 'Cloud Error');188 }189};190Cloud.prototype.withCredentialsRequest = function (191 method,192 path,193 onSuccess,194 onError,195 errorMsg,196 wantsRawResponse,197 body) {198 var myself = this;199 this.checkCredentials(200 function (username) {201 if (username) {202 myself.request(203 method,204 // %username is replaced by the actual username205 path,206 onSuccess,207 onError,208 errorMsg,209 wantsRawResponse,210 body);211 } else {212 onError.call(this, 'You are not logged in', 'Snap!Cloud');213 }214 }215 );216};217// Credentials management218Cloud.prototype.initSession = function (onSuccess) {219 var myself = this;220 if (location.protocol === 'file:') {221 // disabled for now (jens)222 return;223 }224 this.request(225 'POST',226 '/init',227 function () { myself.checkCredentials(onSuccess); },228 function () {},229 null,230 true231 );232};233Cloud.prototype.checkCredentials = function (onSuccess, onError, response) {234 var myself = this;235 this.getCurrentUser(236 function (user) {237 if (user.username) {238 myself.username = user.username;239 myself.verified = user.verified;240 }241 if (onSuccess) {242 onSuccess.call(243 null,244 user.username,245 user.role,246 response ? JSON.parse(response) : null247 );248 }249 },250 onError251 );252};253Cloud.prototype.getCurrentUser = function (onSuccess, onError) {254 this.request(255 'GET',256 '/users/c',257 onSuccess,258 onError,259 'Could not retrieve current user'260 );261};262Cloud.prototype.getUser = function (username, onSuccess, onError) {263 this.request(264 'GET',265 '/users/' + encodeURIComponent(username),266 onSuccess,267 onError,268 'Could not retrieve user'269 );270};271Cloud.prototype.logout = function (onSuccess, onError) {272 this.username = null;273 this.request(274 'POST',275 '/logout',276 onSuccess,277 onError,278 'logout failed'279 );280};281Cloud.prototype.login = function (282 username,283 password,284 persist,285 onSuccess,286 onError287) {288 var myself = this;289 this.request(290 'POST',291 '/users/' + encodeURIComponent(username) + '/login?' +292 this.encodeDict({293 persist: persist294 }),295 function (response) {296 myself.checkCredentials(onSuccess, onError, response);297 },298 onError,299 'login failed',300 'false', // wants raw response301 hex_sha512(password) // password travels inside the body302 );303};304Cloud.prototype.signup = function (305 username,306 password,307 passwordRepeat,308 email,309 onSuccess,310 onError311) {312 this.request(313 'POST',314 '/users/' + encodeURIComponent(username.trim()) + '?' + this.encodeDict({315 email: email,316 password: hex_sha512(password),317 password_repeat: hex_sha512(passwordRepeat)318 }),319 onSuccess,320 onError,321 'signup failed');322};323Cloud.prototype.changePassword = function (324 password,325 newPassword,326 passwordRepeat,327 onSuccess,328 onError329) {330 this.withCredentialsRequest(331 'POST',332 '/users/%username/newpassword?' + this.encodeDict({333 oldpassword: hex_sha512(password),334 password_repeat: hex_sha512(passwordRepeat),335 newpassword: hex_sha512(newPassword)336 }),337 onSuccess,338 onError,339 'Could not change password'340 );341};342Cloud.prototype.resetPassword = function (username, onSuccess, onError) {343 this.request(344 'POST',345 '/users/' + encodeURIComponent(username) + '/password_reset',346 onSuccess,347 onError,348 'Password reset request failed'349 );350};351Cloud.prototype.resendVerification = function (username, onSuccess, onError) {352 this.request(353 'POST',354 '/users/' + encodeURIComponent(username) + '/resendverification',355 onSuccess,356 onError,357 'Could not send verification email'358 );359};360// Projects361Cloud.prototype.saveProject = function (projectName, body, onSuccess, onError) {362 // Expects a body object with the following paramters:363 // xml, media, thumbnail, remixID (optional), notes (optional)364 var myself = this;365 this.checkCredentials(366 function (username) {367 if (username) {368 myself.request(369 'POST',370 '/projects/' +371 encodeURIComponent(username) +372 '/' +373 encodeURIComponent(projectName),374 onSuccess,375 onError,376 'Project could not be saved',377 false,378 JSON.stringify(body) // POST body379 );380 } else {381 onError.call(this, 'You are not logged in', 'Snap!Cloud');382 }383 }384 );385};386Cloud.prototype.getProjectList = function (onSuccess, onError, withThumbnail) {387 var path = '/projects/%username?updatingnotes=true';388 if (withThumbnail) {389 path += '&withthumbnail=true';390 }391 this.withCredentialsRequest(392 'GET',393 path,394 onSuccess,395 onError,396 'Could not fetch projects'397 );398};399Cloud.prototype.getPublishedProjectList = function (400 username,401 page,402 pageSize,403 searchTerm,404 onSuccess,405 onError,406 withThumbnail407) {408 var path = '/projects' +409 (username ? '/' + encodeURIComponent(username) : '') +410 '?ispublished=true';411 if (!username) {412 // When requesting the global list of published projects, filter out413 // those with project names that are typical of online courses like414 // Teals or BJC. When requesting a user's published projects, show them415 // all.416 path += '&filtered=true';417 }418 if (withThumbnail) {419 path += '&withthumbnail=true';420 }421 if (page) {422 path += '&page=' + page + '&pagesize=' + (pageSize || 16);423 }424 if (searchTerm) {425 path += '&matchtext=' + encodeURIComponent(searchTerm);426 }427 this.request(428 'GET',429 path,430 onSuccess,431 onError,432 'Could not fetch projects'433 );434};435Cloud.prototype.getThumbnail = function (436 username,437 projectName,438 onSuccess,439 onError440) {441 this[username ? 'request' : 'withCredentialsRequest'](442 'GET',443 '/projects/' +444 (username ? encodeURIComponent(username) : '%username') +445 '/' +446 encodeURIComponent(projectName) +447 '/thumbnail',448 onSuccess,449 onError,450 'Could not fetch thumbnail',451 true452 );453};454Cloud.prototype.getProject = function (projectName, delta, onSuccess, onError) {455 this.withCredentialsRequest(456 'GET',457 '/projects/%username/' +458 encodeURIComponent(projectName) +459 (delta ? '?delta=' + delta : ''),460 onSuccess,461 onError,462 'Could not fetch project ' + projectName,463 true464 );465};466Cloud.prototype.getPublicProject = function (467 projectName,468 username,469 onSuccess,470 onError471) {472 this.request(473 'GET',474 '/projects/' +475 encodeURIComponent(username) +476 '/' +477 encodeURIComponent(projectName),478 onSuccess,479 onError,480 'Could not fetch project ' + projectName,481 true482 );483};484Cloud.prototype.getProjectMetadata = function (485 projectName,486 username,487 onSuccess,488 onError489) {490 this.request(491 'GET',492 '/projects/' +493 encodeURIComponent(username) +494 '/' +495 encodeURIComponent(projectName) +496 '/metadata',497 onSuccess,498 onError,499 'Could not fetch metadata for ' + projectName500 );501};502Cloud.prototype.getProjectVersionMetadata = function (503 projectName,504 onSuccess,505 onError506) {507 this.withCredentialsRequest(508 'GET',509 '/projects/%username/' +510 encodeURIComponent(projectName) +511 '/versions',512 onSuccess,513 onError,514 'Could not fetch versions for project ' + projectName515 );516};517Cloud.prototype.getRemixes = function (518 username,519 projectName,520 page,521 pageSize,522 onSuccess,523 onError524) {525 var path = '/projects/' +526 encodeURIComponent(username) + '/' +527 encodeURIComponent(projectName) + '/remixes';528 if (page) {529 path += '?page=' + page + '&pagesize=' + (pageSize || 16);530 }531 this.request(532 'GET',533 path,534 onSuccess,535 onError,536 'Could not fetch remixes for project ' + projectName537 );538};539Cloud.prototype.deleteProject = function (540 projectName,541 username,542 onSuccess,543 onError544) {545 this[username ? 'request' : 'withCredentialsRequest'](546 'DELETE',547 '/projects/' +548 (username ? encodeURIComponent(username) : '%username') +549 '/' +550 encodeURIComponent(projectName),551 onSuccess,552 onError,553 'Could not delete project'554 );555};556Cloud.prototype.shareProject = function (557 projectName,558 username,559 onSuccess,560 onError561) {562 this[username ? 'request' : 'withCredentialsRequest'](563 'POST',564 '/projects/' +565 (username ? encodeURIComponent(username) : '%username') +566 '/' +567 encodeURIComponent(projectName) +568 '/metadata?ispublic=true',569 onSuccess,570 onError,571 'Could not share project'572 );573};574Cloud.prototype.unshareProject = function (575 projectName,576 username,577 onSuccess,578 onError579) {580 this[username ? 'request' : 'withCredentialsRequest'](581 'POST',582 '/projects/' +583 (username ? encodeURIComponent(username) : '%username') +584 '/' +585 encodeURIComponent(projectName) +586 '/metadata?ispublic=false&ispublished=false',587 onSuccess,588 onError,589 'Could not unshare project'590 );591};592Cloud.prototype.publishProject = function (593 projectName,594 username,595 onSuccess,596 onError597) {598 this[username ? 'request' : 'withCredentialsRequest'](599 'POST',600 '/projects/' +601 (username ? encodeURIComponent(username) : '%username') +602 '/' +603 encodeURIComponent(projectName) +604 '/metadata?ispublished=true',605 onSuccess,606 onError,607 'Could not publish project'608 );609};610Cloud.prototype.unpublishProject = function (611 projectName,612 username,613 onSuccess,614 onError615) {616 this[username ? 'request' : 'withCredentialsRequest'](617 'POST',618 '/projects/' +619 (username ? encodeURIComponent(username) : '%username') +620 '/' +621 encodeURIComponent(projectName) +622 '/metadata?ispublished=false',623 onSuccess,624 onError,625 'Could not unpublish project'626 );627};628Cloud.prototype.updateNotes = function (629 projectName,630 notes,631 onSuccess,632 onError633) {634 this.withCredentialsRequest(635 'POST',636 '/projects/%username/' +637 encodeURIComponent(projectName) +638 '/metadata',639 onSuccess,640 onError,641 'Could not update project notes',642 false, // wants raw response643 JSON.stringify({ notes: notes })644 );645};646Cloud.prototype.updateProjectName = function (647 projectName,648 newName,649 onSuccess,650 onError651) {652 this.withCredentialsRequest(653 'POST',654 '/projects/%username/' +655 encodeURIComponent(projectName) +656 '/metadata',657 onSuccess,658 onError,659 'Could not update project name',660 false, // wants raw response661 JSON.stringify({ projectname: newName })662 );663};664// Collections665Cloud.prototype.newCollection = function (666 collectionName,667 onSuccess,668 onError669) {670 this.withCredentialsRequest(671 'POST',672 '/users/%username/collections/' + encodeURIComponent(collectionName),673 onSuccess,674 onError,675 'Could not create collection'676 );677};678Cloud.prototype.getCollectionMetadata = function (679 collectionUsername,680 collectionName,681 onSuccess,682 onError683) {684 this.request(685 'GET',686 '/users/' +687 (collectionUsername ?688 encodeURIComponent(collectionUsername) :689 '%username') +690 '/collections/' + encodeURIComponent(collectionName) +691 '/metadata',692 onSuccess,693 onError,694 'Could not fetch metadata for ' + collectionName695 );696};697Cloud.prototype.getCollectionProjects = function (698 collectionUsername,699 page,700 pageSize,701 collectionName,702 onSuccess,703 onError,704 withThumbnail705) {706 var path = '/users/' +707 (collectionUsername ?708 encodeURIComponent(collectionUsername) :709 '%username') +710 '/collections/' + encodeURIComponent(collectionName) +711 '/projects';712 if (page) {713 path += '?page=' + page + '&pagesize=' + (pageSize || 16);714 }715 if (withThumbnail) {716 path += (page ? '&' : '?') + 'withthumbnail=true';717 }718 this.request(719 'GET',720 path,721 onSuccess,722 onError,723 'Could not fetch projects'724 );725};726Cloud.prototype.setCollectionThumbnail = function (727 collectionUsername,728 collectionName,729 thumbnailId,730 onSuccess,731 onError732) {733 this.withCredentialsRequest(734 'POST',735 '/users/' + encodeURIComponent(collectionUsername) +736 '/collections/' + encodeURIComponent(collectionName) +737 '/thumbnail?id=' + encodeURIComponent(thumbnailId),738 onSuccess,739 onError,740 'Could not set project thumbnail'741 );742};743Cloud.prototype.updateCollectionDescription = function (744 collectionUsername,745 collectionName,746 description,747 onSuccess,748 onError749) {750 this.withCredentialsRequest(751 'POST',752 '/users/' + encodeURIComponent(collectionUsername) +753 '/collections/' + encodeURIComponent(collectionName) +754 '/metadata',755 onSuccess,756 onError,757 'Could not update collection description',758 false, // wants raw response759 JSON.stringify({ description: description })760 );761};762Cloud.prototype.updateCollectionName = function (763 collectionUsername,764 collectionName,765 newName,766 onSuccess,767 onError768) {769 this.withCredentialsRequest(770 'POST',771 '/users/' + encodeURIComponent(collectionUsername) +772 '/collections/' + encodeURIComponent(collectionName) +773 '/metadata',774 onSuccess,775 onError,776 'Could not update collection name',777 false, // wants raw response778 JSON.stringify({ name: newName })779 );780};781Cloud.prototype.shareCollection = function (782 collectionUsername,783 collectionName,784 onSuccess,785 onError786) {787 this.withCredentialsRequest(788 'POST',789 '/users/' + encodeURIComponent(collectionUsername) +790 '/collections/' + encodeURIComponent(collectionName) +791 '/metadata?shared=true',792 onSuccess,793 onError,794 'Could not share collection'795 );796};797Cloud.prototype.unshareCollection = function (798 collectionUsername,799 collectionName,800 onSuccess,801 onError802) {803 this.withCredentialsRequest(804 'POST',805 '/users/' + encodeURIComponent(collectionUsername) +806 '/collections/' + encodeURIComponent(collectionName) +807 '/metadata?shared=false&published=false',808 onSuccess,809 onError,810 'Could not unshare collection'811 );812};813Cloud.prototype.publishCollection = function (814 collectionUsername,815 collectionName,816 onSuccess,817 onError818) {819 this.withCredentialsRequest(820 'POST',821 '/users/' + encodeURIComponent(collectionUsername) +822 '/collections/' + encodeURIComponent(collectionName) +823 '/metadata?published=true',824 onSuccess,825 onError,826 'Could not publish collection'827 );828};829Cloud.prototype.unpublishCollection = function (830 collectionUsername,831 collectionName,832 onSuccess,833 onError834) {835 this.withCredentialsRequest(836 'POST',837 '/users/' + encodeURIComponent(collectionUsername) +838 '/collections/' + encodeURIComponent(collectionName) +839 '/metadata?published=false',840 onSuccess,841 onError,842 'Could not unpublish collection'843 );844};845Cloud.prototype.addProjectToCollection = function (846 collectionUsername,847 collectionName,848 projectUsername,849 projectName,850 onSuccess,851 onError852) {853 this.withCredentialsRequest(854 'POST',855 '/users/' + encodeURIComponent(collectionUsername) +856 '/collections/' + encodeURIComponent(collectionName) +857 '/projects',858 onSuccess,859 onError,860 'Could not add project to collection',861 false, // wants raw response862 JSON.stringify({863 username: projectUsername,864 projectname: projectName865 })866 );867};868Cloud.prototype.removeProjectFromCollection = function (869 collectionUsername,870 collectionName,871 projectId,872 onSuccess,873 onError874) {875 this.withCredentialsRequest(876 'DELETE',877 '/users/' + encodeURIComponent(collectionUsername) +878 '/collections/' + encodeURIComponent(collectionName) +879 '/projects/' + encodeURIComponent(projectId),880 onSuccess,881 onError,882 'Could not remove project from collection'883 );884};885Cloud.prototype.getUserCollections = function (886 collectionUsername,887 page,888 pageSize,889 searchTerm,890 onSuccess,891 onError892) {893 this[(collectionUsername !== this.username) ?894 'request' :895 'withCredentialsRequest'](896 'GET',897 '/users/' +898 (collectionUsername ?899 encodeURIComponent(collectionUsername) :900 '%username') +901 '/collections?' +902 this.encodeDict(903 page > 0 ?904 {905 page: page,906 pagesize: pageSize || 16,907 matchtext:908 searchTerm ? encodeURIComponent(searchTerm) : ''909 } : {}910 ),911 onSuccess,912 onError,913 'Could not fetch collections'914 );915};916Cloud.prototype.getCollectionsContainingProject = function (917 username,918 projectName,919 page,920 pageSize,921 onSuccess,922 onError923) {924 var path = '/projects/' +925 encodeURIComponent(username) + '/' +926 encodeURIComponent(projectName) + '/collections';927 if (page) {928 path += '?page=' + page + '&pagesize=' + (pageSize || 16);929 }930 this.request(931 'GET',932 path,933 onSuccess,934 onError,935 'Could not fetch collections for project ' + projectName936 );937};938Cloud.prototype.getCollections = function (939 page,940 pageSize,941 searchTerm,942 onSuccess,943 onError944) {945 var dict = {946 page: page,947 pagesize: page ? pageSize || 16 : '',948 };949 if (searchTerm) { dict.matchtext = encodeURIComponent(searchTerm); }950 this.request(951 'GET',952 '/collections?' + this.encodeDict(dict),953 onSuccess,954 onError,955 'Could not fetch collections'956 );957};958Cloud.prototype.deleteCollection = function (959 collectionUsername,960 collectionName,961 onSuccess,962 onError963) {964 this.withCredentialsRequest(965 'DELETE',966 '/users/' + encodeURIComponent(collectionUsername) +967 '/collections/' + encodeURIComponent(collectionName),968 onSuccess,969 onError,970 'Could not remove collection'971 );972};973Cloud.prototype.addEditorToCollection = function (974 collectionUsername,975 collectionName,976 editorUsername,977 onSuccess,978 onError979) {980 this.withCredentialsRequest(981 'POST',982 '/users/' + encodeURIComponent(collectionUsername) +983 '/collections/' + encodeURIComponent(collectionName) +984 '/editors',985 onSuccess,986 onError,987 'Could not add editor to collection',988 false, // wants raw response989 JSON.stringify({990 editor_username: editorUsername,991 })992 );993};994Cloud.prototype.removeEditorFromCollection = function (995 collectionUsername,996 collectionName,997 editorUsername,998 onSuccess,999 onError1000) {1001 this.withCredentialsRequest(1002 'DELETE',1003 '/users/' + encodeURIComponent(collectionUsername) +1004 '/collections/' + encodeURIComponent(collectionName) +1005 '/editors/' + encodeURIComponent(editorUsername),1006 onSuccess,1007 onError,1008 'Could not remove editor from collection'1009 );1010};1011// Paths to front-end pages1012/*1013 This list of paths is incomplete, we will add them as necessary.1014 Important: a path is a string *without* a domain.1015 These paths are not prefixed by `apiBasePath`.1016*/1017Cloud.prototype.showProjectPath = function (username, projectname) {1018 return '/project?' + this.encodeDict({1019 user: username,1020 project: projectname1021 });...

Full Screen

Full Screen

test_autoIncrement.js

Source:test_autoIncrement.js Github

copy

Full Screen

1/**2 * Any copyright is dedicated to the Public Domain.3 * http://creativecommons.org/publicdomain/zero/1.0/4 */5if (!this.window) {6 this.runTest = function() {7 todo(false, "Test disabled in xpcshell test suite for now");8 finishTest();9 }10}11var testGenerator = testSteps();12function genCheck(key, value, test, options) {13 return function(event) {14 is(JSON.stringify(event.target.result), JSON.stringify(key),15 "correct returned key in " + test);16 if (options && options.store) {17 is(event.target.source, options.store, "correct store in " + test);18 }19 if (options && options.trans) {20 is(event.target.transaction, options.trans, "correct transaction in " + test);21 }22 event.target.source.get(key).onsuccess = function(event) {23 is(JSON.stringify(event.target.result), JSON.stringify(value),24 "correct stored value in " + test);25 continueToNextStepSync();26 }27 }28}29function testSteps()30{31 const dbname = this.window ? window.location.pathname : "Splendid Test";32 const RW = "readwrite";33 let c1 = 1;34 let c2 = 1;35 let openRequest = indexedDB.open(dbname, 1);36 openRequest.onerror = errorHandler;37 openRequest.onupgradeneeded = grabEventAndContinueHandler;38 openRequest.onsuccess = unexpectedSuccessHandler;39 let event = yield undefined;40 let db = event.target.result;41 let trans = event.target.transaction;42 // Create test stores43 let store1 = db.createObjectStore("store1", { autoIncrement: true });44 let store2 = db.createObjectStore("store2", { autoIncrement: true, keyPath: "id" });45 let store3 = db.createObjectStore("store3", { autoIncrement: false });46 is(store1.autoIncrement, true, "store1 .autoIncrement");47 is(store2.autoIncrement, true, "store2 .autoIncrement");48 is(store3.autoIncrement, false, "store3 .autoIncrement");49 store1.createIndex("unique1", "unique", { unique: true });50 store2.createIndex("unique1", "unique", { unique: true });51 // Test simple inserts52 let test = " for test simple insert"53 store1.add({ foo: "value1" }).onsuccess =54 genCheck(c1++, { foo: "value1" }, "first" + test);55 store1.add({ foo: "value2" }).onsuccess =56 genCheck(c1++, { foo: "value2" }, "second" + test);57 yield undefined;58 yield undefined;59 store2.put({ bar: "value1" }).onsuccess =60 genCheck(c2, { bar: "value1", id: c2 }, "first in store2" + test,61 { store: store2 });62 c2++;63 store1.put({ foo: "value3" }).onsuccess =64 genCheck(c1++, { foo: "value3" }, "third" + test,65 { store: store1 });66 yield undefined;67 yield undefined;68 store2.get(IDBKeyRange.lowerBound(c2)).onsuccess = grabEventAndContinueHandler;69 event = yield undefined;70 is(event.target.result, undefined, "no such value" + test);71 // Close version_change transaction72 openRequest.onsuccess = grabEventAndContinueHandler;73 event = yield undefined;74 is(event.target, openRequest, "succeeded to open" + test);75 is(event.type, "success", "succeeded to open" + test);76 // Test inserting explicit keys77 test = " for test explicit keys";78 trans = db.transaction("store1", RW);79 trans.objectStore("store1").add({ explicit: 1 }, 100).onsuccess =80 genCheck(100, { explicit: 1 }, "first" + test);81 c1 = 101;82 trans = db.transaction("store1", RW);83 trans.objectStore("store1").add({ explicit: 2 }).onsuccess =84 genCheck(c1++, { explicit: 2 }, "second" + test);85 yield undefined; yield undefined;86 trans = db.transaction("store1", RW);87 trans.objectStore("store1").add({ explicit: 3 }, 200).onsuccess =88 genCheck(200, { explicit: 3 }, "third" + test);89 c1 = 201;90 trans.objectStore("store1").add({ explicit: 4 }).onsuccess =91 genCheck(c1++, { explicit: 4 }, "fourth" + test);92 yield undefined; yield undefined;93 trans = db.transaction("store1", RW);94 trans.objectStore("store1").add({ explicit: 5 }, 150).onsuccess =95 genCheck(150, { explicit: 5 }, "fifth" + test);96 yield undefined;97 trans.objectStore("store1").add({ explicit: 6 }).onsuccess =98 genCheck(c1++, { explicit: 6 }, "sixth" + test);99 yield undefined;100 trans = db.transaction("store1", RW);101 trans.objectStore("store1").add({ explicit: 7 }, "key").onsuccess =102 genCheck("key", { explicit: 7 }, "seventh" + test);103 yield undefined;104 trans.objectStore("store1").add({ explicit: 8 }).onsuccess =105 genCheck(c1++, { explicit: 8 }, "eighth" + test);106 yield undefined;107 trans = db.transaction("store1", RW);108 trans.objectStore("store1").add({ explicit: 7 }, [100000]).onsuccess =109 genCheck([100000], { explicit: 7 }, "seventh" + test);110 yield undefined;111 trans.objectStore("store1").add({ explicit: 8 }).onsuccess =112 genCheck(c1++, { explicit: 8 }, "eighth" + test);113 yield undefined;114 trans = db.transaction("store1", RW);115 trans.objectStore("store1").add({ explicit: 9 }, -100000).onsuccess =116 genCheck(-100000, { explicit: 9 }, "ninth" + test);117 yield undefined;118 trans.objectStore("store1").add({ explicit: 10 }).onsuccess =119 genCheck(c1++, { explicit: 10 }, "tenth" + test);120 yield undefined;121 trans = db.transaction("store2", RW);122 trans.objectStore("store2").add({ explicit2: 1, id: 300 }).onsuccess =123 genCheck(300, { explicit2: 1, id: 300 }, "first store2" + test);124 c2 = 301;125 trans = db.transaction("store2", RW);126 trans.objectStore("store2").add({ explicit2: 2 }).onsuccess =127 genCheck(c2, { explicit2: 2, id: c2 }, "second store2" + test);128 c2++;129 yield undefined; yield undefined;130 trans = db.transaction("store2", RW);131 trans.objectStore("store2").add({ explicit2: 3, id: 400 }).onsuccess =132 genCheck(400, { explicit2: 3, id: 400 }, "third store2" + test);133 c2 = 401;134 trans.objectStore("store2").add({ explicit2: 4 }).onsuccess =135 genCheck(c2, { explicit2: 4, id: c2 }, "fourth store2" + test);136 c2++;137 yield undefined; yield undefined;138 trans = db.transaction("store2", RW);139 trans.objectStore("store2").add({ explicit: 5, id: 150 }).onsuccess =140 genCheck(150, { explicit: 5, id: 150 }, "fifth store2" + test);141 yield undefined;142 trans.objectStore("store2").add({ explicit: 6 }).onsuccess =143 genCheck(c2, { explicit: 6, id: c2 }, "sixth store2" + test);144 c2++;145 yield undefined;146 trans = db.transaction("store2", RW);147 trans.objectStore("store2").add({ explicit: 7, id: "key" }).onsuccess =148 genCheck("key", { explicit: 7, id: "key" }, "seventh store2" + test);149 yield undefined;150 trans.objectStore("store2").add({ explicit: 8 }).onsuccess =151 genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);152 c2++;153 yield undefined;154 trans = db.transaction("store2", RW);155 trans.objectStore("store2").add({ explicit: 7, id: [100000] }).onsuccess =156 genCheck([100000], { explicit: 7, id: [100000] }, "seventh store2" + test);157 yield undefined;158 trans.objectStore("store2").add({ explicit: 8 }).onsuccess =159 genCheck(c2, { explicit: 8, id: c2 }, "eighth store2" + test);160 c2++;161 yield undefined;162 trans = db.transaction("store2", RW);163 trans.objectStore("store2").add({ explicit: 9, id: -100000 }).onsuccess =164 genCheck(-100000, { explicit: 9, id: -100000 }, "ninth store2" + test);165 yield undefined;166 trans.objectStore("store2").add({ explicit: 10 }).onsuccess =167 genCheck(c2, { explicit: 10, id: c2 }, "tenth store2" + test);168 c2++;169 yield undefined;170 // Test separate transactions doesn't generate overlapping numbers171 test = " for test non-overlapping counts";172 trans = db.transaction("store1", RW);173 trans2 = db.transaction("store1", RW);174 trans2.objectStore("store1").put({ over: 2 }).onsuccess =175 genCheck(c1 + 1, { over: 2 }, "first" + test,176 { trans: trans2 });177 trans.objectStore("store1").put({ over: 1 }).onsuccess =178 genCheck(c1, { over: 1 }, "second" + test,179 { trans: trans });180 c1 += 2;181 yield undefined; yield undefined;182 trans = db.transaction("store2", RW);183 trans2 = db.transaction("store2", RW);184 trans2.objectStore("store2").put({ over: 2 }).onsuccess =185 genCheck(c2 + 1, { over: 2, id: c2 + 1 }, "third" + test,186 { trans: trans2 });187 trans.objectStore("store2").put({ over: 1 }).onsuccess =188 genCheck(c2, { over: 1, id: c2 }, "fourth" + test,189 { trans: trans });190 c2 += 2;191 yield undefined; yield undefined;192 // Test that error inserts doesn't increase generator193 test = " for test error inserts";194 trans = db.transaction(["store1", "store2"], RW);195 trans.objectStore("store1").add({ unique: 1 }, -1);196 trans.objectStore("store2").add({ unique: 1, id: "unique" });197 trans.objectStore("store1").add({ error: 1, unique: 1 }).198 addEventListener("error", new ExpectError("ConstraintError", true));199 trans.objectStore("store1").add({ error: 2 }).onsuccess =200 genCheck(c1++, { error: 2 }, "first" + test);201 yield undefined; yield undefined;202 trans.objectStore("store2").add({ error: 3, unique: 1 }).203 addEventListener("error", new ExpectError("ConstraintError", true));204 trans.objectStore("store2").add({ error: 4 }).onsuccess =205 genCheck(c2, { error: 4, id: c2 }, "second" + test);206 c2++;207 yield undefined; yield undefined;208 trans.objectStore("store1").add({ error: 5, unique: 1 }, 100000).209 addEventListener("error", new ExpectError("ConstraintError", true));210 trans.objectStore("store1").add({ error: 6 }).onsuccess =211 genCheck(c1++, { error: 6 }, "third" + test);212 yield undefined; yield undefined;213 trans.objectStore("store2").add({ error: 7, unique: 1, id: 100000 }).214 addEventListener("error", new ExpectError("ConstraintError", true));215 trans.objectStore("store2").add({ error: 8 }).onsuccess =216 genCheck(c2, { error: 8, id: c2 }, "fourth" + test);217 c2++;218 yield undefined; yield undefined;219 // Test that aborts doesn't increase generator220 test = " for test aborted transaction";221 trans = db.transaction(["store1", "store2"], RW);222 trans.objectStore("store1").add({ abort: 1 }).onsuccess =223 genCheck(c1, { abort: 1 }, "first" + test);224 trans.objectStore("store2").put({ abort: 2 }).onsuccess =225 genCheck(c2, { abort: 2, id: c2 }, "second" + test);226 yield undefined; yield undefined;227 trans.objectStore("store1").add({ abort: 3 }, 500).onsuccess =228 genCheck(500, { abort: 3 }, "third" + test);229 trans.objectStore("store2").put({ abort: 4, id: 600 }).onsuccess =230 genCheck(600, { abort: 4, id: 600 }, "fourth" + test);231 yield undefined; yield undefined;232 trans.objectStore("store1").add({ abort: 5 }).onsuccess =233 genCheck(501, { abort: 5 }, "fifth" + test);234 trans.objectStore("store2").put({ abort: 6 }).onsuccess =235 genCheck(601, { abort: 6, id: 601 }, "sixth" + test);236 yield undefined; yield undefined;237 trans.abort();238 trans.onabort = grabEventAndContinueHandler;239 event = yield240 is(event.type, "abort", "transaction aborted");241 is(event.target, trans, "correct transaction aborted");242 trans = db.transaction(["store1", "store2"], RW);243 trans.objectStore("store1").add({ abort: 1 }).onsuccess =244 genCheck(c1++, { abort: 1 }, "re-first" + test);245 trans.objectStore("store2").put({ abort: 2 }).onsuccess =246 genCheck(c2, { abort: 2, id: c2 }, "re-second" + test);247 c2++;248 yield undefined; yield undefined;249 // Test that delete doesn't decrease generator250 test = " for test delete items"251 trans = db.transaction(["store1", "store2"], RW);252 trans.objectStore("store1").add({ delete: 1 }).onsuccess =253 genCheck(c1++, { delete: 1 }, "first" + test);254 trans.objectStore("store2").put({ delete: 2 }).onsuccess =255 genCheck(c2, { delete: 2, id: c2 }, "second" + test);256 c2++;257 yield undefined; yield undefined;258 trans.objectStore("store1").delete(c1 - 1).onsuccess =259 grabEventAndContinueHandler;260 trans.objectStore("store2").delete(c2 - 1).onsuccess =261 grabEventAndContinueHandler;262 yield undefined; yield undefined;263 trans.objectStore("store1").add({ delete: 3 }).onsuccess =264 genCheck(c1++, { delete: 3 }, "first" + test);265 trans.objectStore("store2").put({ delete: 4 }).onsuccess =266 genCheck(c2, { delete: 4, id: c2 }, "second" + test);267 c2++;268 yield undefined; yield undefined;269 trans.objectStore("store1").delete(c1 - 1).onsuccess =270 grabEventAndContinueHandler;271 trans.objectStore("store2").delete(c2 - 1).onsuccess =272 grabEventAndContinueHandler;273 yield undefined; yield undefined;274 trans = db.transaction(["store1", "store2"], RW);275 trans.objectStore("store1").add({ delete: 5 }).onsuccess =276 genCheck(c1++, { delete: 5 }, "first" + test);277 trans.objectStore("store2").put({ delete: 6 }).onsuccess =278 genCheck(c2, { delete: 6, id: c2 }, "second" + test);279 c2++;280 yield undefined; yield undefined;281 // Test that clears doesn't decrease generator282 test = " for test clear stores";283 trans = db.transaction(["store1", "store2"], RW);284 trans.objectStore("store1").add({ clear: 1 }).onsuccess =285 genCheck(c1++, { clear: 1 }, "first" + test);286 trans.objectStore("store2").put({ clear: 2 }).onsuccess =287 genCheck(c2, { clear: 2, id: c2 }, "second" + test);288 c2++;289 yield undefined; yield undefined;290 trans.objectStore("store1").clear().onsuccess =291 grabEventAndContinueHandler;292 trans.objectStore("store2").clear().onsuccess =293 grabEventAndContinueHandler;294 yield undefined; yield undefined;295 trans.objectStore("store1").add({ clear: 3 }).onsuccess =296 genCheck(c1++, { clear: 3 }, "third" + test);297 trans.objectStore("store2").put({ clear: 4 }).onsuccess =298 genCheck(c2, { clear: 4, id: c2 }, "forth" + test);299 c2++;300 yield undefined; yield undefined;301 trans.objectStore("store1").clear().onsuccess =302 grabEventAndContinueHandler;303 trans.objectStore("store2").clear().onsuccess =304 grabEventAndContinueHandler;305 yield undefined; yield undefined;306 trans = db.transaction(["store1", "store2"], RW);307 trans.objectStore("store1").add({ clear: 5 }).onsuccess =308 genCheck(c1++, { clear: 5 }, "fifth" + test);309 trans.objectStore("store2").put({ clear: 6 }).onsuccess =310 genCheck(c2, { clear: 6, id: c2 }, "sixth" + test);311 c2++;312 yield undefined; yield undefined;313 // Test that close/reopen doesn't decrease generator314 test = " for test clear stores";315 trans = db.transaction(["store1", "store2"], RW);316 trans.objectStore("store1").clear().onsuccess =317 grabEventAndContinueHandler;318 trans.objectStore("store2").clear().onsuccess =319 grabEventAndContinueHandler;320 yield undefined; yield undefined;321 db.close();322 SpecialPowers.gc();323 openRequest = indexedDB.open(dbname, 2);324 openRequest.onerror = errorHandler;325 openRequest.onupgradeneeded = grabEventAndContinueHandler;326 openRequest.onsuccess = unexpectedSuccessHandler;327 event = yield undefined;328 db = event.target.result;329 trans = event.target.transaction;330 trans.objectStore("store1").add({ reopen: 1 }).onsuccess =331 genCheck(c1++, { reopen: 1 }, "first" + test);332 trans.objectStore("store2").put({ reopen: 2 }).onsuccess =333 genCheck(c2, { reopen: 2, id: c2 }, "second" + test);334 c2++;335 yield undefined; yield undefined;336 openRequest.onsuccess = grabEventAndContinueHandler;337 yield undefined;338 finishTest();339 yield undefined;...

Full Screen

Full Screen

mc-controller.js

Source:mc-controller.js Github

copy

Full Screen

...88 * @param {function} onSuccess - a callback function with no arguments89 * @param {function} onFailure - a callback function with no arguments90 */91 function requestListOfWatches(onSuccess, onFailure) {92 requestJSON("api/watches/data/", (response) => onSuccess(response.watches), onFailure);93 }94 /**95 * @param {object} watch - a JS watch object as expected by the server API (object corresponds to java class WatchData)96 * @param {function} onSuccess - a callback function with no arguments97 * @param {function} onFailure - a callback function with no arguments98 */99 function requestCreateWatch(watch, onSuccess, onFailure) {100 requestWithJsonBody('PUT', 'api/watches/data/', watch, onSuccess, onFailure);101 }102 /**103 * @param {string} name - name of the watch to delete104 * @param {function} onSuccess - a callback function with no arguments105 * @param {function} onFailure - a callback function with no arguments106 */...

Full Screen

Full Screen

DocumentServiceProxy.js

Source:DocumentServiceProxy.js Github

copy

Full Screen

...5 var GET = function(url, data, onSuccess, onFail){6 $.get(baseUrl + url, data)7 .done(function (data) {8 if (onSuccess) {9 onSuccess(data);10 }11 })12 .fail(function(jqXHR, textStatus, errorThrown){13 if (onFail) {14 onFail(textStatus);15 } else {16 throw "Error occurred on call to server. " + textStatus + " " + errorThrown;17 } 18 });19 };20 var POST = function(url, data, onSuccess, onFail){21 var options = {};22 if (data != null)23 {24 var payload = '';25 if (data.toJS){26 payload = data.toJS();27 }28 else{29 payload = data;30 }31 options = {32 url: baseUrl + url, 33 type: "POST",34 data: JSON.stringify(payload),35 dataType: "json",36 contentType: "application/json"37 }38 }39 else40 {41 options = {42 url: baseUrl + url, 43 type: "POST",44 dataType: "json"45 }46 }47 48 $.ajax(options)49 .done(function (data) {50 if (onSuccess) {51 onSuccess(data);52 }53 })54 .fail(function(jqXHR, textStatus, errorThrown){55 if (onFail) {56 onFail(textStatus, errorThrown, jqXHR.status);57 } else {58 throw "Error occurred on call to server. " + textStatus + " " + errorThrown;59 } 60 });61 };62 //users/login63 self.Login = function (userId, password, onSuccess, onFail) {64 var obj = { userId: userId, password: password };65 POST("/users/login", obj, onSuccess, function(textStatus, errorText, status){66 if(status == "401")67 bootbox.alert("Login failed for user " + userId, function(){68 window.close();69 });70 else71 bootbox.alert("Login failed with error: " + textStatus + "\n" + errorText, function(){72 window.close();73 });74 });75 };76//documents/sections/77 self.RetrieveAndLockSection = function (document, sectionName, overrideLock, onLockGranted, onLockDenied, onFailure) {78 docRequest = { DocumentId: document._id, SectionName: sectionName, OverrideLock: overrideLock }; 79 if (_.isUndefined(document._id) || document.DocumentInfo.Status !== SEE.enum.DocumentStatusCode.DRAFT) { //new document, never saved or finalized/sent doc not able to change80 var lock = new SEE.model.dto.SectionLockInfo();81 lock.LockedBy = SEE.session.User;82 lock.LockTime = new Date();83 lock.Lock = document.DocumentInfo.Status !== SEE.enum.DocumentStatusCode.DRAFT ? "on" : "N";84 SEE.session.SetSectionLock(document, sectionName, lock);85 onLockGranted(lock)86 } else {87 POST("/documents/sections", docRequest, function (data) {88 if (data.LockInfo) {89 SEE.session.SetSectionLock(document, sectionName, data.LockInfo);90 onLockGranted(data);91 } else {92 onLockDenied(data);93 }94 }, onFailure);95 }96 };97//documents/sections/releaselock98 self.ReleaseLockedSection = function (document, sectionName, onSuccess, onFailure) {99 lockInfo = SEE.session.GetSectionLock(document, sectionName),100 docRequest = { DocumentId: document._id, SectionName: sectionName, Lock: lockInfo ? lockInfo.Lock : null };101 if (lockInfo && lockInfo.Lock === "N") {102 SEE.session.ClearSectionLock(document, sectionName);103 onSuccess(document[sectionName]);104 return;105 }106 SEE.session.ClearSectionLock(document, sectionName);107 if (!_.isUndefined(document._id) && !_.isNull(docRequest.Lock)) { //new document, never saved108 POST("/documents/sections/releaselock", docRequest, function (data) {109 if (onSuccess) {110 onSuccess(data);111 }112 }, onFailure);113 } else { //we weren't holding a lock, move on114 onSuccess(document[sectionName]);115 }116 };117//document118 self.RetrieveDocumentList = function (args, onSuccess) {119 var param = null;120 if (!_.isUndefined(args) && !_.isNull(args)) {121 //MRU, Status, id122 param = args;123 }124 GET("/list", param, onSuccess);125 };126//documents?id127 self.RetrieveDocument = function (documentId, onSuccess) {128 var docRequest = { 'id': documentId };129 GET("/documents", docRequest, onSuccess);130 };131//documents132 self.CreateDocument = function (document, onSuccess) {133 POST("/documents", document, function (data) {134 var newDocument;135 if (_.isArray(data.payload) && data.payload.length > 0) {136 newDocument = data.payload[0];137 }138 onSuccess(newDocument);139 });140 };141//documents142 self.UpdateDocument = function (document, onSuccess) {143 POST("/documents", document, function (data) {144 onSuccess(data);145 });146 };147//document/search? or document/148 self.Search = function (query, onSuccess) {149 GET("/search", { query: query }, function (data) {150 var results;151 if (!_.isUndefined(data) && !_.isUndefined(data.results)) {152 results = data.results;153 }154 onSuccess(results);155 });156 };157//documents/send158 self.SendDocument = function (document, onSuccess, onFail) {159 POST("/documents/send", document, onSuccess, onFail);160 };161//problems162 self.SnomedProblemSearch = function (query, onSuccess) {163 GET("/problems", { query: query }, onSuccess);164 };165//medications166 self.MedicationSearch = function (query, onSuccess) {167 GET("/medications", { query: query }, onSuccess);168 };169//medicationroutes170 self.MedicationRouteSearch = function (query, onSuccess) {171 GET("/medicationroutes", null, onSuccess);172 };173//documents/status174 self.UpdateDocumentStatus = function (document, newStatus, onSuccess) {175 var param = { DocumentId: document._id, DocumentStatusCode: newStatus };176 POST("/documents/status", param, function (result) {177 if (onSuccess) {178 onSuccess(result);179 }180 });181 }182//documents/cda183 self.GenerateCdaXml = function (document, onSuccess) {184 var param = { Document: document };185 POST("/documents/cda", param, function (result) {186 if (onSuccess) {187 onSuccess(result);188 }189 });190 };191//documents/sections/transform?sourceDocumentId=;sectionCode=192 self.TransformSection = function (document, importSectionCode, onSuccess) {193 var param = { sourceDocumentId: document._id, sectionCode: importSectionCode };194 POST("/documents/sections/transform", param, onSuccess);195 };196//DELETE documents197 //self.RemoveAllDocuments = function (onSuccess) {198 // var url = baseUrl + "/list";199 // var param = { };200 // return doAJAXCall(param, url, "DELETE", onSuccess);201 //};202//organizations/assigningauthorities?groupIdentifier=203 self.RetrieveAssigningAuthorityList = function (groupIdentifier, onSuccess) {204 var param = { groupIdentifier: groupIdentifier };205 GET("/organizations/assigningauthorities", param, onSuccess);206 }207//documents/sections/208 self.UpdateDocumentSection = function (document, sectionName, onSuccess) {209 var lockInfo = SEE.session.GetSectionLock(document, sectionName);210 var param = {211 documentId: document._id,212 sectionName: sectionName,213 newEvents: document.DocumentInfo.History.NewEvents,214 title: document.DocumentInfo.Title,215 section: document[sectionName],216 lock: lockInfo ? lockInfo.Lock : "999"217 };218 POST("/documents/sections/update", param, function (data) {219 //clear the events220 document.DocumentInfo.History.NewEvents = [];221 onSuccess(data);222 });223 };224//documents/locks?id=225 self.GetAllLocksForDocument = function (document, onSuccess) {226 var param = { id: document._id };227 GET("/documents/locks", param, function (result) {228 if (onSuccess) {229 onSuccess(result);230 }231 });232 };233///organizations?id=234 self.GetOrganizationForUser = function (user, onSuccess) {235 var param = { groupIdentifier: user.GroupIdentifier };236 GET("/organizations", param,237 function (result) {238 if (onSuccess) {239 onSuccess(result);240 }241 },242 function(error){243 bootbox.alert("Login failed with error: " + error, function(){244 window.close();245 });246 });247 };248 self.UpdateOrganization = function (organization, onSuccess) {249 var param = { organization: organization };250 POST("/organizations", param, function (result) {251 if (onSuccess) {252 onSuccess(result);253 }254 });255 };256//users257 self.UpdateUser = function (user, onSuccess) {258 var param = {259 user: user260 };261 POST("/users/", param,function (data) {262 if (onSuccess) {263 onSuccess(data);264 }265 });266 };...

Full Screen

Full Screen

xy_api.js

Source:xy_api.js Github

copy

Full Screen

...67 if (response.authorization !== undefined) {68 XY.token = response.authorization;69 }70 if (onSuccess !== undefined) {71 onSuccess(response, passData);72 }73 }74 ).fail(function(f) {75 if (onError) {76 onError(f);77 }78 });79 }80 XY.API = XY.API || {81 makeCall: makeCall,82 postSettings: postSettings,83 /* TODO preflight checks, currently allows you invoke methods without required params*/84 about: {85 get: function (onSuccess, onError) {86 makeCall(postSettings("about", "get", {}), onSuccess, onError);87 }88 },89 account: {90 read: function(user, onSuccess, onError) {91 makeCall(postSettings("account", "read", {92 user: user93 }), onSuccess, onError);94 },95 signin: function(user, onSuccess, onError) {96 makeCall(postSettings("account", "signin", {97 user: user98 }), onSuccess, onError);99 },100 signup: function(user, onSuccess, onError) {101 makeCall(postSettings("account", "add", {102 user: user103 }), onSuccess, onError);104 },105 sendVerification: function(user, onSuccess, onError) {106 makeCall(postSettings("account", "sendVerification", {107 user: user108 }), onSuccess, onError);109 },110 update: function(user, onSuccess, onError) {111 makeCall(postSettings("account", "update", {112 user: user113 }), onSuccess, onError);114 },115 reset: function(email, onSuccess, onError) {116 makeCall(postSettings("account", "reset", {117 user: {118 email: email119 }120 }), onSuccess, onError);121 },122 intercom: function(email, onSuccess, onError) {123 var settings = postSettings("intercom", "authorize", {124 user: {125 email: email126 }127 });128 settings.url = "https://devapi.xyfindit.com/2.2/intercom";129 // TODO fix this : )130 makeCall(settings, onSuccess, function (e) {131 if (e.status == 200) {132 onSuccess(e.responseText);133 }134 else {135 onError(e);136 }137 });138 }139 },140 beacon: {141 read: function(onSuccess, onError, s, ids) {142 var settings = postSettings("beacon", "read", {143 ids: ids144 }, s);145 settings.url = "https://devapi.xyfindit.com/2.2/beacon";146 // TODO fix this to prod api...

Full Screen

Full Screen

CameraPreview.js

Source:CameraPreview.js Github

copy

Full Screen

1var argscheck = require('cordova/argscheck'),2 utils = require('cordova/utils'),3 exec = require('cordova/exec');4var PLUGIN_NAME = "CameraPreview";5var CameraPreview = function() {};6function isFunction(obj) {7 return !!(obj && obj.constructor && obj.call && obj.apply);8};9CameraPreview.startCamera = function(options, onSuccess, onError) {10 options = options || {};11 options.x = options.x || 0;12 options.y = options.y || 0;13 options.width = options.width || window.screen.width;14 options.height = options.height || window.screen.height;15 options.camera = options.camera || CameraPreview.CAMERA_DIRECTION.FRONT;16 if (typeof(options.tapPhoto) === 'undefined') {17 options.tapPhoto = true;18 }19 if (typeof (options.tapFocus) == 'undefined') {20 options.tapFocus = false;21 }22 options.previewDrag = options.previewDrag || false;23 options.toBack = options.toBack || false;24 if (typeof(options.alpha) === 'undefined') {25 options.alpha = 1;26 }27 options.disableExifHeaderStripping = options.disableExifHeaderStripping || false;28 exec(onSuccess, onError, PLUGIN_NAME, "startCamera", [options.x, options.y, options.width, options.height, options.camera, options.tapPhoto, options.previewDrag, options.toBack, options.alpha, options.tapFocus, options.disableExifHeaderStripping]);29};30CameraPreview.stopCamera = function(onSuccess, onError) {31 exec(onSuccess, onError, PLUGIN_NAME, "stopCamera", []);32};33CameraPreview.switchCamera = function(onSuccess, onError) {34 exec(onSuccess, onError, PLUGIN_NAME, "switchCamera", []);35};36CameraPreview.hide = function(onSuccess, onError) {37 exec(onSuccess, onError, PLUGIN_NAME, "hideCamera", []);38};39CameraPreview.show = function(onSuccess, onError) {40 exec(onSuccess, onError, PLUGIN_NAME, "showCamera", []);41};42CameraPreview.takePicture = function(opts, onSuccess, onError) {43 if (!opts) {44 opts = {};45 } else if (isFunction(opts)) {46 onSuccess = opts;47 opts = {};48 }49 if (!isFunction(onSuccess)) {50 return false;51 }52 opts.width = opts.width || 0;53 opts.height = opts.height || 0;54 if (!opts.quality || opts.quality > 100 || opts.quality < 0) {55 opts.quality = 85;56 }57 exec(onSuccess, onError, PLUGIN_NAME, "takePicture", [opts.width, opts.height, opts.quality]);58};59CameraPreview.setColorEffect = function(effect, onSuccess, onError) {60 exec(onSuccess, onError, PLUGIN_NAME, "setColorEffect", [effect]);61};62CameraPreview.setZoom = function(zoom, onSuccess, onError) {63 exec(onSuccess, onError, PLUGIN_NAME, "setZoom", [zoom]);64};65CameraPreview.getMaxZoom = function(onSuccess, onError) {66 exec(onSuccess, onError, PLUGIN_NAME, "getMaxZoom", []);67};68CameraPreview.getZoom = function(onSuccess, onError) {69 exec(onSuccess, onError, PLUGIN_NAME, "getZoom", []);70};71CameraPreview.getHorizontalFOV = function(onSuccess, onError) {72 exec(onSuccess, onError, PLUGIN_NAME, "getHorizontalFOV", []);73};74CameraPreview.setPreviewSize = function(dimensions, onSuccess, onError) {75 dimensions = dimensions || {};76 dimensions.width = dimensions.width || window.screen.width;77 dimensions.height = dimensions.height || window.screen.height;78 exec(onSuccess, onError, PLUGIN_NAME, "setPreviewSize", [dimensions.width, dimensions.height]);79};80CameraPreview.getSupportedPictureSizes = function(onSuccess, onError) {81 exec(onSuccess, onError, PLUGIN_NAME, "getSupportedPictureSizes", []);82};83CameraPreview.getSupportedFlashModes = function(onSuccess, onError) {84 exec(onSuccess, onError, PLUGIN_NAME, "getSupportedFlashModes", []);85};86CameraPreview.getSupportedColorEffects = function(onSuccess, onError) {87 exec(onSuccess, onError, PLUGIN_NAME, "getSupportedColorEffects", []);88};89CameraPreview.setFlashMode = function(flashMode, onSuccess, onError) {90 exec(onSuccess, onError, PLUGIN_NAME, "setFlashMode", [flashMode]);91};92CameraPreview.getFlashMode = function(onSuccess, onError) {93 exec(onSuccess, onError, PLUGIN_NAME, "getFlashMode", []);94};95CameraPreview.getSupportedFocusModes = function(onSuccess, onError) {96 exec(onSuccess, onError, PLUGIN_NAME, "getSupportedFocusModes", []);97};98CameraPreview.getFocusMode = function(onSuccess, onError) {99 exec(onSuccess, onError, PLUGIN_NAME, "getFocusMode", []);100};101CameraPreview.setFocusMode = function(focusMode, onSuccess, onError) {102 exec(onSuccess, onError, PLUGIN_NAME, "setFocusMode", [focusMode]);103};104CameraPreview.tapToFocus = function(xPoint, yPoint, onSuccess, onError) {105 exec(onSuccess, onError, PLUGIN_NAME, "tapToFocus", [xPoint, yPoint]);106};107CameraPreview.getExposureModes = function(onSuccess, onError) {108 exec(onSuccess, onError, PLUGIN_NAME, "getExposureModes", []);109};110CameraPreview.getExposureMode = function(onSuccess, onError) {111 exec(onSuccess, onError, PLUGIN_NAME, "getExposureMode", []);112};113CameraPreview.setExposureMode = function(exposureMode, onSuccess, onError) {114 exec(onSuccess, onError, PLUGIN_NAME, "setExposureMode", [exposureMode]);115};116CameraPreview.getExposureCompensation = function(onSuccess, onError) {117 exec(onSuccess, onError, PLUGIN_NAME, "getExposureCompensation", []);118};119CameraPreview.setExposureCompensation = function(exposureCompensation, onSuccess, onError) {120 exec(onSuccess, onError, PLUGIN_NAME, "setExposureCompensation", [exposureCompensation]);121};122CameraPreview.getExposureCompensationRange = function(onSuccess, onError) {123 exec(onSuccess, onError, PLUGIN_NAME, "getExposureCompensationRange", []);124};125CameraPreview.getSupportedWhiteBalanceModes = function(onSuccess, onError) {126 exec(onSuccess, onError, PLUGIN_NAME, "getSupportedWhiteBalanceModes", []);127};128CameraPreview.getWhiteBalanceMode = function(onSuccess, onError) {129 exec(onSuccess, onError, PLUGIN_NAME, "getWhiteBalanceMode", []);130};131CameraPreview.setWhiteBalanceMode = function(whiteBalanceMode, onSuccess, onError) {132 exec(onSuccess, onError, PLUGIN_NAME, "setWhiteBalanceMode", [whiteBalanceMode]);133};134CameraPreview.onBackButton = function(onSuccess, onError) {135 exec(onSuccess, onError, PLUGIN_NAME, "onBackButton");136};137CameraPreview.FOCUS_MODE = {138 FIXED: 'fixed',139 AUTO: 'auto',140 CONTINUOUS: 'continuous', // IOS Only141 CONTINUOUS_PICTURE: 'continuous-picture', // Android Only142 CONTINUOUS_VIDEO: 'continuous-video', // Android Only143 EDOF: 'edof', // Android Only144 INFINITY: 'infinity', // Android Only145 MACRO: 'macro' // Android Only146};147CameraPreview.EXPOSURE_MODE = {148 LOCK: 'lock',149 AUTO: 'auto', // IOS Only150 CONTINUOUS: 'continuous', // IOS Only151 CUSTOM: 'custom' // IOS Only152};153CameraPreview.WHITE_BALANCE_MODE = {154 LOCK: 'lock',155 AUTO: 'auto',156 CONTINUOUS: 'continuous',157 INCANDESCENT: 'incandescent',158 CLOUDY_DAYLIGHT: 'cloudy-daylight',159 DAYLIGHT: 'daylight',160 FLUORESCENT: 'fluorescent',161 SHADE: 'shade',162 TWILIGHT: 'twilight',163 WARM_FLUORESCENT: 'warm-fluorescent'164};165CameraPreview.FLASH_MODE = {166 OFF: 'off',167 ON: 'on',168 AUTO: 'auto',169 RED_EYE: 'red-eye', // Android Only170 TORCH: 'torch'171};172CameraPreview.COLOR_EFFECT = {173 AQUA: 'aqua', // Android Only174 BLACKBOARD: 'blackboard', // Android Only175 MONO: 'mono',176 NEGATIVE: 'negative',177 NONE: 'none',178 POSTERIZE: 'posterize',179 SEPIA: 'sepia',180 SOLARIZE: 'solarize', // Android Only181 WHITEBOARD: 'whiteboard' // Android Only182};183CameraPreview.CAMERA_DIRECTION = {184 BACK: 'back',185 FRONT: 'front'186};...

Full Screen

Full Screen

demo.js

Source:demo.js Github

copy

Full Screen

...17endDate.setSeconds(0);18// add a few hours to the dates, JS will automatically update the date (+1 day) if necessary19startDate.setHours(startDate.getHours() + 2);20endDate.setHours(endDate.getHours() + 3);21function onSuccess(msg) {22 alert('Calendar success: ' + JSON.stringify(msg));23}24function onError(msg) {25 alert('Calendar error: ' + JSON.stringify(msg));26}27function hasReadPermission() {28 window.plugins.calendar.hasReadPermission(onSuccess);29}30function requestReadPermission() {31 window.plugins.calendar.requestReadPermission(onSuccess);32}33function hasWritePermission() {34 window.plugins.calendar.hasWritePermission(onSuccess);35}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2fc.assert(3 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),4 { numRuns: 1000, seed: 42 }5);6const fc = require('fast-check');7fc.assert(8 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),9 { numRuns: 1000, seed: 42 }10);11const fc = require('fast-check');12fc.assert(13 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),14 { numRuns: 1000, seed: 42 }15);16const fc = require('fast-check');17fc.assert(18 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),19 { numRuns: 1000, seed: 42 }20);21const fc = require('fast-check');22fc.assert(23 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),24 { numRuns: 1000, seed: 42 }25);26const fc = require('fast-check');27fc.assert(28 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),29 { numRuns: 1000, seed: 42 }30);31const fc = require('fast-check');32fc.assert(33 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),34 { numRuns: 1000, seed: 42 }35);36const fc = require('fast-check');37fc.assert(38 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),39 { numRuns: 1000, seed: 42 }40);41const fc = require('fast-check');42fc.assert(43 fc.property(fc.integer(), fc

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fastCheck } from 'fast-check';2import * as fc from 'fast-check';3const { fastCheck } = require('fast-check');4const fc = require('fast-check');5import { fastCheck } from 'fast-check';6import * as fc from 'fast-check';7const { fastCheck } = require('fast-check');8const fc = require('fast-check');9import { fastCheck } from 'fast-check';10import * as fc from 'fast-check';11const { fastCheck } = require('fast-check');12const fc = require('fast-check');13import { fastCheck } from 'fast-check';14import * as fc from 'fast-check';15const { fastCheck } = require('fast-check');16const fc = require('fast-check');17import { fastCheck } from 'fast-check';18import * as fc from 'fast-check';19const { fastCheck } = require('fast-check');20const fc = require('fast-check');21import { fastCheck } from 'fast-check';22import * as fc from 'fast-check';23const { fastCheck } = require('fast-check');24const fc = require('fast-check');25import { fastCheck } from 'fast-check';26import * as fc from 'fast-check';27const { fastCheck } = require('fast-check');28const fc = require('fast-check');29import { fastCheck } from 'fast-check';30import * as fc from 'fast-check';31const { fastCheck } = require('fast-check');32const fc = require('fast-check');33import { fastCheck } from 'fast-check';34import * as fc from 'fast-check';35const { fastCheck } = require('fast-check');36const fc = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { onSuccess } from 'fast-check/lib/types/fast-check-default'2const property = fc.property(3 fc.integer(),4 fc.integer(),5 (a, b) => {6 },7 {examples: [[1, 2], [2, 1]]}8onSuccess(property, (a, b) => {9 console.log(`Success: ${a} + ${b} === ${b} + ${a}`)10})11fc.property(fc.integer(), (n) => {12 expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).toContain(n);13});14fc.property(fc.integer(), (n) => {15 expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).not.toContain(n);16});17fc.property(fc.integer(), (n) => {18 expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).toContain(n);19 expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).not.toContain(n);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fc, testProp } = require('fast-check');2testProp('test', [fc.integer(), fc.integer()], (a, b) => {3 console.log(a, b);4 return true;5});6{7 "dependencies": {8 },9 "devDependencies": {10 },11 "scripts": {12 },13 "jest": {14 }15}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fc, fc2 } = require('./index.js');2console.log(fc);3console.log(fc2);4const fc = require('fast-check');5const fc2 = require('fast-check');6module.exports = {7};8{ [Function: run]

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ArbitraryBuilder} from '@fast-check/arbitrary-builder';2import {fc} from '@fast-check/core';3const {string} = fc;4const {oneof} = ArbitraryBuilder;5const {option} = ArbitraryBuilder;6const optionString = option(string());7const oneofString = oneof(string(), string(), string());8const result = optionString.generate(10);9console.log(result);10const result2 = oneofString.generate(10);11console.log(result2);12import {ArbitraryBuilder} from '@fast-check/arbitrary-builder';13import {fc} from '@fast-check/core';14const {string} = fc;15const {oneof} = ArbitraryBuilder;16const {option} = ArbitraryBuilder;17const optionString = option(string());18const oneofString = oneof(string(), string(), string());19const result = optionString.generate(10);20console.log(result);21const result2 = oneofString.generate(10);22console.log(result2);23import {ArbitraryBuilder} from '@fast-check/arbitrary-builder';24import {fc} from '@fast-check/core';25const {string} = fc;26const {oneof} = ArbitraryBuilder;27const {option} = ArbitraryBuilder;28const optionString = option(string());29const oneofString = oneof(string(), string(), string());30const result = optionString.generate(10);31console.log(result);32const result2 = oneofString.generate(10);33console.log(result2);34import {ArbitraryBuilder} from '@fast-check/arbitrary-builder';35import {fc} from '@fast-check/core';36const {string} = fc;37const {oneof} = ArbitraryBuilder;38const {option} = ArbitraryBuilder;39const optionString = option(string());40const oneofString = oneof(string(), string(), string());41const result = optionString.generate(10);42console.log(result);43const result2 = oneofString.generate(10);44console.log(result2);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fc, testProp } from 'fast-check'2import { onSuccess } from 'fast-check-monorepo'3testProp(4 [fc.string()],5 (s) => {6 return onSuccess(() => {7 })8 }

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful