Skip to content

Commit

Permalink
resolved issue #39 and #51
Browse files Browse the repository at this point in the history
  • Loading branch information
freyesdulib committed Jan 15, 2025
1 parent d280de5 commit 101cd05
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 101 deletions.
21 changes: 20 additions & 1 deletion exhibits/items_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,26 @@ exports.update_item_record = async function (is_member_of_exhibit, item_id, data
if (data.kaltura.length > 0) {
data.media = data.kaltura;
data.is_kaltura_item = 1;
} else if (data.repo_uuid.length > 0) {
}

if (data.kaltura.length === 0 && data.item_type !== 'audio') {
data.is_kaltura_item = 0;
}

if (data.kaltura.length === 0 && data.item_type !== 'video') {
data.is_kaltura_item = 0;
}

if (data.item_type === 'audio') {
data.is_kaltura_item = 1;
}

if (data.item_type === 'video') {
data.is_kaltura_item = 1;
}


if (data.repo_uuid.length > 0) {
data.media = data.repo_uuid;
data.is_repo_item = 1;
}
Expand Down
157 changes: 62 additions & 95 deletions public/app/helper.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ const helperModule = (function () {

document.querySelector('#item-type').value = item_type;
document.querySelector('#repo-item-metadata').innerHTML = `<p><strong>${response.data.data.title}</strong><br><em>${response.data.data.mime_type}</em></p>`;
document.querySelector('#is-repo-item').value = 1;
helperModule.clear_media_fields('repo_media');

} else {
document.querySelector('#repo-item-metadata').innerHTML = `<p style="color:red">Metadata record not found in repository.</p>`;
Expand All @@ -195,6 +197,36 @@ const helperModule = (function () {
}
};

/**
* Clears media fields
*/
obj.clear_media_fields = function (type) {

if (type === 'uploaded_media') {
document.querySelector('#repo-uuid').value = '';
document.querySelector('#audio-video').value = '';
document.querySelector('#is-kaltura-item').value = 0;
document.querySelector('#is-repo-item').value = 0;
}

if (type === 'repo_media') {
document.querySelector('#audio-video').value = '';
document.querySelector('#is-kaltura-item').value = 0;
}

if (type === 'kaltura_media') {
document.querySelector('#repo-uuid').value = '';
document.querySelector('#is-repo-item').value = 0;
}

document.querySelector('#item-type').value = '';
document.querySelector('#item-mime-type').value = '';
document.querySelector('#item-media').value = '';
document.querySelector('#item-media-thumbnail-image-display').innerHTML = '';
document.querySelector('#item-media-filename-display').innerHTML = '';
document.querySelector('#item-media-trash').style.display = 'none';
};

/**
* Shows form - changes .card class to visible
*/
Expand Down Expand Up @@ -481,109 +513,44 @@ const helperModule = (function () {
}
};

obj.init = function () {};

return obj;

}());

/**
* TODO: Remove - timeline items should not be reordered
* Reorders timeline item list via drag and drop
* @param event
* @param id
*/
/*
obj.reorder_timeline_items = function (event, id) {
try {
const exhibit_id = helperModule.get_parameter_by_name('exhibit_id');
const timeline_id = helperModule.get_parameter_by_name('timeline_id');
const EXHIBITS_ENDPOINTS = endpointsModule.get_exhibits_endpoints();
const tr_elem = Array.from(document.getElementsByTagName('tr'));
let row;
let children;
let updated_order = [];
let reorder_obj = {};
obj.check_bandwidth = function (cb) {

tr_elem.forEach(tr => {
const URL = 'https://upload.wikimedia.org/wikipedia/commons/9/90/ODJBcard.JPG';
const FILE_SIZE = 55 // KB
// const URL = 'http://upload.wikimedia.org/wikipedia/commons/5/51/Google.png';
// const FILE_SIZE = 238; // KB
let start = new Date().getTime();
let bandwidth;
let count = 10;
let i = 0;

tr.addEventListener('dragstart', (event) => {
row = event.target;
});
tr.addEventListener('dragover', (event) => {
try {
(async function request() {

let e = event;
e.preventDefault();
children = Array.from(e.target.parentNode.parentNode.children);
if (children.indexOf(e.target.parentNode) > children.indexOf(row)) {
// move down
e.target.parentNode.after(row);
} else {
// move up
e.target.parentNode.before(row);
}
} catch (error) {
console.log(error);
// document.querySelector('#message').innerHTML = `<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation"></i> ${error.message}</div>`;
}
const response = await httpModule.req({
method: 'GET',
url: URL
});

tr.addEventListener('drop', async (event) => {
if (response.status === 200) {

try {
let x = new Date().getTime() - start;
let bw = Number(((FILE_SIZE / (x / 1000))));
bandwidth = ((bandwidth || bw) + bw) / 2;
i++;

if (event.target.className === 'dropzone') {
row.parentNode.removeChild(row);
event.target.appendChild(row);
}
if (i < count) {
start = new Date().getTime();
await request();
} else {
cb(bandwidth.toFixed(0));
}
}

for (let i=0;i<children.length;i++ ) {
let child = children[i];
let id = child.getAttribute('id');
let id_arr = id.split('_');
reorder_obj.type = id_arr.pop();
reorder_obj.uuid = id_arr.pop();
reorder_obj.timeline_id = timeline_id;
reorder_obj.order = i + 1;
updated_order.push(reorder_obj);
reorder_obj = {};
}
})();
};

const token = authModule.get_user_token();
const response = await httpModule.req({
method: 'POST',
url: EXHIBITS_ENDPOINTS.exhibits.reorder_records.post.endpoint.replace(':exhibit_id', exhibit_id),
data: updated_order,
headers: {
'Content-Type': 'application/json',
'x-access-token': token
}
});
obj.init = function () {};

if (response !== undefined && response.status === 201) {
await itemsTimelineModule.display_timeline_items(event);
} else {
document.querySelector('#message').innerHTML = `<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation"></i> An error occurred while reordering items.</div>`;
}
return obj;

} catch (error) {
console.log(error);
}
});
});
} catch (error) {
console.log(error);
// document.querySelector('#message').innerHTML = `<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation"></i> ${error.message}</div>`;
}
};
*/
}());
4 changes: 3 additions & 1 deletion public/app/items.add.standard.item.form.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ const itemsAddStandardItemFormModule = (function () {
if (response !== undefined && response.status === 201) {

document.querySelector('#message').innerHTML = `<div class="alert alert-success" role="alert"><i class="fa fa-info"></i> Item record created</div>`;
const item_id = response.data.data;

setTimeout(() => {
window.location.reload();
window.location.replace(`${APP_PATH}/items/standard/edit?exhibit_id=${uuid}&item_id=${item_id}`);
// window.location.reload();
// location.replace(`${APP_PATH}/items?exhibit_id=${uuid}`);
}, 900);
}
Expand Down
13 changes: 11 additions & 2 deletions public/app/items.common.standard.item.form.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const itemsCommonStandardItemFormModule = (function () {
}

if (item.media_padding === true) {
item.media_padding = 1;
} else if (item.media_padding === false) {
item.media_padding = 0;
} else if (item.media_padding === false) {
item.media_padding = 1;
}

// item media
Expand All @@ -75,6 +75,8 @@ const itemsCommonStandardItemFormModule = (function () {
item.media_prev = document.querySelector('#item-media-prev').value;
item.kaltura = document.querySelector('#audio-video').value;
item.repo_uuid = document.querySelector('#repo-uuid').value;
item.is_repo_item = parseInt(document.querySelector('#is-repo-item').value);
item.is_kaltura_item = parseInt(document.querySelector('#is-kaltura-item').value);

if (item.media.length === 0 && item.kaltura.length === 0 && item.repo_uuid.length === 0) {
if (item.text.length === 0) {
Expand Down Expand Up @@ -168,6 +170,8 @@ const itemsCommonStandardItemFormModule = (function () {

if (response !== undefined && response.status === 204) {

document.querySelector('#item-type').value = '';
document.querySelector('#item-mime-type').value = '';
document.querySelector('#item-media').value = '';
document.querySelector('#item-media-thumbnail-image-display').innerHTML = '';
document.querySelector('#item-media-filename-display').innerHTML = '';
Expand Down Expand Up @@ -263,6 +267,11 @@ const itemsCommonStandardItemFormModule = (function () {
}, 1000);

document.querySelector('#repo-uuid-btn').addEventListener('click', await helperModule.get_repo_item_data);
document.querySelector('#audio-video').addEventListener('focusout', () => {
helperModule.clear_media_fields('kaltura_media');
document.querySelector('#is-kaltura-item').value = 1;
});

helperModule.show_form();

} catch (error) {
Expand Down
6 changes: 4 additions & 2 deletions public/app/items.edit.standard.item.form.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ const itemsEditStandardItemFormModule = (function () {
}

if (record.media_padding === 1) {
document.querySelector('#media-padding').checked = true;
} else {
document.querySelector('#media-padding').checked = false;
} else {
document.querySelector('#media-padding').checked = true;
}

if (record.media.length > 0) {
Expand Down Expand Up @@ -143,6 +143,7 @@ const itemsEditStandardItemFormModule = (function () {
document.getElementById('upload-media-tab').setAttribute('aria-selected', 'false');
document.getElementById('import-repo-media-tab').setAttribute('aria-selected', 'true');
document.querySelector('#repo-uuid').value = record.media;
document.querySelector('#is-repo-item').value = 1;
await helperModule.get_repo_item_data();
}

Expand All @@ -157,6 +158,7 @@ const itemsEditStandardItemFormModule = (function () {
document.getElementById('upload-media-tab').setAttribute('aria-selected', 'false');
document.getElementById('import-audio-video-tab').setAttribute('aria-selected', 'true');
document.querySelector('#audio-video').value = record.media;
document.querySelector('#is-kaltura-item').value = 1;

let item_types = document.getElementsByName('item_type');

Expand Down
1 change: 1 addition & 0 deletions public/app/uploads.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const uploadsModule = (function () {
item_type = 'Unable to Determine Type';
}

helperModule.clear_media_fields('uploaded_media');
document.querySelector('#item-type').value = item_type;
document.querySelector('#item-mime-type').value = mime_type;
document.querySelector('.upload-error').innerHTML = '';
Expand Down
43 changes: 43 additions & 0 deletions views/auth-landing.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,48 @@
</div>
<div class="clearfix"></div>
<script>window.sessionStorage.clear();</script>
<script src="/exhibits-dashboard/static/libs/axios-2.x/dist/axios.min.js"></script>
<script src="/exhibits-dashboard/static/app/http.module.js"></script>
<script src="/exhibits-dashboard/static/app/helper.module.js"></script>
<script>
helperModule.check_bandwidth(function (bandwidth) {
console.log('bandwidth ', bandwidth);
});
/*
//http://upload.wikimedia.org/wikipedia/commons/5/51/Google.png
//Size = 238 KB
function measureBW(cnt, cb) {
let start = new Date().getTime();
let bandwidth;
let i = 0;
(function rec() {
let xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', 'http://upload.wikimedia.org/wikipedia/commons/5/51/Google.png', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
let x = new Date().getTime() - start;
let bw = Number(((238 / (x / 1000))));
bandwidth = ((bandwidth || bw) + bw) / 2;
i++;
if (i < cnt) {
start = new Date().getTime();
rec();
}
else cb(bandwidth.toFixed(0));
}
};
xmlHttp.send(null);
})();
}
measureBW(10, function (e) {
console.log('bandwidth ', e);
});
*/
</script>
<%- include('partials/footer.ejs'); %>
</div>
1 change: 1 addition & 0 deletions views/dashboard-item-standard-add-form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<%- include('partials/embed-item.ejs'); %>
<hr>
<%- include('partials/media-padding.ejs'); %>
<input type="hidden" id="is-repo-item" name="is_repo_item" value="0">
</div>
</div>
<div id="item-layout-card" class="card">
Expand Down
1 change: 1 addition & 0 deletions views/partials/tab-import-audio-video.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
value="video" />
</label>
</p>
<input type="hidden" id="is-kaltura-item" name="is_kaltura_item" value="0">
</form>
</p>
</div>
1 change: 1 addition & 0 deletions views/partials/tab-import-repo-media.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<form class="row form-group">
<div class="col-7 col-md-7">
<input type="text" class="form-control" id="repo-uuid" name="repo_uuid" placeholder="Repository record UUID">
<input type="hidden" id="is-repo-item" name="is_repo_item" value="0">
</div>
<div class="col-auto">
<button type="button" id="repo-uuid-btn" class="btn btn-secondary mb-3">Get item metadata</button>
Expand Down

0 comments on commit 101cd05

Please sign in to comment.