123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /*##############################################################################
- # Copyright (C) 2011 HPCC Systems.
- #
- # All rights reserved. This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/xhr",
- "dojo/_base/Deferred",
- "dojo/store/util/QueryResults",
- "hpcc/ESPBase"
- ], function (declare, lang, xhr, Deferred, QueryResults, ESPBase) {
- var WUQuery = declare(ESPBase, {
- idProperty: "Wuid",
- constructor: function (options) {
- declare.safeMixin(this, options);
- },
- getIdentity: function (object) {
- return object[this.idProperty];
- },
- query: function (query, options) {
- var request = {};
- lang.mixin(request, options.query);
- if (options.start)
- request['PageStartFrom'] = options.start;
- if (options.count)
- request['Count'] = options.count;
- if (options.sort) {
- request['Sortby'] = options.sort[0].attribute;
- request['Descending'] = options.sort[0].descending;
- }
- request['rawxml_'] = "1";
- var results = xhr.get({
- url: this.getBaseURL("WsWorkunits") + "/WUQuery",
- handleAs: "xml",
- content: request
- });
- var context = this;
- var parsedResults = results.then(function (domXml) {
- data = context.getValues(domXml, "ECLWorkunit");
- data.total = context.getValue(domXml, "NumWUs");
- return data;
- });
- lang.mixin(parsedResults, {
- total: Deferred.when(parsedResults, function (data) {
- return data.total;
- })
- });
- return QueryResults(parsedResults);
- }
- });
- var WUResult = declare(ESPBase, {
- idProperty: "myInjectedRowNum",
- wuid: "",
- sequence: 0,
- isComplete: false,
- constructor: function (args) {
- declare.safeMixin(this, args);
- },
- getIdentity: function (object) {
- return object[this.idProperty];
- },
- queryWhenComplete: function (query, options, deferredResults) {
- var context = this;
- if (this.isComplete == true) {
- var request = {};
- request['Wuid'] = this.wuid;
- request['Sequence'] = this.sequence;
- request['Start'] = options.start;
- request['Count'] = options.count;
- request['rawxml_'] = "1";
- var results = xhr.post({
- url: this.getBaseURL("WsWorkunits") + "/WUResult",
- handleAs: "xml",
- content: request,
- load: function (domXml) {
- var rows = context.getValues(domXml, "Row");
- for (var i = 0; i < rows.length; ++i) {
- rows[i].myInjectedRowNum = options.start + i + 1;
- }
- rows.total = context.getValue(domXml, "Total");
- // TODO - Need to check why this happens only sometimes (Suspect non XML from the server) ---
- if (rows.total == null) {
- var debug = context.flattenXml(domXml);
- setTimeout(function () {
- context.queryWhenComplete(query, options, deferredResults);
- }, 100);
- }
- else {
- deferredResults.resolve(rows);
- }
- }
- });
- } else {
- setTimeout(function () {
- context.queryWhenComplete(query, options, deferredResults);
- }, 100);
- }
- },
- query: function (query, options) {
- var deferredResults = new Deferred();
- this.queryWhenComplete(query, options, deferredResults);
- var retVal = lang.mixin({
- total: Deferred.when(deferredResults, function (rows) {
- return rows.total;
- })
- }, deferredResults);
- return QueryResults(retVal);
- }
- });
- return {
- WUQuery: WUQuery,
- WUResult: WUResult
- };
- });
|