Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

Commit

Permalink
Rework the bug code to use Microdata and to support updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Jun 29, 2014
1 parent 406da47 commit f92396c
Show file tree
Hide file tree
Showing 8 changed files with 836 additions and 902 deletions.
178 changes: 94 additions & 84 deletions webroot/index.html

Large diffs are not rendered by default.

520 changes: 520 additions & 0 deletions webroot/static/scripts/bug.js

Large diffs are not rendered by default.

751 changes: 3 additions & 748 deletions webroot/static/scripts/bzdeck.js

Large diffs are not rendered by default.

148 changes: 144 additions & 4 deletions webroot/static/scripts/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,44 @@ BzDeck.DetailsPage.prototype.open = function (bug, bug_list = []) {
};

BzDeck.DetailsPage.prototype.prep_tabpanel = function (bug) {
let $template = document.querySelector('template#tabpanel-details'),
$tabpanel = BzDeck.global.fill_template($template.content, bug, true),
mobile = FlareTail.util.device.type.startsWith('mobile'),
let FTw = FlareTail.widget,
$tabpanel = document.querySelector('template#tabpanel-details').content
.cloneNode(true).firstElementChild,
$bug = this.view.$bug = $tabpanel.querySelector('article'),
$star_checkbox = $tabpanel.querySelector('[role="checkbox"][data-field="_starred"]');

// Assign unique IDs
$tabpanel.id = $tabpanel.id.replace(/TID/, bug.id);

if ($tabpanel.hasAttribute('aria-labelledby')) {
$tabpanel.setAttribute('aria-labelledby',
$tabpanel.getAttribute('aria-labelledby').replace(/TID/, bug.id));
}

for (let attr of ['id', 'aria-controls', 'aria-labelledby']) {
for (let $element of $tabpanel.querySelectorAll('[' + attr +']')) {
$element.setAttribute(attr, $element.getAttribute(attr).replace(/TID/, bug.id));
}
}

// Star on the header
(new FTw.Checkbox($star_checkbox)).bind('Toggled', event =>
BzDeck.core.toggle_star(bug.id, event.detail.checked));

for (let $area of $tabpanel.querySelectorAll('.scrollable')) {
// Custom scrollbar
let scrollbar = new FTw.ScrollBar($area);

if (scrollbar && $area.classList.contains('bug-timeline')) {
scrollbar.onkeydown_extend = BzDeck.timeline.handle_keydown.bind(scrollbar);
}

$area.tabIndex = 0;
}

BzDeck.bug.fill_data($bug, bug);

let mobile = FlareTail.util.device.type.startsWith('mobile'),
phone = FlareTail.util.device.type === 'mobile-phone',
$tablist = $tabpanel.querySelector('[role="tablist"]'),
_tablist = new FlareTail.widget.TabList($tablist),
Expand Down Expand Up @@ -240,7 +275,7 @@ BzDeck.DetailsPage.prototype.fetch_bug = function (id) {
if ($tabpanel) {
BzDeck.global.show_status('');
// Update UI
BzDeck.global.fill_template($tabpanel, bug);
BzDeck.bug.fill_data(this.view.$bug, bug);
$tab.title = this.get_tab_title(bug);
}
});
Expand All @@ -265,6 +300,111 @@ BzDeck.DetailsPage.prototype.navigate = function (id) {
BzDeck.detailspage = new BzDeck.DetailsPage(id, this.data.bug_list);
};

/* ----------------------------------------------------------------------------------------------
* Attachments
* ---------------------------------------------------------------------------------------------- */

BzDeck.DetailsPage.attachments = {};

