123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/array",
- "dojo/on",
- "dijit/form/Button",
- "dgrid/OnDemandGrid",
- "dgrid/Keyboard",
- "dgrid/Selection",
- "dgrid/selector",
- "dgrid/extensions/ColumnResizer",
- "dgrid/extensions/DijitRegistry",
- "hpcc/GridDetailsWidget",
- "hpcc/WsWorkunits",
- "hpcc/FileSpray",
- "hpcc/WsDfu",
- "hpcc/WUDetailsWidget",
- "hpcc/DFUWUDetailsWidget",
- "hpcc/LFDetailsWidget",
- "hpcc/SFDetailsWidget",
- "hpcc/ESPUtil"
- ], function (declare, lang, arrayUtil, on,
- Button,
- OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
- GridDetailsWidget, WsWorkunits, FileSpray, WsDfu, WUDetailsWidget, DFUWUDetailsWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
- return declare("SearchResultsWidget", [GridDetailsWidget], {
- gridTitle: "Search Results",
- idProperty: "id",
- doSearch: function (searchText) {
- this.searchText = searchText;
- this.selectChild(this.gridTab);
- this.refreshGrid();
- },
- init: function (params) {
- if (this.initalized)
- return;
- this.initalized = true;
- this._refreshActionState();
- },
- createGrid: function (domID) {
- var context = this;
- var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: this.store,
- loadingMessage: "Loading data...",
- noDataMessage: "No results found.",
- columns: {
- col1: selector({ width: 27, selectorType: 'checkbox' }),
- Type: { label: "What", width: 108, sortable: true },
- Reason: { label: "Where", width: 108, sortable: true },
- Summary: {
- label: "Who", sortable: true,
- formatter: function (summary, idx) {
- return "<a href=# rowIndex=" + idx + " class='" + context.id + "SearchResultClick'>" + summary + "</a>";
- }
- }
- }
- }, domID);
- var context = this;
- on(document, "." + this.id + "SearchResultClick:click", function (evt) {
- if (context._onRowDblClick) {
- var row = retVal.row(evt).data;
- context._onRowDblClick(row);
- }
- });
- return retVal;
- },
- createDetail: function (id, row, params) {
- switch (row._type) {
- case "Wuid":
- return new WUDetailsWidget({
- id: id,
- title: row.Summary,
- closable: true,
- hpcc: {
- params: {
- Wuid: row._wuid
- }
- }
- });
- break;
- case "DFUWuid":
- return new DFUWUDetailsWidget.fixCircularDependency({
- id: id,
- title: row.Summary,
- closable: true,
- hpcc: {
- params: {
- Wuid: row._wuid
- }
- }
- });
- break;
- case "LogicalFile":
- if (row.isSuperfile) {
- return new SFDetailsWidget.fixCircularDependency({
- id: id,
- title: row.Summary,
- closable: true,
- hpcc: {
- params: {
- Name: row._name
- }
- }
- });
- } else {
- return new LFDetailsWidget.fixCircularDependency({
- id: id,
- title: row.Summary,
- closable: true,
- hpcc: {
- params: {
- Name: row._name
- }
- }
- });
- }
- break;
- default:
- break;
- }
- return null;
- },
- loadWUQueryResponse: function(prefix, response) {
- var workunits = lang.getObject("WUQueryResponse.Workunits.ECLWorkunit", false, response)
- if (workunits) {
- var idPrefix = prefix.split(" ").join("_");
- var context = this;
- arrayUtil.forEach(workunits, function (item, idx) {
- context.store.add({
- id: "WsWorkunitsWUQuery" + idPrefix + idx,
- Type: "ECL Workunit",
- Reason: prefix,
- Summary: item.Wuid,
- _type: "Wuid",
- _wuid: item.Wuid
- });
- });
- return workunits.length;
- }
- return 0;
- },
- loadGetDFUWorkunitsResponse: function (prefix, response) {
- var workunits = lang.getObject("GetDFUWorkunitsResponse.results.DFUWorkunit", false, response)
- if (workunits) {
- var idPrefix = prefix.split(" ").join("_");
- var context = this;
- arrayUtil.forEach(workunits, function (item, idx) {
- context.store.add({
- id: "FileSprayGetDFUWorkunits" + idPrefix + idx,
- Type: "DFU Workunit",
- Reason: prefix,
- Summary: item.ID,
- _type: "DFUWuid",
- _wuid: item.ID
- });
- });
- return workunits.length;
- }
- return 0;
- },
- loadGetDFUWorkunitResponse: function (prefix, response) {
- var workunit = lang.getObject("GetDFUWorkunitResponse.result", false, response)
- if (workunit) {
- var idPrefix = prefix.split(" ").join("_");
- this.store.add({
- id: "FileSprayGetDFUWorkunits" + idPrefix + idx,
- Type: "DFU Workunit",
- Reason: prefix,
- Summary: workunit.ID,
- _type: "DFUWuid",
- _wuid: workunit.ID
- });
- return 1;
- }
- return 0;
- },
- loadDFUQueryResponse: function (prefix, response) {
- var items = lang.getObject("DFUQueryResponse.DFULogicalFiles.DFULogicalFile", false, response)
- if (items) {
- var idPrefix = prefix.split(" ").join("_");
- var context = this;
- arrayUtil.forEach(items, function (item, idx) {
- context.store.add({
- id: "WsDfuDFUQuery" + idPrefix + idx,
- Type: "Logical File",
- Reason: prefix,
- Summary: item.Name,
- _type: "LogicalFile",
- _name: item.Name
- });
- });
- return items.length;
- }
- return 0;
- },
- refreshGrid: function (args) {
- this.store.setData([]);
- this.grid.refresh();
- if (this.searchText) {
- var context = this;
- // ECL WU ---
- WsWorkunits.WUQuery({ request: { Wuid: this.searchText }, suppressExceptionToaster: true }).then(function (response) {
- context.loadWUQueryResponse("Wuid", response);
- });
- WsWorkunits.WUQuery({ request: { Jobname: "*" + this.searchText + "*" } }).then(function (response) {
- context.loadWUQueryResponse("Job Name", response);
- });
- WsWorkunits.WUQuery({ request: { Owner: this.searchText } }).then(function (response) {
- context.loadWUQueryResponse("Owner", response);
- });
- WsWorkunits.WUQuery({ request: { ECL: this.searchText } }).then(function (response) {
- context.loadWUQueryResponse("ECL", response);
- });
- // DFU WU ---
- FileSpray.GetDFUWorkunit({ request: { wuid: this.searchText }, suppressExceptionToaster: true }).then(function (response) {
- context.loadGetDFUWorkunitResponse("Wuid", response);
- });
- FileSpray.GetDFUWorkunits({ request: { Jobname: "*" + this.searchText + "*" } }).then(function (response) {
- context.loadGetDFUWorkunitsResponse("Job Name", response);
- });
- FileSpray.GetDFUWorkunits({ request: { Owner: this.searchText } }).then(function (response) {
- context.loadGetDFUWorkunitsResponse("Owner", response);
- });
- // Logical Files ---
- WsDfu.DFUQuery({ request: { LogicalName: "*" + this.searchText + "*" } }).then(function (response) {
- context.loadDFUQueryResponse("Logical Name", response);
- });
- WsDfu.DFUQuery({ request: { Description: "*" + this.searchText + "*" } }).then(function (response) {
- context.loadDFUQueryResponse("Description", response);
- });
- WsDfu.DFUQuery({ request: { Owner: this.searchText } }).then(function (response) {
- context.loadDFUQueryResponse("Owner", response);
- });
- }
- },
- refreshActionState: function (selection) {
- this.inherited(arguments);
- }
- });
- });
|