1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 10:42:41 +01:00
phorge-phorge/webroot/rsrc/js/application/transactions/behavior-show-older-transactions.js

120 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* @provides javelin-behavior-phabricator-show-older-transactions
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
* phabricator-busy
*/
JX.behavior('phabricator-show-older-transactions', function(config) {
function get_hash() {
return window.location.hash.replace(/^#/, '');
}
function hash_is_hidden() {
var hash = get_hash();
if (!hash) {
return false;
}
// If the hash isn't purely numeric, ignore it. Comments always have
// numeric hashes. See PHI43 and T12970.
if (!hash.match(/^\d+$/)) {
return false;
}
var id = 'anchor-'+hash;
try {
JX.$(id);
} catch (not_found_exception) {
return true;
}
return false;
}
function check_hash() {
if (hash_is_hidden()) {
load_older(load_hidden_hash_callback);
}
}
function load_older(callback) {
var showOlderBlock = null;
try {
showOlderBlock = JX.DOM.find(
JX.$(config.timelineID),
'div',
'show-older-block');
} catch (not_found_exception) {
// we loaded everything...!
return;
}
var showOlderLink = JX.DOM.find(
showOlderBlock,
'a',
'show-older-link');
var workflow = fetch_older_workflow(
showOlderLink.href,
callback,
showOlderBlock);
var routable = workflow.getRoutable()
.setPriority(2000)
.setType('workflow');
JX.Router.getInstance().queue(routable);
}
var show_older = function(swap, r) {
JX.DOM.replace(swap, JX.$H(r.timeline).getFragment());
JX.Stratcom.invoke('resize');
};
var load_hidden_hash_callback = function(swap, r) {
show_older(swap, r);
// We aren't actually doing a scroll position because
// `behavior-watch-anchor` will handle that for us.
};
var load_all_older_callback = function(swap, r) {
show_older(swap, r);
load_older(load_all_older_callback);
};
var fetch_older_workflow = function(href, callback, swap) {
Remove "willRenderTimeline()" from ApplicationTransactionInterface Summary: Depends on D19914. Ref T11351. Some of the Phoilo rabbit holes go very deep. `PhabricatorApplicationTransactionInterface` currently requires you to implement `willRenderTimeline()`. Almost every object just implements this as `return $timeline`; only Pholio, Diffusion, and Differential specialize it. In all cases, they are specializing it mostly to render inline comments. The actual implementations are a bit of a weird mess and the way the data is threaded through the call stack is weird and not very modern. Try to clean this up: - Stop requiring `willRenderTimeline()` to be implemented. - Stop requiring `getApplicationTransactionViewObject()` to be implemented (only the three above, plus Legalpad, implement this, and Legalpad's implementation is a no-op). These two methods are inherently pretty coupled for almost any reasonable thing you might want to do with the timeline. - Simplify the handling of "renderdata" and call it "View Data". This is additional information about the current view of the transaction timeline that is required to render it correctly. This is only used in Differential, to decide if we can link an inline comment to an anchor on the same page or should link it to another page. We could perhaps do this on the client instead, but having this data doesn't seem inherently bad to me. - If objects want to customize timeline rendering, they now implement `PhabricatorTimelineInterface` and provide a `TimelineEngine` which gets a nice formal stack. This leaves a lot of empty `willRenderTimeline()` implementations hanging around. I'll remove these in the next change, it's just going to be deleting a couple dozen copies of an identical empty method implementation. Test Plan: - Viewed audits, revisions, and mocks with inline comments. - Used "Show Older" to page a revision back in history (this is relevant for "View Data"). - Grepped for symbols: willRenderTimeline, getApplicationTransactionViewObject, Legalpad classes. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T11351 Differential Revision: https://secure.phabricator.com/D19918
2018-12-19 20:52:53 +01:00
var params = {
viewData: JX.JSON.stringify(config.viewData)
};
return new JX.Workflow(href, params)
.setHandler(JX.bind(null, callback, swap));
};
JX.Stratcom.listen(
'click',
['show-older-block'],
function(e) {
e.kill();
var workflow = fetch_older_workflow(
JX.DOM.find(
e.getNode('show-older-block'),
'a',
'show-older-link').href,
show_older,
e.getNode('show-older-block'));
var routable = workflow.getRoutable()
.setPriority(2000)
.setType('workflow');
JX.Router.getInstance().queue(routable);
});
JX.Stratcom.listen('hashchange', null, check_hash);
check_hash();
new JX.KeyboardShortcut(['@'], 'Show all older changes in the timeline.')
.setHandler(JX.bind(null, load_older, load_all_older_callback))
.register();
});