From b6c11ac8249559d18e3549cb55dc2897d0aa9b60 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Tue, 2 Oct 2018 09:49:24 -0400 Subject: [PATCH 1/9] Use shared search-help-modal and remove search-dropdown --- CHANGELOG.md | 3 + app/locales/en/translations.ts | 8 +- app/locales/ja/translations.ts | 9 +- app/locales/zh/translations.ts | 15 +--- .../components/search-help-modal/component.ts | 4 +- .../components/search-dropdown/component.ts | 63 ------------- .../components/search-dropdown/styles.scss | 68 -------------- .../components/search-dropdown/template.hbs | 88 ------------------- .../components/search-dropdown/component.js | 1 - .../search-dropdown/component-test.ts | 13 --- 10 files changed, 8 insertions(+), 264 deletions(-) delete mode 100644 lib/osf-components/addon/components/search-dropdown/component.ts delete mode 100644 lib/osf-components/addon/components/search-dropdown/styles.scss delete mode 100644 lib/osf-components/addon/components/search-dropdown/template.hbs delete mode 100644 lib/osf-components/app/components/search-dropdown/component.js delete mode 100644 tests/integration/components/search-dropdown/component-test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b212f29200..19457b4f451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `token` - `scope` - Components: + - `search-help-modal` - you know, the search help modal but as it's own component - `draft-registration-card` - summary card for draft registrations - `node-list` - produce a paginated list of nodes from a relationship - `copyable-text` - display some read-only text with a button to copy it @@ -143,6 +144,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `metaschema` (including related adapter & serializer) - Services: - `file-manager` (including skipped tests and one unused reference) +- Components: + - `search-dropdown` (Unused) ## [0.7.0] - 2018-08-07 ### Added diff --git a/app/locales/en/translations.ts b/app/locales/en/translations.ts index 7c1f4e8185e..bba30a71a2a 100644 --- a/app/locales/en/translations.ts +++ b/app/locales/en/translations.ts @@ -259,12 +259,6 @@ export default { user_gravatar: 'User gravatar', toggle_auth_dropdown: 'Toggle auth dropdown', }, - search_help_modal: { - close: 'Close', - search_help: 'Search help', - queries: 'Queries', - paragraph: 'Search uses the Lucene search syntax. This gives you many options, but can be very simple as well. Examples of valid searches include:', - }, support: { title: 'Support', faq_title: 'Frequently asked questions', @@ -782,7 +776,7 @@ export default { close: 'Close', title: 'Search help', queries: 'Queries', - searchSyntax: 'Search uses the Lucene search syntax', + searchSyntax: 'Search uses the Lucene search syntax.', helpDescription: 'This gives you many options, but can be very simple as well. Examples of valid searches include:', }, search_paginator: { diff --git a/app/locales/ja/translations.ts b/app/locales/ja/translations.ts index 16820462aa6..391290631f7 100644 --- a/app/locales/ja/translations.ts +++ b/app/locales/ja/translations.ts @@ -782,7 +782,7 @@ export default { close: 'Close', title: 'Search help', queries: 'Queries', - searchSyntax: 'Search uses the Lucene search syntax', + searchSyntax: 'Search uses the Lucene search syntax.', helpDescription: 'This gives you many options, but can be very simple as well. Examples of valid searches include:', }, search_paginator: { @@ -1167,11 +1167,4 @@ export default { }, }, }, - searchHelp: { - close: 'Close', - title: 'Search help', - helpDescription: 'This gives you many options, but can be very simple as well. Examples of valid searches include:', - queries: 'Queries', - searchSyntax: 'Search uses the Lucene search syntax', - }, }; diff --git a/app/locales/zh/translations.ts b/app/locales/zh/translations.ts index 304d4b2ef3e..2ebd9bd4d3b 100644 --- a/app/locales/zh/translations.ts +++ b/app/locales/zh/translations.ts @@ -259,12 +259,6 @@ export default { user_gravatar: 'User gravatar', toggle_auth_dropdown: 'Toggle auth dropdown', }, - search_help_modal: { - close: 'Close', - search_help: 'Search help', - queries: 'Queries', - paragraph: 'Search uses the Lucene search syntax. This gives you many options, but can be very simple as well. Examples of valid searches include:', - }, support: { title: 'Support', faq_title: 'Frequently asked questions', @@ -782,7 +776,7 @@ export default { close: 'Close', title: 'Search help', queries: 'Queries', - searchSyntax: 'Search uses the Lucene search syntax', + searchSyntax: 'Search uses the Lucene search syntax.', helpDescription: 'This gives you many options, but can be very simple as well. Examples of valid searches include:', }, search_paginator: { @@ -1167,11 +1161,4 @@ export default { }, }, }, - searchHelp: { - close: 'Close', - title: 'Search help', - helpDescription: 'This gives you many options, but can be very simple as well. Examples of valid searches include:', - queries: 'Queries', - searchSyntax: 'Search uses the Lucene search syntax', - }, }; diff --git a/lib/app-components/addon/components/search-help-modal/component.ts b/lib/app-components/addon/components/search-help-modal/component.ts index 88469c3a355..ec522a5f3e9 100644 --- a/lib/app-components/addon/components/search-help-modal/component.ts +++ b/lib/app-components/addon/components/search-help-modal/component.ts @@ -1,7 +1,7 @@ import { service } from '@ember-decorators/service'; import { getOwner } from '@ember/application'; import Component from '@ember/component'; -import { Registry as Services } from '@ember/service'; +import RouterService from '@ember/routing/router-service'; import defaultTo from 'ember-osf-web/utils/default-to'; import styles from './styles'; import layout from './template'; @@ -19,7 +19,7 @@ export default class SearchHelpModal extends Component { layout = layout; styles = styles; - @service router!: Services['router']; + @service router!: RouterService; isOpen: boolean = defaultTo(this.isOpen, false); diff --git a/lib/osf-components/addon/components/search-dropdown/component.ts b/lib/osf-components/addon/components/search-dropdown/component.ts deleted file mode 100644 index c83b8b270a5..00000000000 --- a/lib/osf-components/addon/components/search-dropdown/component.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { action } from '@ember-decorators/object'; -import { service } from '@ember-decorators/service'; -import Component from '@ember/component'; -import config from 'ember-get-config'; -import I18N from 'ember-i18n/services/i18n'; -import Analytics from 'ember-osf-web/services/analytics'; -import defaultTo from 'ember-osf-web/utils/default-to'; -import styles from './styles'; -import layout from './template'; - -const { OSF: { url } } = config; - -function getQuery(text: string) { - return `${url}search/?q=${encodeURIComponent(text)}`; -} - -interface SearchExample { - link: string; - text: string; -} - -/** - * @module ember-osf-web - * @submodule components - */ - -/** - * Display a search dropdown as used in the OSF navbar - * - * Sample usage: - * ```handlebars - * {{search-dropdown closeSearchAction=(action 'closeSearch')}} - * ``` - * @class search-dropdown - */ -export default class SearchDropdown extends Component { - layout = layout; - styles = styles; - - @service analytics!: Analytics; - @service i18n!: I18N; - - closeSearchAction?: () => void; - - isOpen: boolean = defaultTo(this.isOpen, false); - query: string = defaultTo(this.query, ''); - - searchExamples: SearchExample[] = [ - 'repro*', - 'brian AND title:many', - 'tags:(psychology)', - ].map(text => ({ - link: getQuery(text), - text, - })); - - @action - search() { - if (this.query) { - window.location.href = getQuery(this.query); - } - } -} diff --git a/lib/osf-components/addon/components/search-dropdown/styles.scss b/lib/osf-components/addon/components/search-dropdown/styles.scss deleted file mode 100644 index 736f4b56175..00000000000 --- a/lib/osf-components/addon/components/search-dropdown/styles.scss +++ /dev/null @@ -1,68 +0,0 @@ -/* stylelint-disable */ - -.search-label-placeholder { - position:absolute; - left: 0; - right: 0; - bottom: 0; - font-size: 20px; - color: #738EA2; - font-weight: 300; - visibility: hidden; -} - -.osf-search { - padding: 10px 0; - background: #B8ECC0; - position: fixed; - width: 100%; - box-shadow: 0 0 9px -2px #464545; - left: 0; - top: 50px; - z-index: 1030; /* Should not less than 1030 */ -} - -.osf-search-input { - background: none; - border: none; - box-shadow: none; - border-bottom: 1px dotted #FFF; - border-radius: 0; - padding: 0 0; - font-size: 20px; - color: #214762; - font-weight: 300; -} -.osf-search-input:focus { - outline : 0 !important; - box-shadow: none; - border-bottom: 1px dotted #FFF; -} -.osf-search-btn { - color: #214762; - background: rgba(0, 0, 0, 0); -} - -.osf-search-btn:hover { - color: #738EA2; -} - - -#searchPageFullBar::-webkit-input-placeholder { - color: #738EA2; -} - -#searchPageFullBar:-moz-placeholder { /* Firefox 18- */ - color: #738EA2; -} - -#searchPageFullBar::-moz-placeholder { /* Firefox 19+ */ - color: #738EA2; -} - -#searchPageFullBar:-ms-input-placeholder { - color: #738EA2; -} -#searchControls>.row { - padding-top: 60px; -} diff --git a/lib/osf-components/addon/components/search-dropdown/template.hbs b/lib/osf-components/addon/components/search-dropdown/template.hbs deleted file mode 100644 index 120ee62c7b9..00000000000 --- a/lib/osf-components/addon/components/search-dropdown/template.hbs +++ /dev/null @@ -1,88 +0,0 @@ -{{!Green OSF Search bar}} - - -{{!Search help modal - appears after clicking question mark on green search dropdown}} -{{#bs-modal open=isOpen onHidden=(action (mut isOpen) false) as |modal|}} - {{#modal.header}} - - {{/modal.header}} - {{#modal.body}} -

