Skip to content

Commit

Permalink
refs elan-ev#569 ADD Seriestitle Selection and Description, Setting C…
Browse files Browse the repository at this point in the history
…ontributor per default
  • Loading branch information
Dennis Pfahl committed Apr 16, 2020
1 parent 5493785 commit 5bdc550
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"save-creation-button-upload": "Upload to Opencast",
"save-creation-form-invalid": "Please set title and presenter",
"save-creation-label-presenter": "Presenter",
"save-creation-label-description": "Description",
"save-creation-label-title": "Title",
"save-creation-label-series": "Series",
"save-creation-title": "Almost done!",
"save-creation-title-done": "Done!",
"save-creation-subsection-title-download": "Download recording",
Expand Down
86 changes: 75 additions & 11 deletions src/opencast.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class Opencast {

updateGlobalOc = null;

IDS = new Map();

username = '';


// Creates a new instance. Static method instead of constructor because it
// needs to be async.
Expand Down Expand Up @@ -86,9 +90,47 @@ export class Opencast {

await catchRequestError(async () => await self.updateUser());

await self.handleSeriesIDSelection();

return self;
}


async getSeriesID() {
let headers = this.header();
let url = `${this.getServerUrl()}/admin-ng/series/series.json`
await fetch(url, {
credentials: 'same-origin',
redirect: 'manual',
headers,
method: 'get'
}).then(response => response.json()).then(data => {
for (let root in data) {
for (let enumerator in data[root]) {
this.IDS.set(data[root][enumerator]['id'], data[root][enumerator]['title']);
}
}
}).catch(error => this.IDS = {});

}



header() {
let headers = {};
if (this.getLoginUsername() && this.getLoginPassword()) {
const encoded = btoa(unescape(encodeURIComponent(
this.getLoginUsername() + ':' + this.getLoginPassword()
)));
headers = {'Authorization': `Basic ${encoded}`};
}
return headers;
}

async handleSeriesIDSelection() {
await this.getSeriesID();
}

// Updates the global OC instance from `this` to `newInstance`, IF the new
// instance is different. This should only be called when the settings are
// saved.
Expand Down Expand Up @@ -136,7 +178,7 @@ export class Opencast {
// the state or user object has changed in any way.
async updateUser() {
const newUser = await this.getInfoMe();

this.username = newUser.user.name;
if (!equal(newUser, this.#currentUser)) {
this.#currentUser = newUser;
if (newUser.user.username === 'anonymous') {
Expand Down Expand Up @@ -223,7 +265,7 @@ export class Opencast {
// Uploads the given recordings with the given title and creator metadata. If
// the upload fails, `false` is returned and `getState` changes to an error
// state.
async upload({ recordings, title, creator, uploadSettings, onProgress }) {
async upload({ recordings, title,description, creator,seriesID , uploadSettings, onProgress }) {
// Refresh connection and check if we are ready to upload.
await this.refreshConnection();
if (!this.isReadyToUpload()) {
Expand All @@ -237,7 +279,7 @@ export class Opencast {
.then(response => response.text());

// Add metadata to media package
mediaPackage = await this.addDcCatalog({ mediaPackage, uploadSettings, title, creator });
mediaPackage = await this.addDcCatalog({ mediaPackage, uploadSettings, title, creator,description, seriesID });

// Set appropriate ACL unless the configuration says no.
if (uploadSettings?.acl !== false) {
Expand All @@ -259,10 +301,11 @@ export class Opencast {

// Adds the DC Catalog with the given metadata to the current ingest process
// via `ingest/addDCCatalog`. Do not call this method outside of `upload`!
async addDcCatalog({ mediaPackage, title, creator, uploadSettings }) {
const seriesId = uploadSettings?.seriesId;
async addDcCatalog({ mediaPackage, title, creator, description, seriesID, uploadSettings }) {
//const seriesId = uploadSettings?.seriesId;
let username = this.#currentUser.user.username;

const dcc = dcCatalog({ creator, title, seriesId });
const dcc = dcCatalog({ creator, title,description, seriesID, username });
const body = new FormData();
body.append('mediaPackage', mediaPackage);
body.append('dublinCore', dcc);
Expand Down Expand Up @@ -384,6 +427,22 @@ export class Opencast {
return this.#login === true;
}

getLoginUsername(){
return this.#login?.username;
}

getLoginPassword(){
return this.#login?.password;
}

getServerUrl(){
return this.#serverUrl;
}

getFinalSeriesTitles(){
return this.IDS;
}

// Returns whether or not the connection is ready to upload a video.
isReadyToUpload() {
return this.#state === STATE_LOGGED_IN;
Expand Down Expand Up @@ -490,10 +549,11 @@ const escapeString = s => {
return new XMLSerializer().serializeToString(new Text(s));
}

const dcCatalog = ({ creator, title, seriesId }) => {
const seriesLine = seriesId
? `<dcterms:isPartOf>${escapeString(seriesId)}</dcterms:isPartOf>`
: '';
const dcCatalog = ({ creator, title, description, seriesID, username }) => {
// const seriesLine = seriesId
// ? `<dcterms:isPartOf>${escapeString(seriesId)}</dcterms:isPartOf>`
// : '';


return `<?xml version="1.0" encoding="UTF-8"?>
<dublincore xmlns="http://www.opencastproject.org/xsd/1.0/dublincore/"
Expand All @@ -505,8 +565,12 @@ const dcCatalog = ({ creator, title, seriesId }) => {
<dcterms:creator>${escapeString(creator)}</dcterms:creator>
<dcterms:extent xsi:type="dcterms:ISO8601">PT5.568S</dcterms:extent>
<dcterms:title>${escapeString(title)}</dcterms:title>
<dcterms:description>${escapeString(description)}</dcterms:description>
<dcterms:spatial>Opencast Studio</dcterms:spatial>
${seriesLine}
<dcterms:isPartOf>${escapeString(seriesID)}</dcterms:isPartOf>
<dcterms:contributor>${escapeString(username)}</dcterms:contributor>
<dcterms:tou></dcterms:tou>
</dublincore>`;
}

Expand Down
1 change: 1 addition & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ const SCHEMA = {
loginProvided: 'boolean',
},
upload: {
enableSeries: 'string',
seriesId: 'string',
workflowId: 'string',
// This gets some special treatment in `fetchAcl`. After `fetchAcl` is
Expand Down
2 changes: 2 additions & 0 deletions src/studio-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const STATE_ERROR = 'error';
const defaultMetaData = {
title: '',
presenter: '',
description: '',
seriesID: '',
};
export let metaData = { ...defaultMetaData };

Expand Down
46 changes: 44 additions & 2 deletions src/ui/studio/save-creation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCheckCircle, faUpload, faRedoAlt } from '@fortawesome/free-solid-svg-icons';
import { Button, Box, Container, Spinner, Text } from '@theme-ui/components';
import React, { useEffect } from 'react';
import Select from 'react-select';
import { Link, useLocation } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -114,7 +115,7 @@ export default function SaveCreation(props) {
});

async function handleUpload() {
const { title, presenter } = metaData;
const {title, presenter, description, seriesID} = metaData;

if (title === '' || presenter === '') {
dispatch({ type: 'UPLOAD_ERROR', payload: t('save-creation-form-invalid') });
Expand All @@ -132,7 +133,9 @@ export default function SaveCreation(props) {
const success = await opencast.upload({
recordings: recordings.filter(Boolean),
title,
description,
creator: presenter,
seriesID,
uploadSettings: settings.upload,
onProgress,
});
Expand Down Expand Up @@ -269,7 +272,6 @@ const DownloadBox = ({ recordings, dispatch }) => (
// to settings.
const ConnectionUnconfiguredWarning = () => {
const location = useLocation();

return (
<Notification key="opencast-connection" isDanger>
<Trans i18nKey="warning-missing-connection-settings">
Expand All @@ -287,12 +289,27 @@ const ConnectionUnconfiguredWarning = () => {

const UploadForm = ({ opencast, uploadState, recordings, handleUpload }) => {
const { t } = useTranslation();
let series = opencast.getFinalSeriesTitles();
let titles = [];
for (let keys of series.keys()){
let tmp = {value:keys,label:series.get(keys)};
titles.push(tmp);
}


const enabledSeries = useSettings().upload?.enableSeries;
const displaySeries = enabledSeries == 'true' ? 'block' : 'none';


function handleInputChange(event) {
const target = event.target;
metaData[target.name] = target.value;
}

function handleSelectChange(event){
metaData['seriesID'] = event.value;
}

// If the user has not yet changed the value of the field and the last used
// presenter name is used in local storage, use that.
const presenterValue
Expand Down Expand Up @@ -331,6 +348,31 @@ const UploadForm = ({ opencast, uploadState, recordings, handleUpload }) => {
/>
</FormField>

<FormField label={t('save-creation-label-description')}>
<Input
name="description"
autoComplete="off"
defaultValue={metaData.description}
onChange={handleInputChange}
disabled={uploadState.state === STATE_UPLOADING}
/>
</FormField>
<div sx={{
display : displaySeries,
marginBottom : '30px'
}}>

<FormField label={t('save-creation-label-series')}>
<Select
name="series"
autoComplete="off"
options={titles}
onChange={handleSelectChange}
disabled={uploadState.state === STATE_UPLOADING}
/>
</FormField>
</div>

<Button onClick={handleUpload} disabled={recordings.length === 0}>
<FontAwesomeIcon icon={faUpload} />
{ buttonLabel }
Expand Down

0 comments on commit 5bdc550

Please sign in to comment.