cleaned up create page process, update page edit template to handle empty files

This commit is contained in:
Ro 2022-03-15 16:56:37 -07:00
parent 2210e39aee
commit 1351b98ee4
6 changed files with 88 additions and 107 deletions

View file

@ -116,15 +116,15 @@ class DashControl
$files = []; $files = [];
foreach ($imageList as $item) { foreach ($imageList as $item) {
$image = trim($item); $image = trim($item);
if ($item != null || $item != "") { if (!empty($image)) {
array_push($images, $item); array_push($images, $image);
} }
} }
foreach ($fileList as $item) { foreach ($fileList as $item) {
$file = trim($item); $file = trim($item);
if ($item != null || $item != "") { if (!empty($file)) {
array_push($files, $item); array_push($files, $file);
} }
} }

View file

@ -53,96 +53,67 @@ class Book
$path = date("Y") . "/" . date("m"); $path = date("Y") . "/" . date("m");
} }
if (isset($files)) { $page_feature = '';
//var_dump($files); $page_files = '';
if ($task != "create") {
$imageList = ""; if (isset($files["page_files"])) {
$fileList = ""; $imageList = "";
$fileList = "";
//var_dump($files["page_files"] ); //var_dump($files["page_files"] );
foreach ($files["page_files"] as $file) { foreach ($files["page_files"] as $file) {
$type = $file->getClientMediaType(); $type = $file->getClientMediaType();
switch ($type) { switch ($type) {
case "image/jpeg": case "image/jpeg":
case "image/png": case "image/png":
case "image/gif": case "image/gif":
case "image/svg": case "image/svg":
$imagesPath = "/assets/images/blog/" . $path . "/"; $imagesPath = "/assets/images/blog/" . $path . "/";
$imageList = $imageList =
$imageList . $imagesPath . urlencode($file->getClientFileName()). ", "; $imageList . $imagesPath . urlencode($file->getClientFileName()). ", ";
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/images/blog/" . $path . "/", "../public/assets/images/blog/" . $path . "/",
$file $file
); );
break; break;
case "video/mp4": case "video/mp4":
$videosPath = "/assets/video/blog/" . $path . "/"; $videosPath = "/assets/video/blog/" . $path . "/";
$imageList = $imageList =
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", "; $imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/video/blog/" . $path . "/", "../public/assets/video/blog/" . $path . "/",
$file $file
); );
break; break;
case "audio/mpeg": case "audio/mpeg":
$soundPath = "/assets/sound/blog/" . $path . "/"; $soundPath = "/assets/sound/blog/" . $path . "/";
$fileList = $fileList . $soundPath . urlencode($file->getClientFileName()). ", "; $fileList = $fileList . $soundPath . urlencode($file->getClientFileName()). ", ";
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/sound/blog/" . $path . "/", "../public/assets/sound/blog/" . $path . "/",
$file $file
); );
break; break;
case 'application/pdf': case 'application/pdf':
case 'text/plain': case 'text/plain':
case 'text/rtf': case 'text/rtf':
$docPath = "/assets/docs/blog/" . $path . "/"; $docPath = "/assets/docs/blog/" . $path . "/";
$fileList = $fileList . $docPath . urlencode($file->getClientFileName()). ", "; $fileList = $fileList . $docPath . urlencode($file->getClientFileName()). ", ";
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/docs/blog/" . $path . "/", "../public/assets/docs/blog/" . $path . "/",
$file $file
); );
break; break;
}
} }
$feature = $imageList;
$files = $fileList;
//var_dump($feature);
//return ["message" => "JUST DEBUGGING"];
} else {
//if creating a new page, from file payload and set $feature and $files
/*
$feature =
"/assets/images/blog/" .
$path .
"/" .
$image["feature_image"]->getClientFileName();
*/
} }
$page_feature = $imageList;
$page_files = $fileList;
} else { } else {
//if no files, do no file stuff //if no files, just reset string from page object
/* $page_feature = $page["feature"];
if (isset($body["feature_image"])) { $page_files = $page["files"];
$url = explode("/", $body["feature_image"]);
$feature =
"/" .
$url[3] .
"/" .
$url[4] .
"/" .
$url[5] .
"/" .
$url[6] .
"/" .
$url[7] .
"/" .
$url[8];
} else {
//$task == "create" ? ($feature = "") : ($feature = $body["feature"]);
}
*/
} }
if ($task == "delete") { if ($task == "delete") {
@ -167,8 +138,8 @@ class Book
$body["id"] = $id; $body["id"] = $id;
$body["uuid"] = $uuid; $body["uuid"] = $uuid;
$body["feature"] = $feature; $body["feature"] = $page_feature;
$body["files"] = $files; $body["files"] = $page_files;
$body["path"] = $path; $body["path"] = $path;
$body["author"] = $member["handle"]; $body["author"] = $member["handle"];
$body["created"] = $created->format("Y-m-d\TH:i:sP"); $body["created"] = $created->format("Y-m-d\TH:i:sP");

View file

@ -1,7 +1,7 @@
<div id="dash-login"> <div id="dash-login">
<div id="dash-form" class="dash-form"> <div id="dash-form" class="dash-form">
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/> <img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
<form id="login" class='login' name="login"> <form id="login" class='login' name="login" method="POST">
<input type="text" name="handle" class="form-control" placeholder="Handle" required "> <input type="text" name="handle" class="form-control" placeholder="Handle" required ">
<input type="password" name="password" class="form-control" placeholder="Password" required"> <input type="password" name="password" class="form-control" placeholder="Password" required">
<button id="login-btn" class='login-btn' type='submit'> <button id="login-btn" class='login-btn' type='submit'>

View file

@ -44,8 +44,17 @@
<div id="post-edit-index-wrapper"> <div id="post-edit-index-wrapper">
<div id="post-feature"> <div id="post-feature">
{% if page['feature'] == null %} {% if page['feature'] == null %}
<div id="featured-image-drop"> <div id="page-file-manager">
DRAG AND DROP IMAGE OR <label for="featured-image-upload">CLICK TO CHOSE</label> <div id="page-file-wrapper">
<div id="page-file-drop">
<label for="page-files-upload">DRAG AND DROP FILES OR CLICK TO SELECT</label>
</div>
IMAGES AND VIDEO
<div id="page-images-list"></div>
FILES
<div id="page-files-list"></div>
</div>
</div> </div>
{% else %} {% else %}
<div id="page-file-manager"> <div id="page-file-manager">
@ -64,11 +73,14 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% else %} {% else %}
{% if item.type == "mp4"%} {% if media[0] != '' %}
<div id="0" class="video-item" data-source="{{ media[0].file }}"></div> {% if media[0].type == "mp4"%}
<div id="0" class="video-item" data-source="{{ media[0].file }}"></div>
{% else %} {% else %}
<div id="0" class="img-item" style="background: url({{ media[0].file }}) no-repeat center center / cover"></div> <div id="0" class="img-item" style="background: url({{ media[0].file }}) no-repeat center center / cover"></div>
{% endif %} {% endif %}
{% else %}
{% endif %}
{% endif %} {% endif %}
</div> </div>
@ -83,11 +95,16 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% else %} {% else %}
{% if item.type == "mp3"%} {% if files[0] != '' %}
{% if files[0].type == "mp3"%}
<div id="0" class="audio-item" data-source="{{ files[0].file }}"></div> <div id="0" class="audio-item" data-source="{{ files[0].file }}"></div>
{% else %} {% else %}
<div id="0" class="file-item" data-source="{{ files[0].file }}"></div> <div id="0" class="file-item" data-source="{{ files[0].file }}"></div>
{% endif %} {% endif %}
{% else %}
{% endif %}
{% endif %} {% endif %}
</div> </div>