BzDeck.DetailsPage.attachments.render = function ($bug, attachments, addition = false) {
let $placeholder = $bug.querySelector('[data-field="attachments"]');

if (!$placeholder || !attachments.length) {
return;
}

if (!addition) {
for (let $attachment of $placeholder.querySelectorAll('[itemprop="attachment"]')) {
$attachment.remove();
}
}

for (let att of attachments) {
let $attachment = $placeholder.appendChild(document.querySelector('#details-attachment')
.content.cloneNode(true).firstElementChild);

FlareTail.util.content.fill($attachment, {
'url': '/attachment/' + att.id,
'description': att.description,
'name': att.file_name,
'contentSize': (att.size / 1024).toFixed(2) + ' KB', // l10n
'encodingFormat': att.is_patch ? 'Patch' : att.content_type, // l10n
'uploadDate': att.creation_time,
'flag': [for (flag of att.flags || []) {
'creator': {
'name': flag.setter.name
},
'name': flag.name,
'status': flag.status
}],
'creator': {
'name': att.attacher.name
}
}, {
'data-attachment-id': att.id
});
}

$bug.querySelector('[id$="-tab-attachments"]').setAttribute('aria-hidden', 'false');
};

/* ----------------------------------------------------------------------------------------------
* History
* ---------------------------------------------------------------------------------------------- */

BzDeck.DetailsPage.history = {};

BzDeck.DetailsPage.history.render = function ($bug, history, addition = false) {
let $placeholder = $bug.querySelector('[data-field="history"]');

if (!$placeholder || !history.length) {
return;
}

let datetime = FlareTail.util.datetime,
conf_field = BzDeck.data.bugzilla_config.field,
$tbody = $placeholder.querySelector('tbody'),
$template = document.querySelector('#details-change');

let cell_content = (field, content) =>
['blocks', 'depends_on'].indexOf(field) > -1
? content.replace(/(\d+)/g, '<a href="/bug/$1" data-bug-id="$1">$1</a>')
: content.replace('@', '&#8203;@'); // ZERO WIDTH SPACE

if (!addition) {
$tbody.innerHTML = ''; // Remove the table rows
}

for (let hist of history) {
for (let [i, change] of Iterator(hist.changes)) {
let $row = $tbody.appendChild($template.content.cloneNode(true).firstElementChild),
$cell = field => $row.querySelector('[data-field="' + field + '"]');

if (i === 0) {
$cell('who').innerHTML = hist.changer.name.replace('@', '&#8203;@');
$cell('who').rowSpan = $cell('when').rowSpan = hist.changes.length;
datetime.fill_element($cell('when').appendChild(document.createElement('time')),
hist.change_time, { relative: false });
} else {
$cell('when').remove();
$cell('who').remove();
}

let _field = conf_field[change.field_name] ||
// Bug 909055 - Field name mismatch in history: group vs groups
conf_field[change.field_name.replace(/s$/, '')] ||
// If the Bugzilla config is outdated, the field name can be null
change.field_name;

$cell('what').textContent = _field.description;
$cell('removed').innerHTML = cell_content(change.field_name, change.removed);
$cell('added').innerHTML = cell_content(change.field_name, change.added);
}
}

$bug.querySelector('[id$="-tab-history"]').setAttribute('aria-hidden', 'false');
};

/* ----------------------------------------------------------------------------------------------
* Swipe navigation
* ---------------------------------------------------------------------------------------------- */
Expand Down
19 changes: 12 additions & 7 deletions webroot/static/scripts/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@ BzDeck.HomePage = function () {
});
}

let $bug = document.querySelector('#home-preview-pane article'),
$info = document.querySelector('#preview-bug-info').content.cloneNode(true).firstElementChild;

$bug.appendChild($info).id = 'home-preview-bug-info';

// Star on the header
let $star_checkbox = document.querySelector('#home-preview-bug header [data-field="_starred"]');
(new FTw.Checkbox($star_checkbox)).bind('Toggled', event => {
BzDeck.core.toggle_star(this.data.preview_id, event.detail.checked);
});

// Custom scrollbar (info)
new FTw.ScrollBar(document.querySelector('#home-preview-bug-info'));
new FTw.ScrollBar($info);

// Custom scrollbar (timeline)
let scrollbar = new FTw.ScrollBar(document.querySelector('#home-preview-bug-timeline'));

if (scrollbar) {
scrollbar.onkeydown_extend = BzDeck.global.handle_timeline_keydown.bind(scrollbar);
scrollbar.onkeydown_extend = BzDeck.timeline.handle_keydown.bind(scrollbar);
}

