Skip to content

Commit 849a853

Browse files
authored
New upcoming page (GoogleChrome#1426)
* Created Upcoming page by duplicating code from schedule page * The new upcoming page now uses Features and Channels API to fetch data * Fetching features of each milestone separately * Using csClient for fetching information * Removed unreferenced variable set from upcoming-page.js
1 parent a9650cd commit 849a853

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

app.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ handlers:
7777
script: pages.featurelist.app
7878
secure: always
7979

80+
- url: /upcoming
81+
script: pages.upcoming.app
82+
secure: always
83+
8084
- url: /features/schedule
8185
script: pages.schedule.app
8286
secure: always

pages/upcoming.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from __future__ import division
2+
from __future__ import print_function
3+
4+
# -*- coding: utf-8 -*-
5+
# Copyright 2021 Google Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License")
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
__author__ = 'shivam.agrawal.2000@gmail.com (Shivam Agarwal)'
20+
21+
from framework import basehandlers
22+
import settings
23+
24+
class UpcomingHandler(basehandlers.FlaskHandler):
25+
26+
TEMPLATE_PATH = 'upcoming.html'
27+
28+
def get_template_data(self):
29+
return {}
30+
31+
32+
app = basehandlers.FlaskApplication([
33+
('/upcoming', UpcomingHandler),
34+
], debug=settings.DEBUG)

static/js-src/cs-client.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ class ChromeStatusClient {
194194
`/features/${featureId}/approvals/${fieldId}/comments`,
195195
{state, comment});
196196
}
197+
198+
// Features API
199+
getFeaturesInMilestone(milestone) {
200+
return this.doGet(`/features?milestone?=${milestone}`);
201+
}
202+
203+
// Channels API
204+
getChannels() {
205+
return this.doGet('/channels');
206+
}
197207
};
198208

199209
exports.ChromeStatusClient = ChromeStatusClient;

static/js-src/upcoming-page.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Start fetching right away.
2+
const channelsArray = ['stable', 'beta', 'dev'];
3+
4+
const channelsPromise = window.csClient.getChannels();
5+
6+
7+
document.querySelector('.show-blink-checkbox').addEventListener('change', e => {
8+
e.stopPropagation();
9+
document.querySelector('chromedash-schedule').showBlink = e.target.checked;
10+
});
11+
12+
const header = document.querySelector('app-header-layout app-header');
13+
if (header) {
14+
header.fixed = false;
15+
}
16+
17+
async function init() {
18+
// Prepare data for chromedash-schedule
19+
const channels = await channelsPromise;
20+
let featuresPromise = {};
21+
22+
channelsArray.forEach((channel) => {
23+
featuresPromise[channel] = window.csClient.getFeaturesInMilestone(channels[channel].version);
24+
});
25+
26+
const features = {};
27+
28+
for (let channel of channelsArray) {
29+
features[channel] = await featuresPromise[channel];
30+
}
31+
32+
// Remove the loading sign once the data has been fetched from the APIs
33+
document.body.classList.remove('loading');
34+
35+
channelsArray.forEach((channel) => {
36+
channels[channel].components = mapFeaturesToComponents(features[channel].filter(f =>
37+
f.browsers.chrome.status.milestone_str === channels[channel].version));
38+
});
39+
40+
const scheduleEl = document.querySelector('chromedash-schedule');
41+
scheduleEl.channels = channels;
42+
43+
window.csClient.getStars().then((starredFeatureIds) => {
44+
scheduleEl.starredFeatures = new Set(starredFeatureIds);
45+
});
46+
}
47+
48+
function mapFeaturesToComponents(features) {
49+
const featuresMappedToComponents = {};
50+
features.forEach(f => {
51+
const components = f.browsers.chrome.blink_components;
52+
components.forEach(component => {
53+
if (!featuresMappedToComponents[component]) {
54+
featuresMappedToComponents[component] = [];
55+
}
56+
featuresMappedToComponents[component].push(f);
57+
});
58+
});
59+
60+
for (let [, feautreList] of Object.entries(featuresMappedToComponents)) {
61+
sortFeaturesByName(feautreList);
62+
}
63+
64+
return featuresMappedToComponents;
65+
}
66+
67+
68+
/**
69+
* @param {!Array<!Object>} features
70+
*/
71+
function sortFeaturesByName(features) {
72+
features.sort((a, b) => {
73+
a = a.name.toLowerCase();
74+
b = b.name.toLowerCase();
75+
if (a < b) {
76+
return -1;
77+
}
78+
if (a > b) {
79+
return 1;
80+
}
81+
return 0;
82+
});
83+
}
84+
85+
init();

static/sass/upcoming.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@import "vars";
2+
@import "layout";
3+
4+
body[data-path*='features/schedule'] {
5+
--app-drawer-width: 0;
6+
7+
app-drawer {
8+
display: none;
9+
}
10+
11+
#spinner {
12+
display: none;
13+
}
14+
15+
}
16+
17+
.hide-blink-checkbox {
18+
margin-right: 8px;
19+
}
20+
21+
#subheader {
22+
max-width: 100%;
23+
justify-content: center;
24+
}

templates/upcoming.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends "_base.html" %}
2+
{% load inline_file %}
3+
4+
{% block css %}
5+
<style>{% inline_file "/static/css/upcoming.css" %}</style>
6+
{% endblock %}
7+
8+
{% block subheader %}
9+
<div id="subheader">
10+
<!--<h2>Chrome release timeline</h2>-->
11+
<div style="flex:1">
12+
<h3>Release timeline</h3>
13+
<!-- p class="description">Please note, all dates are estimates and are subject to change.</p -->
14+
</div>
15+
<!-- <paper-toggle-button> doesn't working here. Related links:
16+
https://github.com/PolymerElements/paper-toggle-button/pull/132 -->
17+
<label><input type="checkbox" class="show-blink-checkbox">Show Blink components</label>
18+
</div>
19+
{% endblock %}
20+
21+
{% block content %}
22+
<section id="releases-section">
23+
<chromedash-schedule
24+
{% if user %}signedin{% endif %}
25+
{# TODO(jrobbins): Fix to work with google sign-in #}
26+
loginurl="#"
27+
></chromedash-schedule>
28+
</section>
29+
{% endblock %}
30+
31+
{% block js %}
32+
<script nonce="{{nonce}}">
33+
(function() {
34+
'use strict';
35+
36+
{% inline_file "/static/js/upcoming-page.min.js" %}
37+
})();
38+
</script>
39+
{% endblock %}

0 commit comments

Comments
 (0)