2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 .module('ui', [ 'model' ])
21 .controller('SearchCtrl', ['Model', '$routeParams', '$scope', '$window', function(Model
, $routeParams
, $scope
, $window
) {
24 $scope
.reset
= function() {
25 $scope
.activeItem
= 0;
29 $scope
.update
= function(e
) {
32 } else if(e
.keyCode
== 40) {
34 } else if(e
.keyCode
== 27) {
35 $scope
.selectEscape();
36 } else if(e
.keyCode
== 13) {
41 $scope
.selectUp
= function() {
42 if($scope
.activeItem
> 0) {
43 $scope
.activeItem
-= 1;
47 $scope
.selectDown
= function() {
48 if($scope
.activeItem
< $scope
.results
.length
- 1) {
49 $scope
.activeItem
+= 1;
53 $scope
.selectEnter
= function() {
54 $window
.location
.href
= $scope
.results
[$scope
.activeItem
].web_url
;
58 $scope
.selectEscape
= function() {
62 $scope
.search
= function() {
67 Model
.search($scope
.query
, 10,
70 $scope
.results
= data
;
80 .directive('uiFilters', function() {
89 templateUrl
: '/directives/ui-filter-button-vis.html',
90 link
: function ($scope
, element
, attrs
) {
91 $scope
.toggle
= function() {
92 $scope
.property
= !$scope
.property
;
98 .filter('visibility', function() {
99 return function(input
, visibilityFilter
) {
101 input
.forEach(function(entry
) {
102 if(visibilityFilter
.public == false && entry
.visibility
== "public") {
105 if(visibilityFilter
.protected == false && entry
.visibility
== "protected") {
108 if(visibilityFilter
.private == false && entry
.visibility
== "private") {
117 .directive('uiFilterForm', function() {
122 visibilityFilter
: '='
125 templateUrl
: '/directives/ui-filter-form.html'
129 .directive('uiFilterField', function() {
136 templateUrl
: '/directives/ui-filter-field.html'
140 .directive('uiFilterGroupVis', function() {
147 templateUrl
: '/directives/ui-filter-group-vis.html'
151 .directive('uiFilterButtonVis', function() {
160 templateUrl
: '/directives/ui-filter-button-vis.html',
161 link
: function ($scope
, element
, attrs
) {
162 $scope
.toggle
= function() {
163 $scope
.property
= !$scope
.property
;