SourceFilesWidget.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/_base/array",
  20. "dojo/on",
  21. "dgrid/OnDemandGrid",
  22. "dgrid/Keyboard",
  23. "dgrid/Selection",
  24. "dgrid/selector",
  25. "dgrid/extensions/ColumnResizer",
  26. "dgrid/extensions/DijitRegistry",
  27. "hpcc/GridDetailsWidget",
  28. "hpcc/ESPWorkunit",
  29. "hpcc/ResultWidget",
  30. "hpcc/LFDetailsWidget",
  31. "hpcc/SFDetailsWidget",
  32. "hpcc/ESPUtil"
  33. ], function (declare, lang, arrayUtil, on,
  34. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  35. GridDetailsWidget, ESPWorkunit, ResultWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  36. return declare("SourceFilesWidget", [GridDetailsWidget], {
  37. gridTitle: "Inputs",
  38. idProperty: "sequence",
  39. wu: null,
  40. init: function (params) {
  41. if (this.inherited(arguments))
  42. return;
  43. if (params.Wuid) {
  44. this.wu = ESPWorkunit.Get(params.Wuid);
  45. var monitorCount = 4;
  46. var context = this;
  47. this.wu.monitor(function () {
  48. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  49. context.refreshGrid();
  50. }
  51. });
  52. }
  53. this._refreshActionState();
  54. },
  55. createGrid: function (domID) {
  56. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  57. allowSelectAll: true,
  58. deselectOnRefresh: false,
  59. store: this.store,
  60. columns: {
  61. col1: selector({
  62. width: 27,
  63. selectorType: 'checkbox'
  64. }),
  65. Name: {
  66. label: "Name", sortable: true,
  67. formatter: function (Name, row) {
  68. return "<img src='../files/img/" + (row.IsSuperFile ? "folder_table.png" : "file.png") + "'>&nbsp;<a href='#' rowIndex=" + row + " class='" + context.id + "SourceFileClick'>" + Name + "</a>";
  69. }
  70. },
  71. Count: { label: "Usage", width: 72, sortable: true }
  72. }
  73. }, domID);
  74. var context = this;
  75. on(document, "." + this.id + "SourceFileClick:click", function (evt) {
  76. if (context._onRowDblClick) {
  77. var row = context.grid.row(evt).data;
  78. context._onRowDblClick(row);
  79. }
  80. });
  81. return retVal;
  82. },
  83. getDetailTitle: function (row, params) {
  84. return row.Name;
  85. },
  86. createDetail: function (id, row) {
  87. if (lang.exists("IsSuperFile", row) && row.IsSuperFile) {
  88. return new SFDetailsWidget.fixCircularDependency({
  89. id : id,
  90. title: row.Name,
  91. closable: true,
  92. hpcc: {
  93. type: "SFDetailsWidget",
  94. params: row
  95. }
  96. });
  97. } else {
  98. return new LFDetailsWidget.fixCircularDependency({
  99. id: id,
  100. title: row.Name,
  101. closable: true,
  102. hpcc: {
  103. type: "LFDetailsWidget",
  104. params: row
  105. }
  106. });
  107. }
  108. },
  109. refreshGrid: function (args) {
  110. var context = this;
  111. this.wu.getInfo({
  112. onGetSourceFiles: function (sourceFiles) {
  113. arrayUtil.forEach(sourceFiles, function (row, idx) {
  114. row.sequence = idx;
  115. });
  116. context.store.setData(sourceFiles);
  117. context.grid.refresh();
  118. }
  119. });
  120. }
  121. });
  122. });