{{t 'search_help_modal.queries'}}

-

- {{t 'search_help_modal.paragraph' link='http://extensions.xwiki.org/xwiki/bin/view/Extension/Search+Application+Query+Syntax'}} -

- - {{/modal.body}} - {{#modal.footer}} -
- -
- {{/modal.footer}} -{{/bs-modal}} \ No newline at end of file diff --git a/lib/osf-components/app/components/search-dropdown/component.js b/lib/osf-components/app/components/search-dropdown/component.js deleted file mode 100644 index 36e4bb21dcc..00000000000 --- a/lib/osf-components/app/components/search-dropdown/component.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'osf-components/components/search-dropdown/component'; diff --git a/tests/integration/components/search-dropdown/component-test.ts b/tests/integration/components/search-dropdown/component-test.ts deleted file mode 100644 index 8f61ae2d6e8..00000000000 --- a/tests/integration/components/search-dropdown/component-test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { render } from '@ember/test-helpers'; -import { setupRenderingTest } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; -import { module, test } from 'qunit'; - -module('Integration | Component | search-dropdown', hooks => { - setupRenderingTest(hooks); - - test('it renders', async function(assert) { - await render(hbs`{{search-dropdown}}`); - assert.dom(this.element).hasText('Search'); - }); -}); From 86e2dd844852f5f300b31a87025e834d9cf04d7b Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Tue, 2 Oct 2018 15:10:34 -0400 Subject: [PATCH 2/9] Render TeX expression in registries search results --- CHANGELOG.md | 2 + lib/app-components/addon/helpers/math.ts | 97 +++++++++++++++++++ lib/app-components/app/helpers/math.js | 1 + lib/app-components/index.js | 15 +++ lib/app-components/package.json | 3 +- .../registries-search-result/styles.scss | 22 +++++ .../registries-search-result/template.hbs | 19 ++-- package.json | 1 + tests/unit/helpers/math-test.ts | 49 ++++++++++ types/katex/index.d.ts | 10 ++ yarn.lock | 10 ++ 11 files changed, 217 insertions(+), 12 deletions(-) create mode 100644 lib/app-components/addon/helpers/math.ts create mode 100644 lib/app-components/app/helpers/math.js create mode 100644 tests/unit/helpers/math-test.ts create mode 100644 types/katex/index.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 19457b4f451..6b6f0ebda57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `tags-widget` - added to the handbook - Utils: - `param` - drop-in replacement for jQuery.param +- Helpers: + - `math` - A helper to render TeX statements using KaTeX ### Changed - Models: diff --git a/lib/app-components/addon/helpers/math.ts b/lib/app-components/addon/helpers/math.ts new file mode 100644 index 00000000000..d8b46bc1bf5 --- /dev/null +++ b/lib/app-components/addon/helpers/math.ts @@ -0,0 +1,97 @@ +import Helper from '@ember/component/helper'; +import { htmlSafe } from '@ember/string'; +import katex, { KatexRenderOptions } from 'katex'; + +export interface Delimiter { + start: string; + end: string; + inline: boolean; +} + +interface Match { + start: number; + end: number; + delimiter: Delimiter; +} + +// Adapted from https://github.com/Khan/KaTeX/blob/master/contrib/auto-render/splitAtDelimiters.js +export function findEnd(content: string, start: number, end: string) { + let contextLevel = 0; + + for (let i = start; i < content.length; i++) { + if (contextLevel < 1 && content.startsWith(end, i)) { + return i + end.length; + } else if (content[i] === '{') { + contextLevel++; + } else if (content[i] === '}') { + contextLevel--; + } else if (content[i] === '\\') { + i++; + } + } + + return -1; +} + +export function replace(content: string, delimiters: Delimiter[], callback: (exp: string, delim: Delimiter) => string) { + const matches: Match[] = []; + + for (let i = 0; i < content.length; i++) { + for (const delimiter of delimiters) { + if (content.startsWith(delimiter.start, i)) { + const start = i; + const end = findEnd(content, i + delimiter.start.length, delimiter.end); + + // Skip empty matches and non-matches + if (end === -1 || end === i + delimiter.start.length + delimiter.end.length) { + continue; + } + + i = end; + matches.push({ end, start, delimiter }); + } + } + } + + let index = 0; + let result = ''; + + for (const match of matches) { + result += content.slice(index, match.start); + result += callback(content.slice( + match.start + match.delimiter.start.length, + match.end - match.delimiter.end.length, + ), match.delimiter); + + index = match.end; + } + + return result + content.slice(index); +} + +export const DELIMITERS: Delimiter[] = [ + { start: '$$', end: '$$', inline: false }, + { start: '\\[', end: '\\]', inline: false }, + { start: '$', end: '$', inline: true }, + { start: '\\(', end: '\\)', inline: true }, +]; + +export default class MathHelper extends Helper { + compute(params: string[]) { + const renderOptions: KatexRenderOptions = { + allowedProtocols: [], + }; + + return htmlSafe(replace(params[0], DELIMITERS, (expr, delim) => { + try { + return katex.renderToString(expr, { + ...renderOptions, + displayMode: !delim.inline, + }); + } catch (e) { + // If KaTeX fails to render, return the original expression + return expr; + } + })); + } +} diff --git a/lib/app-components/app/helpers/math.js b/lib/app-components/app/helpers/math.js new file mode 100644 index 00000000000..9d709ecd313 --- /dev/null +++ b/lib/app-components/app/helpers/math.js @@ -0,0 +1 @@ +export { default } from 'app-components/helpers/math'; diff --git a/lib/app-components/index.js b/lib/app-components/index.js index 70232418894..83e362ffaaf 100644 --- a/lib/app-components/index.js +++ b/lib/app-components/index.js @@ -1,5 +1,7 @@ /* eslint-env node */ +const fs = require('fs'); + module.exports = { name: 'app-components', @@ -14,4 +16,17 @@ module.exports = { ], }, }, + + included(app, ...args) { + this._super(app, ...args); + + const katexPath = 'node_modules/katex/dist'; + + for (const font of fs.readdirSync(`${katexPath}/fonts`)) { + this.import(`${katexPath}/fonts/${font}`, { destDir: 'assets/fonts' }); + } + + this.import(`${katexPath}/katex.css`); + this.import(`${katexPath}/katex.js`, { using: [{ transformation: 'amd', as: 'katex' }] }); + }, }; diff --git a/lib/app-components/package.json b/lib/app-components/package.json index a5b2c715736..869ac27768d 100644 --- a/lib/app-components/package.json +++ b/lib/app-components/package.json @@ -6,7 +6,6 @@ "dependencies": { "ember-bootstrap": "*", "ember-bootstrap-datepicker": "*", - "ember-component-attributes": "*", "ember-cli-babel": "*", "ember-cli-htmlbars": "*", "ember-cli-htmlbars-inline-precompile": "*", @@ -15,6 +14,7 @@ "ember-cli-template-lint": "*", "ember-cli-typescript": "*", "ember-collapsible-panel": "*", + "ember-component-attributes": "*", "ember-cp-validations": "*", "ember-css-modules": "*", "ember-css-modules-sass": "*", @@ -27,6 +27,7 @@ "ember-tag-input": "*", "ember-toastr": "*", "ember-wormhole": "*", + "katex": "*", "liquid-fire": "*" } } diff --git a/lib/registries/addon/components/registries-search-result/styles.scss b/lib/registries/addon/components/registries-search-result/styles.scss index b2041740557..786b902c15d 100644 --- a/lib/registries/addon/components/registries-search-result/styles.scss +++ b/lib/registries/addon/components/registries-search-result/styles.scss @@ -19,3 +19,25 @@ list-style: none; padding-left: 0; } + +.Description { + max-height: 42px; // Roughtly 2x line height; + overflow-y: hidden; + transition: max-height 0.5s cubic-bezier(0, 1, 0, 1); + + &.Expanded { + max-height: 500px; + transition: max-height 1s ease-in-out; + } +} + +.Details { + max-height: 0; + overflow-y: hidden; + transition: max-height 0.5s cubic-bezier(0, 1, 0, 1); + + &.Expanded { + max-height: 500px; + transition: max-height 1s ease-in-out; + } +} diff --git a/lib/registries/addon/components/registries-search-result/template.hbs b/lib/registries/addon/components/registries-search-result/template.hbs index 3265d3503cd..26a13389a28 100644 --- a/lib/registries/addon/components/registries-search-result/template.hbs +++ b/lib/registries/addon/components/registries-search-result/template.hbs @@ -4,7 +4,7 @@

{{#if osfID}} {{#link-to-external 'registration' osfID data-test-result-title-id=result.id}} - {{unescape-xml-entities result.title}} + {{math (unescape-xml-entities result.title)}} {{/link-to-external}} {{else}} - {{unescape-xml-entities result.title}} + {{math (unescape-xml-entities result.title)}} {{/if}} @@ -31,12 +31,8 @@ {{/if}} -

- {{#if expanded}} - {{unescape-xml-entities result.description}} - {{else}} - {{clip (unescape-xml-entities result.description) 300}} - {{/if}} +

+ {{math (unescape-xml-entities result.description)}}

@@ -51,7 +47,7 @@
- {{#if expanded}} +
    {{#each result.hyperLinks as |hyperlink index|}}
  • @@ -76,9 +72,10 @@
{{#each result.tags as |tag|}} - {{tag}} + {{math tag}} {{/each}} - {{/if}} + +
diff --git a/lib/registries/addon/services/share-search.ts b/lib/registries/addon/services/share-search.ts index bce9b36060e..f8226295a13 100644 --- a/lib/registries/addon/services/share-search.ts +++ b/lib/registries/addon/services/share-search.ts @@ -1,3 +1,4 @@ +import unescapeXMLEntities from 'ember-osf-web/utils/fix-special-char'; import { Map } from 'immutable'; import config from 'registries/config/environment'; import Search, { @@ -75,13 +76,19 @@ export class ShareTermsAggregation implements SearchModifier { } } +export interface ShareContributor { + id: string; + bibliographic: boolean; + citedAs: string; + identifiers: string[]; + name: string; + orderCited: number; +} + export interface ShareRegistration { id: string; description: string; - contributors: Array<{ - citedAs: string; - bibilographic: boolean; - }>; + contributors: ShareContributor[]; dateCreated?: Date; dateModified?: Date; datePublished?: Date; @@ -158,16 +165,15 @@ export default class ShareSearch extends Search { _postProcessRegistrations(registrations: any): ShareRegistration[] { return registrations.hits.hits.map((r: any): ShareRegistration => { const contributors = (r._source.lists.contributors || []) - .sort((a: any, b: any) => (a.order_cited || -1) - (b.order_cited || -1)) - .map((contrib: any) => ({ - users: Object.keys(contrib).reduce( - (acc: {[k: string]: any}, key: string) => ({ - ...acc, - [(key as any).camelize()]: contrib[key], - }), - { bibliographic: contrib.relation !== 'contributor' }, - ), - })); + .map((contrib: any): ShareContributor => ({ + bibliographic: contrib.relation !== 'contributor', + citedAs: unescapeXMLEntities(contrib.cited_as), + id: contrib.id, + identifiers: contrib.identifiers, + name: unescapeXMLEntities(contrib.name), + orderCited: contrib.order_cited || -1, + } as ShareContributor)) + .sort((a: ShareContributor, b: ShareContributor) => a.orderCited - b.orderCited); let mainLink: string | undefined; const infoLinks: Array<{ type: string; uri: string; }> = []; @@ -206,15 +212,15 @@ export default class ShareSearch extends Search { ), mainLink: mainLink || hyperLinks[0], registrationType: r._source.registration_type, - title: r._source.title, + title: unescapeXMLEntities(r._source.title), subjects: r._source.subjects, subjectSynonyms: r._source.subject_synonyms, - description: r._source.description, + description: unescapeXMLEntities(r._source.description), dateUpdated: r._source.date_updated ? new Date(r._source.date_updated) : undefined, dateCreated: r._source.date_created ? new Date(r._source.date_created) : undefined, dateModified: r._source.date_modified ? new Date(r._source.date_modified) : undefined, datePublished: r._source.date_published ? new Date(r._source.date_published) : undefined, - tags: r._source.tags, + tags: r._source.tags.map(unescapeXMLEntities), withdrawn: r._source.withdrawn, }; }); diff --git a/tests/engines/registries/unit/services/search.ts b/tests/engines/registries/unit/services/search-test.ts similarity index 66% rename from tests/engines/registries/unit/services/search.ts rename to tests/engines/registries/unit/services/search-test.ts index 014b6cff6ff..b212c5d1e19 100644 --- a/tests/engines/registries/unit/services/search.ts +++ b/tests/engines/registries/unit/services/search-test.ts @@ -1,5 +1,5 @@ import { setupEngineTest } from 'ember-osf-web/tests/helpers/engines'; -import { OrderedSet } from 'immutable'; +import { is, OrderedSet } from 'immutable'; import { module, test } from 'qunit'; import { SearchFilter, SearchOptions } from 'registries/services/search'; @@ -20,17 +20,17 @@ class TestSearchFilter extends SearchFilter { } } -module('Unit | Registries | Service | Search', hooks => { +module('Registries | Unit | Service | search', hooks => { setupEngineTest(hooks, 'registries'); // Replace this with your real tests. test('it exists', function(assert) { - const service = this.owner.lookup('service:'); + const service = this.owner.lookup('service:search'); assert.ok(service); }); test('SearchOptions immutable', assert => { - const options = new SearchOptions({}); + const options = new SearchOptions({ page: 10 }); const changed = options.set('page', 420); assert.equal(options.page, 10); @@ -38,17 +38,30 @@ module('Unit | Registries | Service | Search', hooks => { }); test('SearchOptions equality', assert => { - assert.equal( + assert.ok(is( new SearchOptions({ query: 'Foo Bar' }), new SearchOptions({ query: 'Foo Bar' }), - ); + )); - assert.notEqual( + assert.notOk(is( new SearchOptions({ query: 'Foo Bar' }), - new SearchOptions({ query: 'Foo Bar' }), - ); + new SearchOptions({ query: 'Foo bar' }), + )); + + assert.ok(is( + new SearchOptions({ + filters: OrderedSet([ + new TestSearchFilter('Foo', 'foo', 43), + ]), + }), + new SearchOptions({ + filters: OrderedSet([ + new TestSearchFilter('Foo', 'foo', 43), + ]), + }), + )); - assert.equal( + assert.ok(is( new SearchOptions({ filters: OrderedSet([ new TestSearchFilter('Foo', 'foo', 43), @@ -60,6 +73,6 @@ module('Unit | Registries | Service | Search', hooks => { new TestSearchFilter('Foo', 'foo', 43), ]), }), - ); + )); }); }); diff --git a/tests/engines/registries/unit/services/share-search-test.ts b/tests/engines/registries/unit/services/share-search-test.ts new file mode 100644 index 00000000000..b24197f3597 --- /dev/null +++ b/tests/engines/registries/unit/services/share-search-test.ts @@ -0,0 +1,83 @@ +import { setupEngineTest } from 'ember-osf-web/tests/helpers/engines'; +import { TestContext } from 'ember-test-helpers'; +import { module, test } from 'qunit'; +import ShareSearch from 'registries/services/share-search'; + +const ES_RESPONSE = { + hits: { + hits: [{ + _index: 'share_customtax_1', + _type: 'creativeworks', + _id: '46218-570-0DA', + _score: null, + _source: { + id: '46218-570-0DA', + type: 'registration', + title: 'Pod Assignment &', + description: '<><', + language: null, + date_created: '2018-10-04T18:37:42.820512+00:00', + date_modified: '2018-10-04T18:37:42.82049+00:00', + date_updated: null, + date_published: '2018-10-04T16:22:11.995933+00:00', + registration_type: 'AsPredicted Preregistration', + withdrawn: false, + justification: null, + tags: ['&', 'Foo'], + identifiers: ['http://osf.io/w4yhb/'], + sources: ['OSF'], + subjects: [], + subject_synonyms: [], + lists: { + contributors: [{ + id: '6402D-242-421', + type: 'person', + name: 'Graham > Berlin', + given_name: 'Graham', + family_name: 'Berlin', + identifiers: ['http://osf.io/6j8ub/'], + order_cited: 0, + cited_as: 'Graham Berlin', + affiliations: [], + awards: [], + relation: 'creator', + }, { + id: '6415A-84F-065', + type: 'person', + name: 'Nicole < Grant', + given_name: 'Nicole', + family_name: 'Grant', + identifiers: ['http://osf.io/8zrkb/'], + order_cited: 4, + cited_as: 'Nicole Grant', + affiliations: [], + relation: 'creator', + }], + }, + }, + }], + }, +}; + +module('Registries | Unit | Service | share-search', hooks => { + setupEngineTest(hooks, 'registries'); + + // Replace this with your real tests. + test('it exists', function(assert) { + const service = this.owner.lookup('service:share-search'); + assert.ok(service); + }); + + test('_postProcessRegistrations', function(this: TestContext, assert) { + const service = this.owner.lookup('service:share-search') as ShareSearch; + + const registrations = service._postProcessRegistrations(ES_RESPONSE); + + assert.equal(registrations.length, 1); + assert.equal(registrations[0].title, 'Pod Assignment &'); + assert.equal(registrations[0].description, '<><'); + assert.equal(registrations[0].tags[0], '&'); + assert.equal(registrations[0].contributors[0].name, 'Graham > Berlin'); + assert.equal(registrations[0].contributors[1].name, 'Nicole < Grant'); + }); +}); From 513f04f1f4b4f76092b9d8c7974c6ba0a252a0f4 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Tue, 2 Oct 2018 16:20:22 -0400 Subject: [PATCH 4/9] Show all contributors in search results --- .../addon/components/comma-list/component.ts | 72 ------------------- .../addon/components/comma-list/styles.scss | 17 ----- .../addon/components/comma-list/template.hbs | 15 ---- .../components/comma-list/x-item/component.ts | 28 -------- .../components/comma-list/x-item/styles.scss | 19 ----- .../components/comma-list/x-item/template.hbs | 3 - .../registries-recent-list/styles.scss | 4 ++ .../registries-recent-list/template.hbs | 10 +-- .../registries-search-result/styles.scss | 21 ++++++ .../registries-search-result/template.hbs | 18 +++-- 10 files changed, 41 insertions(+), 166 deletions(-) delete mode 100644 lib/registries/addon/components/comma-list/component.ts delete mode 100644 lib/registries/addon/components/comma-list/styles.scss delete mode 100644 lib/registries/addon/components/comma-list/template.hbs delete mode 100644 lib/registries/addon/components/comma-list/x-item/component.ts delete mode 100644 lib/registries/addon/components/comma-list/x-item/styles.scss delete mode 100644 lib/registries/addon/components/comma-list/x-item/template.hbs diff --git a/lib/registries/addon/components/comma-list/component.ts b/lib/registries/addon/components/comma-list/component.ts deleted file mode 100644 index 6cd2e5703fd..00000000000 --- a/lib/registries/addon/components/comma-list/component.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { layout } from '@ember-decorators/component'; -import { computed } from '@ember-decorators/object'; -import Component from '@ember/component'; -import { task, timeout } from 'ember-concurrency'; -import { localClassNames } from 'ember-osf-web/decorators/css-modules'; -import styles from './styles'; -import template from './template'; -import itemStyles from './x-item/styles'; - -@layout(template) -@localClassNames('CommaList') -export default class CommaList extends Component { - static positionalParams = ['items']; - - items!: T[]; - cutOff?: number = undefined; - - resizeCallback: any; - - extra = 0; - - onResize = task(function *(this: CommaList) { - yield timeout(500); - - const results = this.$(`.${styles.CommaList__List}`); - if (!results || results.length < 1) { - return; - } - - const parentBounds = results[0].getBoundingClientRect(); - - const i = this.$(`.${itemStyles.Item}`).toArray().findIndex(el => { - return el.getBoundingClientRect().right > parentBounds.right; - }) - 1; - - this.set('cutOff', i > 0 ? i : undefined); - }).restartable(); - - @computed('cutOff', 'filteredItems.length') - get cutOffOrLast(this: CommaList) { - return this.cutOff || (this.filteredItems.length - 1); - } - - @computed('items.[]') - get filteredItems(this: CommaList) { - return this.items.filter(this.filter); - } - - @computed('extra', 'cutOff', 'filteredItems.length') - get unshown() { - return this.extra + (this.filteredItems.length - (this.cutOff ? this.cutOff + 1 : this.filteredItems.length)); - } - - @computed('unshown') - get hasUnshown() { - return this.unshown > 0; - } - - filter(item: T): boolean { - return Boolean(item); - } - - didInsertElement(this: CommaList) { - this.set('resizeCallback', () => this.get('onResize').perform()); - $(window).resize(this.resizeCallback); - this.resizeCallback(); - } - - willDestroyElement() { - $(window).off('resize', this.resizeCallback); - } -} diff --git a/lib/registries/addon/components/comma-list/styles.scss b/lib/registries/addon/components/comma-list/styles.scss deleted file mode 100644 index af39d071577..00000000000 --- a/lib/registries/addon/components/comma-list/styles.scss +++ /dev/null @@ -1,17 +0,0 @@ -.CommaList { - display: flex; -} - -.CommaList__List { - display: inline-flex; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - list-style: none; - padding-left: 0; - margin-bottom: 0; -} - -.CommaList__Extra { - white-space: nowrap; -} diff --git a/lib/registries/addon/components/comma-list/template.hbs b/lib/registries/addon/components/comma-list/template.hbs deleted file mode 100644 index 2acba62edb5..00000000000 --- a/lib/registries/addon/components/comma-list/template.hbs +++ /dev/null @@ -1,15 +0,0 @@ -
    - {{~#each filteredItems as |item index|~}} - {{#comma-list/x-item item index=index cutOff=cutOff length=filteredItems.length}} - {{~#if hasBlock ~}} - {{yield item}} - {{~else~}} - {{~item~}} - {{~/if~}} - {{/comma-list/x-item}} - {{~/each~}} -
- -{{#if hasUnshown}} - + {{unshown}} -{{/if}} diff --git a/lib/registries/addon/components/comma-list/x-item/component.ts b/lib/registries/addon/components/comma-list/x-item/component.ts deleted file mode 100644 index 62c28cc56e1..00000000000 --- a/lib/registries/addon/components/comma-list/x-item/component.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { layout, tagName } from '@ember-decorators/component'; -import { computed } from '@ember-decorators/object'; -import Component from '@ember/component'; -import styles from './styles'; -import template from './template'; - -@tagName('') -@layout(template) -export default class CommaListItem extends Component { - static positionalParams = ['item']; - - styles = styles; - - item!: T; - index!: number; - length!: number; // eslint-disable-line no-restricted-globals - cutOff?: number; - - @computed('index', 'cutOff') - get isHidden() { - return Boolean(this.cutOff) && this.index > this.cutOff!; - } - - @computed('index', 'cutOff', 'length') - get isLast() { - return this.index === (this.cutOff || (this.length - 1)); - } -} diff --git a/lib/registries/addon/components/comma-list/x-item/styles.scss b/lib/registries/addon/components/comma-list/x-item/styles.scss deleted file mode 100644 index 0255c2907cb..00000000000 --- a/lib/registries/addon/components/comma-list/x-item/styles.scss +++ /dev/null @@ -1,19 +0,0 @@ -.Item { - display: inline-flex; - padding-right: 5px; - white-space: nowrap; - - &::after { - content: ', '; - } -} - -.Item.Last { - &::after { - content: ''; - } -} - -.Item.Hidden { - color: transparent; -} diff --git a/lib/registries/addon/components/comma-list/x-item/template.hbs b/lib/registries/addon/components/comma-list/x-item/template.hbs deleted file mode 100644 index 2537acb562d..00000000000 --- a/lib/registries/addon/components/comma-list/x-item/template.hbs +++ /dev/null @@ -1,3 +0,0 @@ -
- {{yield item}} -
diff --git a/lib/registries/addon/components/registries-recent-list/styles.scss b/lib/registries/addon/components/registries-recent-list/styles.scss index 091eae3094f..6e30377e6b9 100644 --- a/lib/registries/addon/components/registries-recent-list/styles.scss +++ b/lib/registries/addon/components/registries-recent-list/styles.scss @@ -13,6 +13,10 @@ } } +.SeeMore { + font-size: 16px; +} + .RecentList__Contributors { white-space: nowrap; text-overflow: ellipsis; diff --git a/lib/registries/addon/components/registries-recent-list/template.hbs b/lib/registries/addon/components/registries-recent-list/template.hbs index 1a5da077ed0..011193420cb 100644 --- a/lib/registries/addon/components/registries-recent-list/template.hbs +++ b/lib/registries/addon/components/registries-recent-list/template.hbs @@ -3,7 +3,7 @@

{{t "registries.index.recent.title"}} - + {{link-to (t 'registries.index.recent.more') 'discover'}}

@@ -15,8 +15,8 @@

{{reg.title}} @@ -28,8 +28,8 @@
    {{#each reg.contributors as |contrib|}} - {{#if contrib.users.bibliographic}} -
  • {{contrib.users.citedAs}}
  • + {{#if contrib.bibliographic}} +
  • {{contrib.name}}
  • {{/if}} {{/each}}
diff --git a/lib/registries/addon/components/registries-search-result/styles.scss b/lib/registries/addon/components/registries-search-result/styles.scss index 786b902c15d..2d4be81da52 100644 --- a/lib/registries/addon/components/registries-search-result/styles.scss +++ b/lib/registries/addon/components/registries-search-result/styles.scss @@ -41,3 +41,24 @@ transition: max-height 1s ease-in-out; } } + +.Contributors { + display: flex; + flex-direction: row; + flex-wrap: wrap; + list-style: none; + padding-left: 0; + + & > li { + display: inline-flex; + padding-right: 5px; + + &::after { + content: ', '; + } + } + + & > li:last-child::after { + content: ''; + } +} diff --git a/lib/registries/addon/components/registries-search-result/template.hbs b/lib/registries/addon/components/registries-search-result/template.hbs index 5fb2aa6c0a6..d9348fb3b38 100644 --- a/lib/registries/addon/components/registries-search-result/template.hbs +++ b/lib/registries/addon/components/registries-search-result/template.hbs @@ -20,13 +20,17 @@ {{/if}}

- {{#comma-list this.contributors as |contrib|}} - {{#if contrib.link}} - {{contrib.name}} - {{else}} - {{contrib.name}} - {{/if}} - {{/comma-list}} +
    + {{#each this.contributors as |contrib|}} +
  • + {{#if contrib.link}} + {{contrib.name}} + {{else}} + {{contrib.name}} + {{/if}} +
  • + {{/each}} +
{{#if result.dateUpdated}}
From 1832760e600b662f47cc899930b98fb77b6d6225 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 3 Oct 2018 10:10:38 -0400 Subject: [PATCH 5/9] Reset to page 1 when changing queries --- lib/registries/addon/discover/controller.ts | 47 +++++++++++++------ lib/registries/addon/services/search.ts | 8 +++- lib/registries/addon/services/share-search.ts | 4 +- .../integration/discover/discover-test.ts | 2 +- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/lib/registries/addon/discover/controller.ts b/lib/registries/addon/discover/controller.ts index d8e95ef6ef9..4601f14374d 100644 --- a/lib/registries/addon/discover/controller.ts +++ b/lib/registries/addon/discover/controller.ts @@ -19,6 +19,11 @@ import ShareSearch, { } from 'registries/services/share-search'; import styles from './styles'; +interface DoSearchOptions { + scrollTop?: boolean; + noPageReset?: boolean; +} + interface DiscoverQueryParams { page: number; query: string; @@ -129,6 +134,9 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi @service analytics!: Analytics; @service shareSearch!: ShareSearch; + // List of keys that, when changed, reset the page to 1 + pageResetKeys = ['query', 'order', 'filter']; + results: EmberArray = A([]); searchable!: number; totalResults: number = 0; @@ -173,7 +181,7 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi return max; } - doSearch = task(function *(this: Discover, opts: SearchOptions, scrollTop?: boolean) { + doSearch = task(function *(this: Discover, opts: SearchOptions, { scrollTop, noPageReset }: DoSearchOptions = {}) { let options = opts; // Unless OSF is the only source, registration_type filters must be cleared @@ -182,6 +190,23 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi options = options.set('filters', options.filters.filter(filter => filter.key !== 'registration_type')); } + // If there is no query, no filters, and no sort, default to -date_modified rather + // than relevance. + if (!options.order.key && (!options.query || options.query === '') && options.filters.size === 0) { + options = options.set('order', new SearchOrder({ + display: '', + ascending: false, + key: 'date_modified', + })); + } + + // Latter bit is just a janky array intersection + // If any of the specified keys have changed, reset to the first page + if ((this.searchOptions && !noPageReset) && + this.searchOptions.differingKeys(options).filter(k => this.pageResetKeys.includes(k)).length > 0) { + options = options.set('page', 1); + } + this.set('searchOptions', options); this.setQueryParams(options); @@ -193,16 +218,6 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi yield timeout(250); - // If there is no query, no filters, and no sort, default to -date_modified rather - // than relevance. - if (!options.order.key && (!options.query || options.query === '') && options.filters.size === 0) { - options = options.set('order', new SearchOrder({ - display: '', - ascending: false, - key: 'date_modified', - })); - } - const results: SearchResults = yield this.shareSearch.registrations(options); this.set('results', A(results.results)); @@ -243,14 +258,18 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi page: event.queryParams.page, order: order || this.sortOptions[0], filters: OrderedSet(filters), - })); + }), { noPageReset: true }); } setQueryParams(this: Discover, options: SearchOptions) { this.set('page', options.page); this.set('size', options.size); this.set('query', options.query || ''); - this.set('sort', `${options.order.ascending ? '' : '-'}${options.order.key || ''}`); + + // date_modified is a weird case, so don't save it in a query param. + if (options.order.key !== 'date_modified') { + this.set('sort', `${options.order.ascending ? '' : '-'}${options.order.key || ''}`); + } const providers: string[] = []; const registrationTypes: string[] = []; @@ -277,7 +296,7 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi changePage(this: Discover, page: number) { this.get('doSearch').perform( this.searchOptions.set('page', page), - true, // Scroll to top + { scrollTop: true }, ); } diff --git a/lib/registries/addon/services/search.ts b/lib/registries/addon/services/search.ts index e7724189a35..5a66e231004 100644 --- a/lib/registries/addon/services/search.ts +++ b/lib/registries/addon/services/search.ts @@ -1,5 +1,5 @@ import Service from '@ember/service'; -import { Map, OrderedSet, ValueObject } from 'immutable'; +import { is, Map, OrderedSet, ValueObject } from 'immutable'; import $ from 'jquery'; // Used later on for slightly stricter typing of immutable Maps @@ -28,6 +28,12 @@ export class MapProxy implements ValueObject { hashCode(): number { return this.internal.hashCode(); } + + differingKeys(other: MapProxy): Array { + return Array.from(this.internal.filter( + (val, key) => !is(val, other.internal.get(key)), + ).keys()); + } } // Doesn't matter for types but useful for keeping all interfaces together. diff --git a/lib/registries/addon/services/share-search.ts b/lib/registries/addon/services/share-search.ts index f8226295a13..6e681b55e18 100644 --- a/lib/registries/addon/services/share-search.ts +++ b/lib/registries/addon/services/share-search.ts @@ -166,10 +166,10 @@ export default class ShareSearch extends Search { return registrations.hits.hits.map((r: any): ShareRegistration => { const contributors = (r._source.lists.contributors || []) .map((contrib: any): ShareContributor => ({ + id: contrib.id as string, bibliographic: contrib.relation !== 'contributor', citedAs: unescapeXMLEntities(contrib.cited_as), - id: contrib.id, - identifiers: contrib.identifiers, + identifiers: contrib.identifiers as string[], name: unescapeXMLEntities(contrib.name), orderCited: contrib.order_cited || -1, } as ShareContributor)) diff --git a/tests/engines/registries/integration/discover/discover-test.ts b/tests/engines/registries/integration/discover/discover-test.ts index 0e1fd4af6ee..cbb379e6536 100644 --- a/tests/engines/registries/integration/discover/discover-test.ts +++ b/tests/engines/registries/integration/discover/discover-test.ts @@ -42,7 +42,7 @@ const QueryParamTestCases: Array<{ expected: { query: '', order: new SearchOrder({ - display: '', + display: 'registries.discover.order.relevance', ascending: false, key: 'date_modified', }), From 8814645991ee307257adaa7b472f8a24a5455916 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 3 Oct 2018 10:13:26 -0400 Subject: [PATCH 6/9] Use sentence casing for consistency --- app/locales/en/translations.ts | 6 +++--- app/locales/ja/translations.ts | 4 ++-- app/locales/zh/translations.ts | 4 ++-- lib/registries/addon/discover/controller.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/locales/en/translations.ts b/app/locales/en/translations.ts index bba30a71a2a..577b7e65d44 100644 --- a/app/locales/en/translations.ts +++ b/app/locales/en/translations.ts @@ -954,11 +954,11 @@ export default { }, sidebar: { refine_your_search: 'Refine your search by', - clear_filters: 'Clear Filters', - active_filters: 'Active Filters', + clear_filters: 'Clear filters', + active_filters: 'Active filters', }, search_result: { - last_edited: 'Last Edited: {{date}}', + last_edited: 'Last edited: {{date}}', withdrawn: 'Withdrawn', }, pagination: { diff --git a/app/locales/ja/translations.ts b/app/locales/ja/translations.ts index 391290631f7..b5860bc8b89 100644 --- a/app/locales/ja/translations.ts +++ b/app/locales/ja/translations.ts @@ -961,10 +961,10 @@ export default { sidebar: { refine_your_search: 'Refine your search by', clear_filters: 'Clear Filters', - active_filters: 'Active Filters', + active_filters: 'Active filters', }, search_result: { - last_edited: 'Last Edited: {{date}}', + last_edited: 'Last edited: {{date}}', withdrawn: 'Withdrawn', }, pagination: { diff --git a/app/locales/zh/translations.ts b/app/locales/zh/translations.ts index 2ebd9bd4d3b..70882d3946d 100644 --- a/app/locales/zh/translations.ts +++ b/app/locales/zh/translations.ts @@ -955,10 +955,10 @@ export default { sidebar: { refine_your_search: 'Refine your search by', clear_filters: 'Clear Filters', - active_filters: 'Active Filters', + active_filters: 'Active filters', }, search_result: { - last_edited: 'Last Edited: {{date}}', + last_edited: 'Last edited: {{date}}', withdrawn: 'Withdrawn', }, pagination: { diff --git a/lib/registries/addon/discover/controller.ts b/lib/registries/addon/discover/controller.ts index 4601f14374d..113932c4147 100644 --- a/lib/registries/addon/discover/controller.ts +++ b/lib/registries/addon/discover/controller.ts @@ -194,7 +194,7 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi // than relevance. if (!options.order.key && (!options.query || options.query === '') && options.filters.size === 0) { options = options.set('order', new SearchOrder({ - display: '', + display: 'registries.discover.order.relevance', ascending: false, key: 'date_modified', })); From 9035583c9af771b13ee40e2f8b87c083aba40dc9 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 3 Oct 2018 12:42:40 -0400 Subject: [PATCH 7/9] Use shared paginator --- .../addon/components/search-paginator/styles.scss | 5 +++++ .../addon/components/search-paginator/template.hbs | 4 ++-- lib/registries/addon/discover/styles.scss | 5 +++++ lib/registries/addon/discover/template.hbs | 14 ++++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/app-components/addon/components/search-paginator/styles.scss b/lib/app-components/addon/components/search-paginator/styles.scss index b6761d2b2b6..30391ae94fd 100644 --- a/lib/app-components/addon/components/search-paginator/styles.scss +++ b/lib/app-components/addon/components/search-paginator/styles.scss @@ -1,3 +1,8 @@ +.ul { + list-style: none; + padding-left: 0; +} + .li { display: inline; diff --git a/lib/app-components/addon/components/search-paginator/template.hbs b/lib/app-components/addon/components/search-paginator/template.hbs index 6c7c7c0cdeb..b379e800d91 100644 --- a/lib/app-components/addon/components/search-paginator/template.hbs +++ b/lib/app-components/addon/components/search-paginator/template.hbs @@ -1,4 +1,4 @@ -
    +
      {{#each items as |item|}}
    • {{/each}} -
    \ No newline at end of file +
diff --git a/lib/registries/addon/discover/styles.scss b/lib/registries/addon/discover/styles.scss index c12b2f6cebe..f3b4bb31c45 100644 --- a/lib/registries/addon/discover/styles.scss +++ b/lib/registries/addon/discover/styles.scss @@ -33,3 +33,8 @@ color: #eee; } } + +.Pagination { + display: inline-flex; + justify-content: flex-end; +} diff --git a/lib/registries/addon/discover/template.hbs b/lib/registries/addon/discover/template.hbs index dd9d1fee3ca..75d154301c0 100644 --- a/lib/registries/addon/discover/template.hbs +++ b/lib/registries/addon/discover/template.hbs @@ -65,14 +65,12 @@ {{/unless}} {{#if (gt maxPage 1) }} -
-
- {{search-paginator - current=searchOptions.page - maximum=maxPage - pageChanged=(action 'changePage') - }} -
+
+ {{search-paginator + current=searchOptions.page + maximum=maxPage + pageChanged=(action 'changePage') + }}
{{/if}} From 53d73e908c380a10d4c4b9e2b1bb69abd2a1b83c Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 3 Oct 2018 14:19:04 -0400 Subject: [PATCH 8/9] Allow customizing the signup campaign --- .../osf-navbar/auth-dropdown/component.ts | 16 ++++++++++++++-- .../addon/components/osf-navbar/template.hbs | 2 +- lib/registries/addon/application/template.hbs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/osf-components/addon/components/osf-navbar/auth-dropdown/component.ts b/lib/osf-components/addon/components/osf-navbar/auth-dropdown/component.ts index b0082062332..2630e1fc045 100644 --- a/lib/osf-components/addon/components/osf-navbar/auth-dropdown/component.ts +++ b/lib/osf-components/addon/components/osf-navbar/auth-dropdown/component.ts @@ -48,6 +48,8 @@ export default class NavbarAuthDropdown extends Component { */ redirectUrl?: string; + campaign?: string; + profileURL: string = defaultTo(this.profileURL, pathJoin(baseUrl, 'profile')); settingsURL: string = defaultTo(this.settingsURL, pathJoin(baseUrl, 'settings')); signUpURL: string = defaultTo(this.signUpURL, pathJoin(baseUrl, 'register')); @@ -60,12 +62,22 @@ export default class NavbarAuthDropdown extends Component { @computed('signUpURL', 'signUpNext') get signUpRoute() { return this.features.isEnabled(featureFlagNames.routes.register) ? 'register' : - `${this.signUpURL}?${param({ next: this.signUpNext })}`; + `${this.signUpURL}?${param(this.signUpQueryParams)}`; } @computed('router.currentRouteName', 'signUpNext') get signUpQueryParams() { - return this.router.currentRouteName === 'register' ? {} : { next: this.signUpNext }; + const params: Record = {}; + + if (this.campaign) { + params.campaign = this.campaign; + } + + if (this.router.currentRouteName !== 'register') { + params.next = this.signUpNext; + } + + return params; } @action diff --git a/lib/osf-components/addon/components/osf-navbar/template.hbs b/lib/osf-components/addon/components/osf-navbar/template.hbs index 6e907c654b4..e4ba60fad6d 100644 --- a/lib/osf-components/addon/components/osf-navbar/template.hbs +++ b/lib/osf-components/addon/components/osf-navbar/template.hbs @@ -65,7 +65,7 @@ {{/if}} {{/let}} - {{osf-navbar/auth-dropdown}} + {{osf-navbar/auth-dropdown campaign=@campaign}} {{/bs-collapse}}
diff --git a/lib/registries/addon/application/template.hbs b/lib/registries/addon/application/template.hbs index cc9eddbd33a..d06b849ae1c 100644 --- a/lib/registries/addon/application/template.hbs +++ b/lib/registries/addon/application/template.hbs @@ -1,7 +1,7 @@ {{title (t 'registries.application.page_title') replace=true}} {{#osf-header as |header|}} - {{#header.navbar activeService=activeService as |ctx|}} + {{#header.navbar campaign='osf-registries' activeService=activeService as |ctx|}} {{#ctx.links as |links|}} {{!links.quickfiles}} {{!links.myprojects}} From 71aa756074f7e8892d9c9507b4c3fcdaebdbb138 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Fri, 28 Sep 2018 13:24:34 -0400 Subject: [PATCH 9/9] Disable no-restricted-globals --- .eslintrc.js | 2 +- app/models/banner.ts | 2 +- app/models/collected-metadatum.ts | 2 +- app/models/file-provider.ts | 2 +- app/models/file.ts | 2 +- app/models/institution.ts | 2 +- app/models/license.ts | 2 +- app/models/node.ts | 2 +- app/models/provider.ts | 2 +- app/models/region.ts | 2 +- app/models/registration-schema.ts | 4 ++-- app/models/taxonomy.ts | 2 +- app/models/token.ts | 2 +- app/models/wiki.ts | 2 +- app/services/meta-tags.ts | 2 +- lib/collections/addon/components/discover-page/component.ts | 2 +- lib/collections/addon/discover/controller.ts | 2 +- lib/osf-components/addon/components/osf-navbar/component.ts | 1 - 18 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e963822e996..2469ef1a515 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -35,6 +35,7 @@ module.exports = { 'ember/no-attrs-in-components': 'error', 'ember/no-old-shims': 'error', 'import/prefer-default-export': 'off', + 'no-restricted-globals': 'off', }, overrides: [ { @@ -56,7 +57,6 @@ module.exports = { { files: ['**/*.d.ts'], rules: { - 'no-restricted-globals': 'off', 'no-useless-constructor': 'off', 'space-infix-ops': 'off', }, diff --git a/app/models/banner.ts b/app/models/banner.ts index ef56bb3ac0e..2a48e530593 100644 --- a/app/models/banner.ts +++ b/app/models/banner.ts @@ -5,7 +5,7 @@ import OsfModel from './osf-model'; export default class BannerModel extends OsfModel { @attr('date') startDate!: Date; @attr('date') endDate!: Date; - @attr('string') name!: string; // eslint-disable-line no-restricted-globals + @attr('string') name!: string; @attr('string') link!: string; @attr('string') mobileAltText!: string; @attr('string') defaultAltText!: string; diff --git a/app/models/collected-metadatum.ts b/app/models/collected-metadatum.ts index 11b34f553a6..cf34110d59e 100644 --- a/app/models/collected-metadatum.ts +++ b/app/models/collected-metadatum.ts @@ -59,7 +59,7 @@ export default class CollectedMetadatum extends OsfModel.extend(Validations) { @attr('string') collectedType?: string; @attr('string') issue?: string; @attr('string') programArea?: string; - @attr('string') status?: string; // eslint-disable-line no-restricted-globals + @attr('string') status?: string; @attr('subjects') subjects!: SubjectRef[][]; @attr('string') volume?: string; diff --git a/app/models/file-provider.ts b/app/models/file-provider.ts index 78c0d5cecd5..00d1dab8ef1 100644 --- a/app/models/file-provider.ts +++ b/app/models/file-provider.ts @@ -17,7 +17,7 @@ import Node from './node'; * @class FileProvider */ export default class FileProvider extends BaseFileItem { - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('string') path!: string; @attr('fixstring') provider!: string; @hasMany('file') files!: DS.PromiseManyArray; diff --git a/app/models/file.ts b/app/models/file.ts index ba003b6fd55..449be5096a0 100644 --- a/app/models/file.ts +++ b/app/models/file.ts @@ -20,7 +20,7 @@ import User from './user'; * @class File */ export default class File extends BaseFileItem { - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('fixstring') guid!: string; @attr('string') path!: string; @attr('number') size!: number; diff --git a/app/models/institution.ts b/app/models/institution.ts index 8554c43724e..5cdbc99f440 100644 --- a/app/models/institution.ts +++ b/app/models/institution.ts @@ -18,7 +18,7 @@ import User from './user'; * @class Institution */ export default class Institution extends OsfModel { - @attr('string') name!: string; // eslint-disable-line no-restricted-globals + @attr('string') name!: string; @attr('fixstring') description!: string; @attr('string') logoPath!: string; @attr('string') authUrl!: string; diff --git a/app/models/license.ts b/app/models/license.ts index 4ca00fb227f..13194075856 100644 --- a/app/models/license.ts +++ b/app/models/license.ts @@ -3,7 +3,7 @@ import { Deserialized } from 'ember-osf-web/transforms/node-license'; import OsfModel from './osf-model'; export default class License extends OsfModel { - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('fixstring') text!: string; @attr('array') requiredFields!: Array; } diff --git a/app/models/node.ts b/app/models/node.ts index 5db995340c2..9c73ec64672 100644 --- a/app/models/node.ts +++ b/app/models/node.ts @@ -104,7 +104,7 @@ export default class Node extends BaseFileItem.extend(Validations, CollectableVa contributors!: DS.PromiseManyArray; @belongsTo('node', { inverse: 'children' }) - parent!: DS.PromiseObject & Node; // eslint-disable-line no-restricted-globals + parent!: DS.PromiseObject & Node; @belongsTo('region') region!: Region; diff --git a/app/models/provider.ts b/app/models/provider.ts index 94132f40dd3..82e018a8261 100644 --- a/app/models/provider.ts +++ b/app/models/provider.ts @@ -21,7 +21,7 @@ export interface Assets { /* eslint-enable camelcase */ export default abstract class Provider extends OsfModel { - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('fixstring') description!: string; @attr('string') advisoryBoard!: string; @attr('fixstring') example!: string; diff --git a/app/models/region.ts b/app/models/region.ts index 275fe60ef67..230052a88e2 100644 --- a/app/models/region.ts +++ b/app/models/region.ts @@ -3,7 +3,7 @@ import { attr } from '@ember-decorators/data'; import OsfModel from './osf-model'; export default class RegionModel extends OsfModel { - @attr('string') name!: string; // eslint-disable-line no-restricted-globals + @attr('string') name!: string; } declare module 'ember-data' { diff --git a/app/models/registration-schema.ts b/app/models/registration-schema.ts index 73a895db26a..f77c15487a5 100644 --- a/app/models/registration-schema.ts +++ b/app/models/registration-schema.ts @@ -34,7 +34,7 @@ export interface Page { } export interface Schema { - name: string; // eslint-disable-line no-restricted-globals + name: string; title: string; version: number; active: boolean; @@ -63,7 +63,7 @@ export interface RegistrationMetadata { */ export default class RegistrationSchema extends OsfModel { @attr('boolean') active!: boolean; - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('number') schemaVersion!: number; @attr('object') schema!: Schema; } diff --git a/app/models/taxonomy.ts b/app/models/taxonomy.ts index 452865a6dbe..caa2277c232 100644 --- a/app/models/taxonomy.ts +++ b/app/models/taxonomy.ts @@ -23,7 +23,7 @@ export default class Taxonomy extends OsfModel { @attr('string') shareTitle!: string; @attr('string') path!: string; @attr('number') childCount!: number; - @attr('object') parent!: SubjectRef; // eslint-disable-line no-restricted-globals + @attr('object') parent!: SubjectRef; } declare module 'ember-data' { diff --git a/app/models/token.ts b/app/models/token.ts index 4b7a82570dc..546814dc8ad 100644 --- a/app/models/token.ts +++ b/app/models/token.ts @@ -15,7 +15,7 @@ const Validations = buildValidations({ }); export default class TokenModel extends OsfModel.extend(Validations) { - @attr('fixstring') name!: string; // eslint-disable-line no-restricted-globals + @attr('fixstring') name!: string; @attr('fixstring') tokenValue?: string; // Exposed only in response to token creation @hasMany('scope') scopes!: string[]; diff --git a/app/models/wiki.ts b/app/models/wiki.ts index 214911c205b..09feecce9ed 100644 --- a/app/models/wiki.ts +++ b/app/models/wiki.ts @@ -5,7 +5,7 @@ import OsfModel from './osf-model'; export default class Wiki extends OsfModel { @attr('string') kind!: string; - @attr('string') name!: string; // eslint-disable-line no-restricted-globals + @attr('string') name!: string; @attr('date') dateModified!: Date; @attr('object') extra!: any; diff --git a/app/services/meta-tags.ts b/app/services/meta-tags.ts index bfe89fe0960..cc1cd652424 100644 --- a/app/services/meta-tags.ts +++ b/app/services/meta-tags.ts @@ -37,7 +37,7 @@ export interface MetaTagsDefs { } export interface NameMetaTagAttrs { - name: string; // eslint-disable-line no-restricted-globals + name: string; content: Content; } diff --git a/lib/collections/addon/components/discover-page/component.ts b/lib/collections/addon/components/discover-page/component.ts index a01dcf5d30f..d490571bd1f 100644 --- a/lib/collections/addon/components/discover-page/component.ts +++ b/lib/collections/addon/components/discover-page/component.ts @@ -130,7 +130,7 @@ export default class DiscoverPage extends Component.extend({ taxonomy: string = defaultTo(this.taxonomy, ''); tags: string = defaultTo(this.tags, ''); type: string = defaultTo(this.type, ''); - status: string = defaultTo(this.status, ''); // eslint-disable-line no-restricted-globals + status: string = defaultTo(this.status, ''); collectedType: string = defaultTo(this.collectedType, ''); /** diff --git a/lib/collections/addon/discover/controller.ts b/lib/collections/addon/discover/controller.ts index 53773bd74c1..96ae5450a36 100644 --- a/lib/collections/addon/discover/controller.ts +++ b/lib/collections/addon/discover/controller.ts @@ -102,7 +102,7 @@ export default class Discover extends Controller { collectedType = ''; issue = ''; programArea = ''; - status = ''; // eslint-disable-line no-restricted-globals + status = ''; volume = ''; // Pass in the list of queryParams for this component diff --git a/lib/osf-components/addon/components/osf-navbar/component.ts b/lib/osf-components/addon/components/osf-navbar/component.ts index f1efc04a920..760b5774ee0 100644 --- a/lib/osf-components/addon/components/osf-navbar/component.ts +++ b/lib/osf-components/addon/components/osf-navbar/component.ts @@ -39,7 +39,6 @@ export default class OsfNavbar extends Component { showNavLinks: boolean = false; activeService: OSFService = defaultTo(this.activeService, OSFService.HOME); - // eslint-disable-next-line no-restricted-globals services: Array<{name: OSFService, route: string}> = defaultTo(this.services, OSF_SERVICES); @computed('activeService', 'router.currentRouteName')