WsFileSpray.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/_base/xhr",
  21. "dojo/_base/Deferred",
  22. "dojo/store/util/QueryResults",
  23. "hpcc/ESPBase"
  24. ], function (declare, lang, xhr, Deferred, QueryResults, ESPBase) {
  25. var GetDFUWorkunits = declare(ESPBase, {
  26. idProperty: "ID",
  27. constructor: function (options) {
  28. declare.safeMixin(this, options);
  29. },
  30. getIdentity: function (object) {
  31. return object[this.idProperty];
  32. },
  33. query: function (query, options) {
  34. var request = {};
  35. lang.mixin(request, options.query);
  36. request['PageStartFrom'] = options.start;
  37. request['PageSize'] = options.count;
  38. if (options.sort) {
  39. request['Sortby'] = options.sort[0].attribute;
  40. request['Descending'] = options.sort[0].descending;
  41. }
  42. request['rawxml_'] = "1";
  43. var results = xhr.get({
  44. url: this.getBaseURL("FileSpray") + "/GetDFUWorkunits",
  45. handleAs: "xml",
  46. content: request
  47. });
  48. var context = this;
  49. var parsedResults = results.then(function (domXml) {
  50. data = context.getValues(domXml, "DFUWorkunit");
  51. data.total = context.getValue(domXml, "NumWUs");
  52. return data;
  53. });
  54. lang.mixin(parsedResults, {
  55. total: Deferred.when(parsedResults, function (data) {
  56. return data.total;
  57. })
  58. });
  59. return QueryResults(parsedResults);
  60. }
  61. });
  62. var FileList = declare(ESPBase, {
  63. idProperty: "name",
  64. constructor: function (options) {
  65. declare.safeMixin(this, options);
  66. },
  67. getIdentity: function (object) {
  68. return object[this.idProperty];
  69. },
  70. query: function (query, options) {
  71. var request = {};
  72. lang.mixin(request, options.query);
  73. request['rawxml_'] = "1";
  74. var results = xhr.get({
  75. url: this.getBaseURL("FileSpray") + "/FileList",
  76. handleAs: "xml",
  77. content: request
  78. });
  79. var context = this;
  80. var parsedResults = results.then(function (domXml) {
  81. var debug = context.flattenXml(domXml);
  82. var data = context.getValues(domXml, "PhysicalFileStruct");
  83. return data;
  84. });
  85. lang.mixin(parsedResults, {
  86. total: Deferred.when(parsedResults, function (data) {
  87. return data.length;
  88. })
  89. });
  90. return QueryResults(parsedResults);
  91. }
  92. });
  93. return {
  94. GetDFUWorkunits: GetDFUWorkunits,
  95. FileList: FileList
  96. };
  97. });