Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [21.8.0] - 2021-10-04
### Added
- bulk upload component `Branded::Moderation::-Components::UploadCsv`
- `registries.branded.moderation.settings` route

### Changed
- bump ember-template-lint

### Remove
- `registries.branded.moderation.notifications` route (now under `registries.branded.moderation.settings`)

## [21.7.0] - 2021-09-14
### Fixed
- A11y: Draft Registration Metadata Page - Critical WCAG 2A Rule Violations - Third Party Libraries
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import config from 'ember-get-config';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import { SafeString } from '@ember/template/-private/handlebars';
import Toast from 'ember-toastr/services/toast';

const { OSF: { apiUrl } } = config;

interface Args {
providerId: string;
}

interface ErrorMessage {
cell: string;
title: string;
detail: string | SafeString;
}
interface ApiErrorDetail {
header: string;
column_index: string;
row_index: string;
type: string;
invalidHeaders?: string[];
missingHeaders?: string[];
}
export default class UploadCsvComponent extends Component<Args> {
dropzoneOptions = {
createImageThumbnails: false,
method: 'PUT',
withCredentials: true,
preventMultipleFiles: true,
acceptDirectories: false,
};

@service intl!: Intl;
@service toast!: Toast;

@tracked errorMessages: ErrorMessage[] = [];
@tracked shouldShowErrorModal = false;
@tracked uploading: any[] = [];

@action
buildUrl(files: any) {
return `${apiUrl}/_/registries/${this.args.providerId}/bulk_create/${files[0].name}/`;
}

@action
addedFile(_: any, __: any, file: any) {
this.uploading.push(file);
}

@action
error(_: any, __: any, file: any, { errors }: { errors: ApiErrorDetail[]}) {
this.uploading.removeObject(file);
this.shouldShowErrorModal = true;
for (const error of errors) {
this.errorMessages.push(
{
cell: error.column_index + error.row_index,
title: this.intl.t(`registries.moderation.settings.${error.type}.title`),
detail: this.intl.t(`registries.moderation.settings.${error.type}.detail`, {
htmlSafe: true,
invalidIds: error.invalidHeaders ? error.invalidHeaders.join(', ') : null,
missingIds: error.missingHeaders ? error.missingHeaders.join(', ') : null,
}),
},
);
}
}

@action
success(_: any, __: any, file: any, ___: any) {
this.uploading.removeObject(file);
this.toast.success(this.intl.t('registries.moderation.settings.uploadSuccess'));
}

@action
closeErrorModal() {
this.shouldShowErrorModal = false;
this.errorMessages = [];
}

@action
async copyToClipboard(elementId: string) {
const mainElement = document.getElementById(elementId);
await navigator.clipboard.writeText(mainElement!.textContent!);
this.toast.success(this.intl.t('registries.moderation.settings.copyToClipboardSuccess'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.upload-zone-content {
text-align: center;
}

.upload-zone {
padding: 50px;
background: #f5f5f5;
border: 5px dashed #c7c7c7;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{{#let (unique-id 'upload-csv-dropzone') as |id|}}
<DropzoneWidget
@buildUrl={{this.buildUrl}}
@options={{this.dropzoneOptions}}
@dropzone={{false}}
@addedfile={{this.addedFile}}
@success={{this.success}}
@error={{this.error}}
@dragenter={{fn (mut this.dropping) true}}
@dragover={{fn (mut this.dropping) true}}
@drop={{fn (mut this.dropping) false}}
@dragleave={{fn (mut this.dropping) false}}
@enable={{true}}
@id={{id}}
@clickable={{array
(concat '.' (local-class 'upload-zone'))
}}
data-test-bulk-upload-widget
>
<div local-class='upload-zone'>
<div local-class='upload-zone-content'>
<FaIcon @icon='upload' @size='5x' />
<div
local-class='file-placeholder-text'
>
{{t 'registries.moderation.settings.dropCsvHere'}}
</div>
</div>
</div>
</DropzoneWidget>
{{/let}}

{{#let (unique-id 'main-content') as |id|}}
<OsfDialog
@isOpen={{this.shouldShowErrorModal}}
@onClose={{this.closeErrorModal}}
as |dialog|
>
<dialog.heading data-test-error-modal-heading>
{{t 'registries.moderation.settings.uploadError'}}
</dialog.heading>
<dialog.main id={{id}} data-test-error-modal-main>
<div data-test-error-modal-general-message>
<p>{{t 'registries.moderation.settings.generalErrorMessage' htmlSafe=true}}</p>
</div>

<dl data-test-error-modal-message-list>
{{#each this.errorMessages as |msg|}}
<p>
{{#if msg.cell}}
<dt data-test-error-modal-cell-identifier>{{t 'registries.moderation.settings.cell'}} {{msg.cell}}</dt>
{{/if}}
<dt data-test-error-modal-message-title>{{msg.title}}</dt>
<dd data-test-error-modal-message-detail>{{msg.detail}}</dd>
</p>
{{/each}}
</dl>
</dialog.main>
<dialog.footer>
<BsButton
data-test-copy-to-clipboard
data-analytics-name='Copy error messages to clipboard'
@type='primary'
{{on 'click' (fn this.copyToClipboard id)}}
>
{{t 'registries.moderation.settings.copyToClipboard'}}
</BsButton>
</dialog.footer>
</OsfDialog>
{{/let}}
17 changes: 0 additions & 17 deletions lib/registries/addon/branded/moderation/notifications/template.hbs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import config from 'ember-get-config';
import pathJoin from 'ember-osf-web/utils/path-join';
import { ReviewPermissions } from 'ember-osf-web/models/provider';

export default class BrandedModerationNotificationsController extends Controller {
export default class BrandedModerationSettingsController extends Controller {
userSettingsLink = pathJoin(config.OSF.url, 'settings', 'notifications');
@alias('model.id') providerId?: string;

get shouldShowBulkUploadWidget() {
return this.model.permissions.includes(ReviewPermissions.AddModerator);
}

@computed('providerId')
get subscriptionIds() {
return this.providerId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { inject as service } from '@ember/service';

import Analytics from 'ember-osf-web/services/analytics';

export default class BrandedModerationNotificationsRoute extends Route {
export default class BrandedModerationSettingsRoute extends Route {
@service analytics!: Analytics;

@action
Expand Down
27 changes: 27 additions & 0 deletions lib/registries/addon/branded/moderation/settings/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{page-title (t 'registries.moderation.settings.title') prepend=false}}

<h2>
{{t 'registries.moderation.settings.heading'}}
</h2>
<p>
{{t 'registries.moderation.settings.paragraph' link=this.userSettingsLink htmlSafe=true}}
</p>

<Subscriptions::Manager
@subscriptionIds={{this.subscriptionIds}}
as |manager|
>
<Subscriptions::List
@manager={{manager}}
/>
</Subscriptions::Manager>

{{#if this.shouldShowBulkUploadWidget}}
<h2>
{{t 'registries.moderation.settings.bulkUpload'}}
</h2>
<p>
{{t 'registries.moderation.settings.bulkUploadHelpText'}}
</p>
<Branded::Moderation::-Components::UploadCsv @providerId={{this.model.id}} />
{{/if}}
8 changes: 4 additions & 4 deletions lib/registries/addon/branded/moderation/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
</OsfLink>
</nav.item>
{{/let}}
{{#let 'registries.branded.moderation.notifications' as |notificationsRoute|}}
<nav.item @active={{eq this.target.currentRouteName notificationsRoute}}>
{{#let 'registries.branded.moderation.settings' as |settingsRoute|}}
<nav.item @active={{eq this.target.currentRouteName settingsRoute}}>
<OsfLink
@route={{notificationsRoute}}
@route={{settingsRoute}}
@models={{array this.model.id}}
>
{{t 'registries.moderation.notifications.title'}}
{{t 'registries.moderation.settings.title'}}
</OsfLink>
</nav.item>
{{/let}}
Expand Down
2 changes: 1 addition & 1 deletion lib/registries/addon/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default buildRoutes(function() {
this.route('moderation', function() {
this.route('submissions');
this.route('moderators');
this.route('notifications');
this.route('settings');
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-osf-web",
"version": "21.7.0",
"version": "21.8.0",
"description": "Ember front-end for the Open Science Framework",
"license": "Apache-2.0",
"author": "Center for Open Science <support@cos.io>",
Expand Down

This file was deleted.

Loading