Skip to content

Commit

Permalink
ref elan-ev#569 CHANGE applied request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Pfahl committed Apr 24, 2020
1 parent cf6b50f commit fcfabdd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 94 deletions.
2 changes: 2 additions & 0 deletions src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"save-creation-form-invalid": "Bitte geben Sie einen Titel und die Vortragenden an",
"save-creation-label-presenter": "Vortragende*r",
"save-creation-label-title": "Titel",
"save-creation-label-description": "Beschreibung",
"save-creation-title": "Fast geschafft!",
"save-creation-label-series": "Serien",
"save-creation-title-done": "Geschafft!",
"save-creation-subsection-title-download": "Aufnahme runterladen",
"save-creation-download-button": "Runterladen",
Expand Down
70 changes: 18 additions & 52 deletions src/opencast.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class Opencast {

updateGlobalOc = null;

IDS = new Map();
// Contains all series on which the user has write access to
// [ key : ID , value: Title } => Example : [ 12345 , 'Episode Title no. 1' ]
ids = new Map();

username = '';

Expand Down Expand Up @@ -90,45 +92,19 @@ export class Opencast {

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

await self.handleSeriesIDSelection();
await catchRequestError(async () => 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 => {
async handleSeriesidselection() {
const data = await this.jsonRequest('/admin-ng/series/series.json');
for (let root in data) {
for (let enumerator in data[root]) {
this.IDS.set(data[root][enumerator]['id'], data[root][enumerator]['title']);
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
Expand Down Expand Up @@ -265,7 +241,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,description, creator,seriesID , 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 @@ -279,7 +255,7 @@ export class Opencast {
.then(response => response.text());

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

// Set appropriate ACL unless the configuration says no.
if (uploadSettings?.acl !== false) {
Expand All @@ -302,10 +278,12 @@ 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, description, seriesID, uploadSettings }) {
//const seriesId = uploadSettings?.seriesId;
if(uploadSettings?.hasOwnProperty('seriesId')){
seriesID = uploadSettings?.seriesId;
}
let username = this.#currentUser.user.username;

const dcc = dcCatalog({ creator, title,description, seriesID, username });
const dcc = dcCatalog({ creator, title, description, seriesID, username });
const body = new FormData();
body.append('mediaPackage', mediaPackage);
body.append('dublinCore', dcc);
Expand Down Expand Up @@ -427,20 +405,8 @@ 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;
return this.ids;
}

// Returns whether or not the connection is ready to upload a video.
Expand Down Expand Up @@ -550,9 +516,9 @@ const escapeString = s => {
}

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


return `<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -567,7 +533,7 @@ const dcCatalog = ({ creator, title, description, seriesID, username }) => {
<dcterms:title>${escapeString(title)}</dcterms:title>
<dcterms:description>${escapeString(description)}</dcterms:description>
<dcterms:spatial>Opencast Studio</dcterms:spatial>
<dcterms:isPartOf>${escapeString(seriesID)}</dcterms:isPartOf>
${seriesLine}
<dcterms:contributor>${escapeString(username)}</dcterms:contributor>
<dcterms:tou></dcterms:tou>
Expand Down
4 changes: 2 additions & 2 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ const SCHEMA = {
loginProvided: 'boolean',
},
upload: {
enableSeries: 'string',
enableDescription: 'string',
enableSeriesSelection: 'boolean',
userProvidedDescription: 'boolean',
seriesId: 'string',
workflowId: 'string',
// This gets some special treatment in `fetchAcl`. After `fetchAcl` is
Expand Down
67 changes: 27 additions & 40 deletions src/ui/studio/save-creation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ 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 @@ -289,20 +290,15 @@ 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 settings = useSettings();
const series = opencast.getFinalSeriesTitles();
const titles = [];
for (const keys of series.keys()){
titles.push({ value:keys,
label:series.get(keys)});
}


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


function handleInputChange(event) {
const target = event.target;
metaData[target.name] = target.value;
Expand Down Expand Up @@ -349,35 +345,26 @@ const UploadForm = ({ opencast, uploadState, recordings, handleUpload }) => {
onChange={handleInputChange}
/>
</FormField>
<div sx={{
display : displayDescription,
marginBottom : '30px'
}}>
<FormField label={t('save-creation-label-description')}>
<Input
name="description"
autoComplete="off"
defaultValue={metaData.description}
onChange={handleInputChange}
disabled={uploadState.state === STATE_UPLOADING}
/>
</FormField>
</div>
<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>
{settings.upload?.userProvidedDescription &&
<FormField label={t('save-creation-label-description')}>
<Input
name="description"
autoComplete="off"
defaultValue={metaData.description}
onChange={handleInputChange}
disabled={uploadState.state === STATE_UPLOADING}
/>
</FormField> }
{settings.upload?.enableSeriesSelection && !settings.upload?.hasOwnProperty('seriesId') &&
<FormField label={t('save-creation-label-series')}>
<Select
name="series"
autoComplete="off"
options={titles}
onChange={handleSelectChange}
disabled={uploadState.state === STATE_UPLOADING}
/>
</FormField>}

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

0 comments on commit fcfabdd

Please sign in to comment.