Skip to content

Commit 7aa4e8c

Browse files
committed
Basic filtering on language and org
1 parent ecb42c5 commit 7aa4e8c

4 files changed

Lines changed: 1127 additions & 534 deletions

File tree

‎index.html‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ <h2 class="large-6 columns" data-magellan-destination="projects">Projects</h2>
6868
<div class="large-9 columns">
6969
<select id="orderby" class="medium" ng-model="filterOrder">
7070
<option value="" DISABLED>Order by:</option>
71-
<option value="watchers_count" selected>Popularity</option>
72-
<option value="pushed_at">Last Push</option>
71+
<option value="-watchers_count" selected>Popularity</option>
72+
<option value="-pushed_at">Last Push</option>
7373
<option value="org">Organisation</option>
7474
<option value="name">Name</option>
7575
</select>
@@ -84,24 +84,24 @@ <h2 class="large-6 columns" data-magellan-destination="projects">Projects</h2>
8484
</div>
8585

8686
<!-- ------- Filters -------- -->
87-
<div class="filters" ng-class="{flat: !toggleFilters}">
87+
<div class="filters" ng-class="{flat: toggleFilters}">
8888
<div class="row">
8989
<form class="custom large-12 columns mainFilters">
9090
<div class="large-4 columns">
9191
<input type="text" ng-model="searchName" placeholder="Search name, description...">
9292
</div>
9393

9494
<div class="large-3 columns">
95-
<input type="text" placeholder="Languages">
95+
<input type="text" ng-model="searchLang" placeholder="Languages">
9696
</div>
9797

9898
<div class="large-3 columns">
99-
<input type="text" placeholder="Organisations">
99+
<input type="text" ng-model="searchOrg" placeholder="Organisations">
100100
</div>
101101

102102
<div class="star large-2 columns">
103-
<img ng-src="img/star_on.svg" />
104-
<img ng-src="img/star_on.svg" />
103+
<img ng-src="img/star_off.svg" />
104+
<img ng-src="img/star_off.svg" />
105105
<img ng-src="img/star_off.svg" />
106106
<img ng-src="img/star_off.svg" />
107107
<img ng-src="img/star_off.svg" />

‎js/script.js‎

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,25 @@ app.filter('star', function() {
3636

3737
app.filter('projectsFilter', function() {
3838
return function(projects, scope) {
39-
console.info(scope.filterOrder);
40-
projects = scope.orderBy(scope.projects,(scope.filterOrder) ? "-"+scope.filterOrder : "-watchers_count");
41-
return projects.slice(0, scope.projLast);
39+
projects = scope.filter('filter')(scope.projects, scope.searchName);
40+
var newProject = new Array();
41+
42+
if (scope.searchLang || scope.searchOrg) {
43+
for (var i = 0; i < projects.length; i++) {
44+
var actProj = projects[i];
45+
46+
var resLang = scope.filter('filter')(actProj.languages, scope.searchLang);
47+
var resOrg = actProj.org.indexOf(scope.searchOrg);
48+
console.log("Org: ", resOrg);
49+
if (resLang.length && (resOrg != -1 || !scope.searchOrg) ) {
50+
newProject.push(actProj);
51+
}
52+
}
53+
} else {
54+
newProject = projects;
55+
}
56+
projects = scope.filter('orderBy')(projects,(scope.filterOrder) ? scope.filterOrder : "-watchers_count");
57+
return newProject.slice(0, scope.projLast);
4258
};
4359
});
4460

@@ -136,12 +152,7 @@ app.factory("ReposAdobe", function($resource) {
136152
this.GitHubCtrl = function($scope, $filter, ReposAdobe, OrgsAdobe) {
137153
//Be able to call math functions
138154
$scope.Math = Math;
139-
$scope.orderBy = function(data, filter) {
140-
newData = $filter('orderBy')(data, filter);
141-
console.info(newData);
142-
143-
return newData;
144-
};
155+
$scope.filter = $filter;
145156

146157
//Loading active
147158
$scope.loading = true;
@@ -181,9 +192,11 @@ app.factory("GitAdobe", function($resource) {
181192

182193
//TODO : Manage offline project list when errors
183194
this.OfflineCtrl = function($scope, $filter, GitAdobe, OrgsAdobe) {
195+
//Initialize the project array
196+
$scope.projects = new Array();
197+
$scope.languages = new Array();
198+
184199
$scope.getOffline = function() {
185-
//Initialize the project array
186-
$scope.projects = new Array();
187200

188201
//Loading active
189202
$scope.loading = true;
@@ -229,6 +242,7 @@ this.OfflineCtrl = function($scope, $filter, GitAdobe, OrgsAdobe) {
229242
for (var key in repLang) {
230243
actProj.languages.push( { name: key, value: repLang[key] } );
231244
actProj.languagesTotal += repLang[key];
245+
$scope.addLanguage( { name: key, value: repLang[key] } );
232246
};
233247
});
234248
});
@@ -249,8 +263,26 @@ this.OfflineCtrl = function($scope, $filter, GitAdobe, OrgsAdobe) {
249263
});
250264

251265
});
252-
});
253-
}
266+
},
267+
function (data, status, headers, config) {
268+
console.log(response);
269+
});
270+
};
271+
272+
$scope.addLanguage = function (lang) {
273+
var isPresent = false;
274+
275+
for (var i = 0; i < $scope.languages.length; i++) {
276+
if ($scope.languages[i].name == lang.name) {
277+
isPresent = true;
278+
}
279+
}
280+
281+
console.log(lang, isPresent, $scope.languages);
282+
if ($scope.languages[lang.key]) {
283+
$scope.languages.push( lang );
284+
}
285+
}
254286
};
255287

256288

‎offline.html‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@
99
<title>Adobe Open Source - Offline pull</title>
1010

1111

12-
<link rel="stylesheet" href="css/app.css">
12+
<link rel="stylesheet" href="stylesheets/app.css">
1313
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
1414

1515
</head>
1616
<body ng-controller="OfflineCtrl">
17-
<input type="button" value="Load" ng-click="getOffline()"/>
17+
<input class="button" type="button" value="Load" ng-click="getOffline()"/>
1818
<div ng-hide="loading == false || loading == unknown">
1919
Loading...
2020
</div>
2121

2222
<textarea ng-show="loading == false">
2323
{{projects}}
2424
</textarea>
25+
26+
<textarea ng-show="loading == false">
27+
{{languages}}
28+
</textarea>
2529

2630
<script src="js/vendor/custom.modernizr.js"></script>
2731

0 commit comments

Comments
 (0)