View file

@ -5483,7 +5483,6 @@ class FileManager {
], path[6], { ], path[6], {
type: blob.type type: blob.type
}); });
console.log('FRESH FILE', fresh);
this.files.push(fresh); this.files.push(fresh);
if (this.files.length <= count - 1) this.reindexFiles(sortOrder, ++step); if (this.files.length <= count - 1) this.reindexFiles(sortOrder, ++step);
else notify.alert('FILES READY TO UPLOAD', true); else notify.alert('FILES READY TO UPLOAD', true);
@ -5511,7 +5510,7 @@ class FileManager {
image.title = escape(theFile.name); image.title = escape(theFile.name);
var span = document.createElement('div'); var span = document.createElement('div');
span.style.background = 'url(' + f.target.result + ') no-repeat center center / cover'; span.style.background = 'url(' + f.target.result + ') no-repeat center center / cover';
span.className = 'img-item'; //span.setAttribute('data-source', theFile.name); span.className = 'img-item';
image.setAttribute('id', i); image.setAttribute('id', i);
self.storage.push([ self.storage.push([
{ {
@ -5568,13 +5567,11 @@ class FileManager {
break; break;
case 'change': case 'change':
case 'drop': case 'drop':
e.type == 'drop' ? rawList = e.dataTransfer.files : rawList = e.target.files; //this.sortFiles(freshList); e.type == 'drop' ? rawList = e.dataTransfer.files : rawList = e.target.files;
for(var i = 0, f; f = rawList[i]; i++){ for(var i = 0, f; f = rawList[i]; i++)// check witch files are cool to upload
// check witch files are cool to upload if (this.accetableFiles.includes(f.type)) sortedList.push(f);
console.log('TYPE', f.type); else notOnTheList.push(f);
if (this.accetableFiles.includes(f.type)) sortedList.push(f); //send for sorting
else notOnTheList.push(f);
} //send for sorting
self.sortFiles(sortedList); self.sortFiles(sortedList);
break; break;
} }

View file

@ -86,7 +86,6 @@ export default class FileManager {
var path = sortOrder[step].earl.split('/'); var path = sortOrder[step].earl.split('/');
utils.imgLoad(sortOrder[step].earl).then(blob => { utils.imgLoad(sortOrder[step].earl).then(blob => {
var fresh = new File([blob], path[6], { type: blob.type }); var fresh = new File([blob], path[6], { type: blob.type });
console.log('FRESH FILE', fresh);
this.files.push(fresh); this.files.push(fresh);
if (this.files.length <= count - 1) { if (this.files.length <= count - 1) {
this.reindexFiles(sortOrder, ++step); this.reindexFiles(sortOrder, ++step);
@ -124,7 +123,6 @@ export default class FileManager {
f.target.result + f.target.result +
') no-repeat center center / cover'; ') no-repeat center center / cover';
span.className = 'img-item'; span.className = 'img-item';
//span.setAttribute('data-source', theFile.name);
image.setAttribute('id', i); image.setAttribute('id', i);
self.storage.push([ self.storage.push([
{ {
@ -190,10 +188,8 @@ export default class FileManager {
e.type == 'drop' e.type == 'drop'
? (rawList = e.dataTransfer.files) ? (rawList = e.dataTransfer.files)
: (rawList = e.target.files); : (rawList = e.target.files);
//this.sortFiles(freshList);
for (var i = 0, f; (f = rawList[i]); i++) { for (var i = 0, f; (f = rawList[i]); i++) {
// check witch files are cool to upload // check witch files are cool to upload
console.log('TYPE', f.type);
if (this.accetableFiles.includes(f.type)) { if (this.accetableFiles.includes(f.type)) {
sortedList.push(f); sortedList.push(f);
} else { } else {