Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
brookgagnon committed May 18, 2024
1 parent 28a62ea commit 3199cbe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
Empty file added TEST
Empty file.
20 changes: 12 additions & 8 deletions models/media_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1166,20 +1166,24 @@ public function validate($args = [])
return array(false,$item['local_id'],'The category selected is no longer valid.');
}
//T The country selected is no longer valid.
$this->db->where('country_id', $item['country']);
$exists = $this->db->get_one('countries');
if (!empty($item['country']) && !$exists) {
return array(false,$item['local_id'],'The country selected is no longer valid.');
if(!empty($item['country'])) {
$this->db->where('country_id', $item['country']);
$exists = $this->db->get_one('countries');
if (!$exists) {
return array(false,$item['local_id'],'The country selected is no longer valid.');
}
}
//T The genre selected is no longer valid.
if (!empty($item['genre_id']) && !$this->db->id_exists('media_genres', $item['genre_id'])) {
return array(false,$item['local_id'],'The genre selected is no longer valid.');
}
//T The language selected is no longer valid.
$this->db->where('language_id', $item['language']);
$exists = $this->db->get_one('languages');
if (!empty($item['language']) && !$exists) {
return array(false,$item['local_id'],'The language selected is no longer valid.');
if(!empty($item['language'])) {
$this->db->where('language_id', $item['language']);
$exists = $this->db->get_one('languages');
if (!$exists) {
return array(false,$item['local_id'],'The language selected is no longer valid.');
}
}

//T The media status is not valid.
Expand Down
60 changes: 29 additions & 31 deletions ui/fields/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ class OBFieldMedia extends OBField {
#init;

connectedCallback() {
this.#mediaItems = [];
this.#mediaContent = {};
this.#mediaItems = [];
this.#mediaContent = {};

this.#recordData = [];
this.#recordUrl = "";
this.#recordData = [];
this.#recordUrl = "";
this.#mediaRecorder = null;

this.#blob = null;
this.#playback = null;
this.#duration = 0.0;
this.#waveformWidth = 350;
this.#blob = null;
this.#playback = null;
this.#duration = 0.0;
this.#waveformWidth = 350;
this.#waveformHeight = 100;
this.#trimStart = 0.0;
this.#trimEnd = 0.0;
this.#trimStart = 0.0;
this.#trimEnd = 0.0;

this.renderComponent();

Expand All @@ -59,18 +59,16 @@ class OBFieldMedia extends OBField {
<span class="media-item-remove" onclick=${this.mediaRemove.bind(this)}></span>
</div>
`)}
${
this.dataset.status === "cached"
? html`
${this.dataset.status === "cached"
? html`
<canvas height="100" width="350" id="waveform"></canvas>
<canvas style="display: none;" height="100" width="350" id="waveform-unedited"></canvas>
<audio style="display: none;" id="audio" controls src=${this.#recordUrl}></audio>
`
: html``
}
: html``
}
</div>
${
(this.#mediaItems.length === 0 && this.dataset.hasOwnProperty('single') && this.dataset.hasOwnProperty('record'))
${(this.#mediaItems.length === 0 && this.dataset.hasOwnProperty('single') && this.dataset.hasOwnProperty('record'))
? html`<span class="media-record" data-status="${this.dataset.hasOwnProperty('status') ? this.dataset.status : 'none'}">
<div class="trim-container">
<span class="trim">Trim Start</span>
Expand Down Expand Up @@ -274,7 +272,7 @@ class OBFieldMedia extends OBField {
onDragStart(event) {
let editable = this.root.querySelector("#media.media-editable");

if (! editable) {
if (!editable) {
return false;
}

Expand All @@ -284,22 +282,22 @@ class OBFieldMedia extends OBField {
onDragEnd(event) {
let editable = this.root.querySelector("#media.media-editable");

if (! editable) {
if (!editable) {
return false;
}

editable.classList.remove("dragging");
}

onMouseUp(event) {
if (! window.dragHelperData || ! window.dragHelperData[0].classList.contains("sidebar_search_media_result")) {
if (!window.dragHelperData || !window.dragHelperData[0].classList.contains("sidebar_search_media_result")) {
return false;
}

var selectedMedia = this.#mediaItems;

Object.keys(window.dragHelperData).forEach((key) => {
if (! window.dragHelperData[key].dataset) {
if (!window.dragHelperData[key].dataset) {
return false;
}

Expand Down Expand Up @@ -394,7 +392,7 @@ class OBFieldMedia extends OBField {
console.error(`The following getUserMedia error occurred: ${err}`);
}

this.#mediaRecorder = navigator.mediaDevices.getUserMedia({audio: true}).then(onSuccess, onError);
this.#mediaRecorder = navigator.mediaDevices.getUserMedia({ audio: true }).then(onSuccess, onError);
} else {
// TODO: Update element look.
console.error('getUserMedia not supported on your browser!');
Expand Down Expand Up @@ -451,8 +449,8 @@ class OBFieldMedia extends OBField {
return response.json();
}).then((data) => {
const fileKey = data.file_key;
const fileId = data.file_id;
const date = new Date();
const fileId = data.file_id;
const date = new Date();
const dateStr = date.getFullYear() + "-" + ('0' + (date.getMonth() + 1)).slice(-2) + "-" + ('0' + date.getDate()).slice(-2);

const media = OB.API.postPromise('media', 'save', {
Expand All @@ -464,7 +462,7 @@ class OBFieldMedia extends OBField {
title: "Media Field Recording " + dateStr,
local_id: 1,
status: "private",
language: 25571,
// language: 25571,
is_copyright_owner: 1,
is_approved: 1,
dynamic_select: 0,
Expand All @@ -474,7 +472,7 @@ class OBFieldMedia extends OBField {
}
});
media.then((data) => {
if (! data.status) {
if (!data.status) {
console.error(data.msg);
} else {
this.value = data.data;
Expand Down Expand Up @@ -531,7 +529,7 @@ class OBFieldMedia extends OBField {
let blockStart = blockSize * i;
let sum = 0;
for (let j = 0; j < blockSize; j++) {
sum = sum + Math.abs(rawData[blockStart + j]);
sum = sum + Math.abs(rawData[blockStart + j]);
}
if (max < (sum / blockSize)) {
max = sum / blockSize;
Expand All @@ -542,12 +540,12 @@ class OBFieldMedia extends OBField {
canvasCtx.clearRect(0, 0, width, height);
canvasCtx.fillStyle = "rgb(200, 200, 200)";
canvasCtx.fillRect(0, 0, width, height);

canvasCtx.lineWidth = 0.1;
canvasCtx.strokeStyle = "rgb(0, 0, 0)";

canvasCtx.beginPath();

const sliceWidth = (width * 1.0) / samples;
let x = 0;

Expand All @@ -565,7 +563,7 @@ class OBFieldMedia extends OBField {
}

canvasCtx.stroke();

// copy to waveform-unedited to use for overwriting any potential changes
// from trim
const canvasUnedited = this.root.querySelector('#waveform-unedited');
Expand Down

0 comments on commit 3199cbe

Please sign in to comment.