Commit 8e1700fa authored by Kyle Keating's avatar Kyle Keating

Add focused user mode for speed grader

parent 59dbd146
'use strict';
const { createElement } = require('preact');
const propTypes = require('prop-types');
const { withServices } = require('../util/service-context');
function FocusedModeHeader({ settings }) {
return (
<div className="focused-mode-header">
Showing annotations by{' '}
<span className="focused-mode-header__user">{settings.focusedUser}</span>
</div>
);
}
FocusedModeHeader.propTypes = {
// Injected services.
settings: propTypes.object.isRequired,
};
FocusedModeHeader.injectedProps = ['settings'];
module.exports = withServices(FocusedModeHeader);
...@@ -125,6 +125,10 @@ function SidebarContentController( ...@@ -125,6 +125,10 @@ function SidebarContentController(
true true
); );
this.showFocusedHeader = () => {
return store.getState().focusedMode;
};
this.showSelectedTabs = function() { this.showSelectedTabs = function() {
if ( if (
this.selectedAnnotationUnavailable() || this.selectedAnnotationUnavailable() ||
...@@ -132,8 +136,11 @@ function SidebarContentController( ...@@ -132,8 +136,11 @@ function SidebarContentController(
store.getState().filterQuery store.getState().filterQuery
) { ) {
return false; return false;
} else if (store.getState().focusedMode) {
return false;
} else {
return true;
} }
return true;
}; };
this.setCollapsed = function(id, collapsed) { this.setCollapsed = function(id, collapsed) {
......
...@@ -10,6 +10,9 @@ function hostPageConfig(window) { ...@@ -10,6 +10,9 @@ function hostPageConfig(window) {
const configJSON = queryString.parse(window.location.search).config; const configJSON = queryString.parse(window.location.search).config;
const config = JSON.parse(configJSON || '{}'); const config = JSON.parse(configJSON || '{}');
// temp: hack to force user
config.focusedUser = 'kyle';
// Known configuration parameters which we will import from the host page. // Known configuration parameters which we will import from the host page.
// Note that since the host page is untrusted code, the filtering needs to // Note that since the host page is untrusted code, the filtering needs to
// be done here. // be done here.
...@@ -38,6 +41,9 @@ function hostPageConfig(window) { ...@@ -38,6 +41,9 @@ function hostPageConfig(window) {
// This should be removed once new note button is enabled for everybody. // This should be removed once new note button is enabled for everybody.
'enableExperimentalNewNoteButton', 'enableExperimentalNewNoteButton',
// Forces the sidebar to filter annotations to a single user.
'focusedUser',
// Fetch config from a parent frame. // Fetch config from a parent frame.
'requestConfigFromFrame', 'requestConfigFromFrame',
......
...@@ -180,6 +180,10 @@ function startAngularApp(config) { ...@@ -180,6 +180,10 @@ function startAngularApp(config) {
'searchStatusBar', 'searchStatusBar',
wrapReactComponent(require('./components/search-status-bar')) wrapReactComponent(require('./components/search-status-bar'))
) )
.component(
'focusedModeHeader',
wrapReactComponent(require('./components/focused-mode-header'))
)
.component( .component(
'selectionTabs', 'selectionTabs',
wrapReactComponent(require('./components/selection-tabs')) wrapReactComponent(require('./components/selection-tabs'))
......
...@@ -39,7 +39,7 @@ const sortFns = { ...@@ -39,7 +39,7 @@ const sortFns = {
* The root thread is then displayed by viewer.html * The root thread is then displayed by viewer.html
*/ */
// @ngInject // @ngInject
function RootThread($rootScope, store, searchFilter, viewFilter) { function RootThread($rootScope, settings, store, searchFilter, viewFilter) {
/** /**
* Build the root conversation thread from the given UI state. * Build the root conversation thread from the given UI state.
* *
...@@ -50,15 +50,19 @@ function RootThread($rootScope, store, searchFilter, viewFilter) { ...@@ -50,15 +50,19 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
const sortFn = sortFns[state.sortKey]; const sortFn = sortFns[state.sortKey];
let filterFn; let filterFn;
if (state.filterQuery) { if (state.filterQuery || state.focusedMode) {
const filters = searchFilter.generateFacetedFilter(state.filterQuery); const filters = searchFilter.generateFacetedFilter(
state.filterQuery,
settings.focusedUser
);
filterFn = function(annot) { filterFn = function(annot) {
return viewFilter.filter([annot], filters).length > 0; return viewFilter.filter([annot], filters).length > 0;
}; };
} }
let threadFilterFn; let threadFilterFn;
if (state.isSidebar && !state.filterQuery) { const hasFilters = state.filterQuery || state.focusedMode;
if (state.isSidebar && !hasFilters) {
threadFilterFn = function(thread) { threadFilterFn = function(thread) {
if (!thread.annotation) { if (!thread.annotation) {
return false; return false;
......
...@@ -129,7 +129,7 @@ function toObject(searchtext) { ...@@ -129,7 +129,7 @@ function toObject(searchtext) {
* @param {string} searchtext * @param {string} searchtext
* @return {Object} * @return {Object}
*/ */
function generateFacetedFilter(searchtext) { function generateFacetedFilter(searchtext, focusedUser) {
let terms; let terms;
const any = []; const any = [];
const quote = []; const quote = [];
...@@ -138,7 +138,7 @@ function generateFacetedFilter(searchtext) { ...@@ -138,7 +138,7 @@ function generateFacetedFilter(searchtext) {
const tag = []; const tag = [];
const text = []; const text = [];
const uri = []; const uri = [];
const user = []; const user = focusedUser ? [focusedUser] : [];
if (searchtext) { if (searchtext) {
terms = tokenize(searchtext); terms = tokenize(searchtext);
......
...@@ -113,6 +113,8 @@ function init(settings) { ...@@ -113,6 +113,8 @@ function init(settings) {
selectedTab: TAB_DEFAULT, selectedTab: TAB_DEFAULT,
focusedMode: !!settings.focusedUser,
// Key by which annotations are currently sorted. // Key by which annotations are currently sorted.
sortKey: TAB_SORTKEY_DEFAULT[TAB_DEFAULT], sortKey: TAB_SORTKEY_DEFAULT[TAB_DEFAULT],
// Keys by which annotations can be sorted. // Keys by which annotations can be sorted.
......
<focused-mode-header
ng-if="vm.showFocusedHeader()">
</focused-mode-header>
<selection-tabs <selection-tabs
ng-if="vm.showSelectedTabs()" ng-if="vm.showSelectedTabs()"
is-loading="vm.isLoading()"> is-loading="vm.isLoading()">
......
.focused-mode-header {
padding: 5px;
.focused-mode-header__user {
font-weight: 800;
}
}
...@@ -27,6 +27,7 @@ $base-line-height: 20px; ...@@ -27,6 +27,7 @@ $base-line-height: 20px;
@import './components/annotation-thread'; @import './components/annotation-thread';
@import './components/annotation-user'; @import './components/annotation-user';
@import './components/excerpt'; @import './components/excerpt';
@import './components/focused-mode-header';
@import './components/group-list'; @import './components/group-list';
@import './components/group-list-item'; @import './components/group-list-item';
@import './components/help-panel'; @import './components/help-panel';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment