SourceFilesWidget.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/i18n",
  20. "dojo/i18n!./nls/common",
  21. "dojo/i18n!./nls/SourceFilesWidget",
  22. "dojo/_base/array",
  23. "dojo/on",
  24. "dgrid/OnDemandGrid",
  25. "dgrid/Keyboard",
  26. "dgrid/Selection",
  27. "dgrid/selector",
  28. "dgrid/extensions/ColumnResizer",
  29. "dgrid/extensions/DijitRegistry",
  30. "hpcc/GridDetailsWidget",
  31. "hpcc/ESPWorkunit",
  32. "hpcc/ResultWidget",
  33. "hpcc/LFDetailsWidget",
  34. "hpcc/SFDetailsWidget",
  35. "hpcc/ESPUtil"
  36. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, on,
  37. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  38. GridDetailsWidget, ESPWorkunit, ResultWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  39. return declare("SourceFilesWidget", [GridDetailsWidget], {
  40. i18n: lang.mixin(nlsCommon, nlsSpecific),
  41. gridTitle: "Inputs",
  42. idProperty: "sequence",
  43. wu: null,
  44. init: function (params) {
  45. if (this.inherited(arguments))
  46. return;
  47. if (params.Wuid) {
  48. this.wu = ESPWorkunit.Get(params.Wuid);
  49. var monitorCount = 4;
  50. var context = this;
  51. this.wu.monitor(function () {
  52. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  53. context.refreshGrid();
  54. }
  55. });
  56. }
  57. this._refreshActionState();
  58. },
  59. createGrid: function (domID) {
  60. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  61. allowSelectAll: true,
  62. deselectOnRefresh: false,
  63. store: this.store,
  64. columns: {
  65. col1: selector({
  66. width: 27,
  67. selectorType: 'checkbox'
  68. }),
  69. Name: {
  70. label: "Name", sortable: true,
  71. formatter: function (Name, row) {
  72. return "<img src='/esp/files/img/" + (row.IsSuperFile ? "folder_table.png" : "file.png") + "'>&nbsp;<a href='#' rowIndex=" + row + " class='" + context.id + "SourceFileClick'>" + Name + "</a>";
  73. }
  74. },
  75. Count: { label: "Usage", width: 72, sortable: true }
  76. }
  77. }, domID);
  78. var context = this;
  79. on(document, "." + this.id + "SourceFileClick:click", function (evt) {
  80. if (context._onRowDblClick) {
  81. var row = context.grid.row(evt).data;
  82. context._onRowDblClick(row);
  83. }
  84. });
  85. return retVal;
  86. },
  87. getDetailTitle: function (row, params) {
  88. return row.Name;
  89. },
  90. createDetail: function (id, row) {
  91. if (lang.exists("IsSuperFile", row) && row.IsSuperFile) {
  92. return new SFDetailsWidget.fixCircularDependency({
  93. id : id,
  94. title: row.Name,
  95. closable: true,
  96. hpcc: {
  97. type: "SFDetailsWidget",
  98. params: row
  99. }
  100. });
  101. } else {
  102. return new LFDetailsWidget.fixCircularDependency({
  103. id: id,
  104. title: row.Name,
  105. closable: true,
  106. hpcc: {
  107. type: "LFDetailsWidget",
  108. params: {
  109. Name: row.Name
  110. }
  111. }
  112. });
  113. }
  114. },
  115. refreshGrid: function (args) {
  116. var context = this;
  117. this.wu.getInfo({
  118. onGetSourceFiles: function (sourceFiles) {
  119. arrayUtil.forEach(sourceFiles, function (row, idx) {
  120. row.sequence = idx;
  121. });
  122. context.store.setData(sourceFiles);
  123. context.grid.refresh();
  124. }
  125. });
  126. }
  127. });
  128. });