this.view = {};
Expand Down Expand Up @@ -212,30 +217,30 @@ BzDeck.HomePage = function () {

BzDeck.HomePage.prototype.show_preview = function (oldval, newval) {
let $pane = document.querySelector('#home-preview-pane'),
$template = document.querySelector('#home-preview-bug'),
$bug = document.querySelector('#home-preview-bug'),
button = this.view.details_button;

// Remove the current preview if exists

if (!newval) {
$template.setAttribute('aria-hidden', 'true');
$bug.setAttribute('aria-hidden', 'true');
button.data.disabled = true;

return;
}

BzDeck.model.get_bug_by_id(newval, bug => {
if (!bug) {
$template.setAttribute('aria-hidden', 'true');
$bug.setAttribute('aria-hidden', 'true');
button.data.disabled = true;

return;
}

// Fill the content
BzDeck.global.fill_template($template, bug);
BzDeck.bug.fill_data($bug, bug);
BzDeck.core.toggle_unread(bug.id, false);
$template.setAttribute('aria-hidden', 'false');
$bug.setAttribute('aria-hidden', 'false');
button.data.disabled = false;
});
};
Expand Down
20 changes: 12 additions & 8 deletions webroot/static/scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ BzDeck.SearchPage.prototype.setup_preview_pane = function () {
let FTw = FlareTail.widget,
ScrollBar = FTw.ScrollBar,
$pane = this.view.panes['preview']
= this.view.$tabpanel.querySelector('[id$="-preview-pane"]');
= this.view.$tabpanel.querySelector('[id$="-preview-pane"]'),
$bug = $pane.querySelector('article'),
$info = document.querySelector('#preview-bug-info').content.cloneNode(true).firstElementChild;

$bug.appendChild($info).id = $bug.id + '-info';

// Star on the header
let $star_checkbox = $pane.querySelector('[role="checkbox"][data-field="_starred"]');
Expand All @@ -370,29 +374,29 @@ BzDeck.SearchPage.prototype.setup_preview_pane = function () {
});

// Custom scrollbar (info)
new ScrollBar($pane.querySelector('[id$="-bug-info"]'));
new ScrollBar($info);

// Custom scrollbar (timeline)
let scrollbar = new ScrollBar($pane.querySelector('[id$="-bug-timeline"]'));

if (scrollbar) {
scrollbar.onkeydown_extend = BzDeck.global.handle_timeline_keydown.bind(scrollbar);
scrollbar.onkeydown_extend = BzDeck.timeline.handle_keydown.bind(scrollbar);
}
};

BzDeck.SearchPage.prototype.show_preview = function (oldval, newval) {
let $pane = this.view.panes['preview'],
$template = $pane.querySelector('[id$="-preview-bug"]');
$bug = $pane.querySelector('[id$="-preview-bug"]');

if (!newval) {
$template.setAttribute('aria-hidden', 'true');
$bug.setAttribute('aria-hidden', 'true');
return;
}

BzDeck.model.get_bug_by_id(newval, bug => {
if (!bug) {
// Unknown bug
$template.setAttribute('aria-hidden', 'true');
$bug.setAttribute('aria-hidden', 'true');
return;
}

Expand All @@ -406,8 +410,8 @@ BzDeck.SearchPage.prototype.show_preview = function (oldval, newval) {
}

// Fill the content
BzDeck.global.fill_template($template, bug);
$template.setAttribute('aria-hidden', 'false');
BzDeck.bug.fill_data($bug, bug);
$bug.setAttribute('aria-hidden', 'false');
});
};

Expand Down
2 changes: 1 addition & 1 deletion webroot/static/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ BzDeck.SettingsPage.prototype.activate_radiogroups = function () {

if (value === true) {
// Show media
for (let $attachment of document.querySelectorAll('[itemprop="associatedMedia"]')) {
for (let $attachment of document.querySelectorAll('[itemprop="attachment"]')) {
let $media = $attachment.querySelector('img, audio, video');

if ($media && !$media.src) {
Expand Down

0 comments on commit f92396c

Please sign in to comment.