/* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ angular.module('wjmquery', ['ngDialog', 'dndLists']). controller('queryCtrl', function ($rootScope, $scope, ngDialog, $timeout, $filter, $location, $anchorScroll) { var vm = $scope; var hubber = $.connection.queryHub; vm.init = function () { var uid = document.getElementById("userId").innerHTML; $.connection.hub.qs = { 'userid': uid }; //Connection string set to identify the unique session ID for the user $.connection.hub.start().done(function () { hubber.server.requestInfo();//initial data request }); hubber.client.processData = function (filters) { // vm.values = JSON.parse(values); vm.filters = JSON.parse(filters); for (var i = 0; i < vm.filters.length;) { vm.filters[i].Comparison = "" + vm.filters[i].Comparison; if (vm.filters[i].Label === "AND" || vm.filters[i].Label === "OR") vm.filters.splice(i, 1); else { vm.filters[i].type = "item"; vm.filters[i].ComparisonValues = vm.comparisonModel[vm.filters[i].CompareType]; i++; } } $scope.$apply(); }; hubber.client.processResults = function (json) { // vm.values = JSON.parse(values); vm.sendingQuery = false; var jsonresults = JSON.parse(json); vm.results = []; vm.resultTokens = []; vm.activeResult = null; for (var i = 0; i < jsonresults.length; i++) { vm.results.push({ "Id": jsonresults[i] }); } $location.hash('allresults'); $scope.$apply(); }; hubber.client.resultLoad = function (json) { var data = JSON.parse(json); var resindex = undefined; for (var i = 0 ; i < vm.results.length; i++) { if (vm.resultTokens[i].id === data.Id) { resindex = vm.resultTokens[i].index; vm.resultTokens.splice(i, 1); break; } } if (resindex != undefined) { vm.results[resindex] = data; vm.results[resindex].CreatedDate = new Date(vm.results[resindex].CreatedDate); vm.activeResult = vm.results[resindex]; $location.hash('result'); vm.loadingResult = false; } $scope.$apply(); } } vm.sendQuery = function () { vm.sendingQuery = true; vm.results = undefined; hubber.server.runQuery(JSON.stringify($scope.models.dropzones.Dropzone)); }; vm.fetchResult = function (index) { vm.loadingResult = true; if(vm.results[index].CreatedDate != undefined){ vm.activeResult = vm.results[index]; $location.hash('result'); vm.loadingResult = false; } else{ vm.resultTokens.push({ "index": index, "id": vm.results[index].Id }); hubber.server.fetchResult(vm.results[index].Id); } }; $scope.models = { selected: null, templates: [ { type: "container", name: "AND", color: "#FF5500", columns: [[]] }, { type: "container", name: "OR",color: "#3a87ad" , columns: [[]] } ], dropzones: { "Dropzone": [ { "type": "container", "name": "AND", "color": "#FF5500", "columns": [ [] ] } ] } }; $scope.comparisonModel = { "HeuristicLab.Clients.OKB.Query.StringComparison": [ {value: 0, text: "="}, {value: 1, text: "<>"}, {value: 2, text: "Contains"}, {value: 3, text: "Not contains"}, {value: 4, text: "Like"}, {value: 5, text: "Not like"} ], "HeuristicLab.Clients.OKB.Query.OrdinalComparison": [ {value: 0, text: "<"}, {value: 1, text: "<="}, {value: 2, text: "="}, {value: 3, text: ">="}, {value: 4, text: ">"}, {value: 5, text: "<>"} ], "HeuristicLab.Clients.OKB.Query.BooleanOperation": [ {value: 0, text: "AND"}, {value: 1, text: "OR"} ], "HeuristicLab.Clients.OKB.Query.EqualityComparison": [ {value: 0, text: "="}, {value: 1, text: "<>"} ] } });