-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
96 lines (86 loc) · 3.46 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
(function () {
const packages_json = 'packagelist.json';
let app = angular.module('LazarusPackages', []);
app.controller('PackagesController', ['$http', function ($http) {
this.packages = [];
this.categories = [];
this.selectedCategory = "*"
// Get packages json
$http.get(packages_json).then(response => {
let i = 0, has_packages = true;
// Create packages array
while (has_packages) {
if (response.data.hasOwnProperty('PackageData' + i)) {
this.packages.push({
data: response.data['PackageData' + i],
files: response.data['PackageFiles' + i]
});
i++;
} else {
has_packages = false;
}
}
// Create categories array from really used categories
this.categories.push("*");
for (let i = 0; i < this.packages.length; i++) {
if (this.packages[i].data.Category) {
let categs = this.packages[i].data.Category.split(", ");
for (let j = 0; j < categs.length; j++) {
if (this.categories.indexOf(categs[j]) == -1) {
this.categories.push(categs[j]);
}
}
}
}
this.categories.sort((a, b) => {
if (a > b)
return 1
if (a < b)
return -1
return 0
})
}).catch(response => {
// Do something if packages json is not reached
});
// Show items depending on search and selected category
this.show = (index) => {
var a, b, c = 0, d;
// Search
if (this.searchText) {
let terms = this.searchText.split(" ").map(v => v.toLowerCase());
for (let j = 0; j < terms.length; j++) {
a = this.packages[index].data.DisplayName.toLowerCase().indexOf(terms[j]) != -1;
b = false;
for (let i = 0; i < this.packages[index].files.length; i++) {
if (this.packages[index].files[i].Name.toLowerCase().indexOf(terms[j]) != -1
|| this.packages[index].files[i].Author.toLowerCase().indexOf(terms[j]) != -1
|| this.packages[index].files[i].Description.toLowerCase().indexOf(terms[j]) != -1
|| this.packages[index].files[i].License.toLowerCase().indexOf(terms[j]) != -1) {
b = true;
break;
}
}
if (!a && !b)
break;
c++;
}
c = c >= terms.length;
} else {
c = true;
}
// Selected category
if (this.selectedCategory != "*") {
d = this.packages[index].data.Category.toLowerCase().indexOf(this.selectedCategory) != -1;
} else {
d = true;
}
return c && d;
}
this.markText = () => {
var instance = new Mark(document.querySelector(".content"));
instance.unmark();
instance.mark(this.searchText);
}
}]);
})();