Skip to content

Commit 6164a76

Browse files
committed
devices: add buttons to switch between Q and R devices
1 parent 7b0411c commit 6164a76

File tree

3 files changed

+55
-43
lines changed

3 files changed

+55
-43
lines changed

js/app.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
import Router from './router.js'
22

33
var navLinks = document.querySelectorAll(".nav-link");
4-
let currentRouter = Router.routes[window.location.hash];
5-
currentRouter.displayView();
4+
handleRoute(window.location.hash)
65

7-
if (window.location.hash) {
8-
manageActiveLink(window.location.hash)
6+
window.onpopstate = () => {
7+
handleRoute(window.location.hash)
8+
window.history.pushState(
9+
{},
10+
destination,
11+
window.location.origin + window.location.hash
12+
)
913
}
1014

11-
navLinks.forEach(link => {
12-
let destination = link.href
13-
if (destination) {
14-
link.onclick = function () {
15-
manageActiveLink(destination)
16-
let currentRouter = Router.routes[destination];
17-
window.history.pushState(
18-
{},
19-
destination,
20-
window.location.origin + destination
21-
)
22-
currentRouter.displayView()
23-
}
24-
}
25-
});
15+
function handleRoute(destination) {
16+
manageActiveLink(destination)
17+
let currentRouter = Object.keys(Router.routes)
18+
.filter(route =>
19+
route !== "" && destination.includes(route))
2620

27-
window.onpopstate = () => {
28-
let currentRouter = Router.routes[window.location.hash];
29-
currentRouter.displayView();
21+
if (destination.includes('/')) {
22+
Router.routes[currentRouter].displayView(destination)
23+
} else {
24+
Router.routes[currentRouter].displayView()
25+
}
3026
}
3127

3228
function manageActiveLink(hash) {

views/devices/devices.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
<div class="col-lg-10 mx-auto">
2-
<div class="row" id="device-list">
1+
<div class="col-lg-12">
2+
<div class="row justify-content-center">
3+
<div class="col-lg-2 col-md-3 col-sm-6">
4+
<a href="#devices/android-10" id="android-10" class="btn btn-light">Android Q (10)</a>
5+
</div>
6+
<div class="col-lg-2 col-md-3 col-sm-6">
7+
<a href="#devices/android-11" id="android-11" class="btn btn-light">Android R (11)</a>
8+
</div>
9+
</div>
10+
<div class="row justify-content-center" id="device-list">
11+
312
</div>
413
</div>

views/devices/devices.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { siteURL, container, showSpinner } from '../../js/const.js'
33
var devicesList = []
44
const gerritURL = 'https://gerrit.omnirom.org'
55
const rawURL = 'https://raw.githubusercontent.com/omnirom/'
6+
var currentVersion = 'android-11'
67

78
class DevicesView {
89

9-
async loadGithubRepos(branch) {
10+
async loadGithubRepos() {
1011
try {
1112
let response = await axios
12-
.get(gerritURL + "/projects/?b=" + branch + "&p=android_device", {
13+
.get(gerritURL + "/projects/?b=" + currentVersion + "&p=android_device", {
1314
});
1415

1516
let magic = ")]}'";
@@ -24,7 +25,7 @@ class DevicesView {
2425
}
2526

2627
async loadDevice(devices) {
27-
var requests = Object.keys(devices).map(repo => axios.get(rawURL + repo + "/android-10/meta/config.json"));
28+
var requests = Object.keys(devices).map(repo => axios.get(rawURL + repo + "/" + currentVersion + "/meta/config.json"));
2829
await Promise.allSettled(requests).then(results => {
2930
results.forEach(result => {
3031
if (result.value) {
@@ -61,8 +62,8 @@ class DevicesView {
6162

6263
devicesList.forEach(device => {
6364
const card = `
64-
<div class="card device-card" style="width: 18rem;">
65-
<img src="${device['image']}" class="card-img-top" width="250" alt="${device['model']}" >
65+
<div class="card device-card col-lg-3 col-md-4 col-sm-5">
66+
<img src="${device['image']}" class="card-img-top" alt="${device['model']}" >
6667
<div class="card-body">
6768
<h5 class="card-title">${device['model']}</h5>
6869
<p class="card-text">${device['make']}<br>${device['state']}</p>
@@ -73,26 +74,32 @@ class DevicesView {
7374
devicesContainer.innerHTML += card
7475
})
7576

77+
let activeButton = tempObject.querySelector('#' + currentVersion)
78+
activeButton.classList.add("btn-dark");
79+
7680
container.innerHTML = tempObject.innerHTML
7781
}
7882

79-
async displayView() {
83+
async displayView(hash) {
8084
try {
81-
if (devicesList.length === 0) {
82-
showSpinner(true);
83-
let d = {};
84-
d['model'] = "All Devices";
85-
d['make'] = "All Manufactures";
86-
d['state'] = "official";
87-
d['pageUrl'] = "https://dl.omnirom.org/";
88-
d['image'] = "/images/default_phone_omni.png";
89-
d['changelog'] = gerritURL + "/q/status:merged+android_device"
90-
devicesList.push(d)
91-
await this.loadGithubRepos('android-10');
92-
} else {
93-
this.showDevices()
85+
if (hash) {
86+
let androidVersion = hash.split("/")[1]
87+
if (androidVersion !== currentVersion) {
88+
currentVersion = androidVersion
89+
}
9490
}
9591

92+
devicesList = []
93+
showSpinner(true);
94+
let d = {};
95+
d['model'] = "All Devices";
96+
d['make'] = "All Manufactures";
97+
d['state'] = "official";
98+
d['pageUrl'] = "https://dl.omnirom.org/";
99+
d['image'] = "/images/default_phone_omni.png";
100+
d['changelog'] = gerritURL + "/q/status:merged+android_device"
101+
devicesList.push(d)
102+
await this.loadGithubRepos();
96103
} catch (error) {
97104
console.log("display device view error: " + error);
98105
}

0 commit comments

Comments
 (0)