mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-16 22:42:16 +00:00
add sort functionality to bookmark widget
This commit is contained in:
@@ -31,6 +31,7 @@ class Bookmark extends FHCAPI_Controller
|
||||
'delete' => self::PERM_LOGGED,
|
||||
'insert' => self::PERM_LOGGED,
|
||||
'update' => self::PERM_LOGGED,
|
||||
'changeOrder' => self::PERM_LOGGED,
|
||||
]);
|
||||
|
||||
$this->load->model('dashboard/Bookmark_model', 'BookmarkModel');
|
||||
@@ -51,7 +52,7 @@ class Bookmark extends FHCAPI_Controller
|
||||
*/
|
||||
public function getBookmarks()
|
||||
{
|
||||
$this->BookmarkModel->addOrder("bookmark_id");
|
||||
$this->BookmarkModel->addOrder("sort");
|
||||
$bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]);
|
||||
|
||||
$bookmarks = $this->getDataOrTerminateWithError($bookmarks);
|
||||
@@ -99,8 +100,9 @@ class Bookmark extends FHCAPI_Controller
|
||||
$url = $this->input->post('url',true);
|
||||
$title = $this->input->post('title',true);
|
||||
$tag = $this->input->post('tag', true);
|
||||
$sort = $this->input->post('sort', true);
|
||||
|
||||
$insert_into_result = $this->BookmarkModel->insert(['uid'=>$this->uid, 'url'=>$url, 'title'=>$title,'tag'=>$tag, 'insertvon'=>$this->uid, 'updateamum'=>NULL, 'updatevon'=>NULL]);
|
||||
$insert_into_result = $this->BookmarkModel->insert(['uid'=>$this->uid, 'url'=>$url, 'title'=>$title,'tag'=>$tag, 'insertvon'=>$this->uid, 'updateamum'=>NULL, 'updatevon'=>NULL, 'sort'=>$sort,]);
|
||||
|
||||
$insert_into_result = $this->getDataOrTerminateWithError($insert_into_result);
|
||||
|
||||
@@ -134,5 +136,32 @@ class Bookmark extends FHCAPI_Controller
|
||||
$this->terminateWithSuccess($update_result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* changes sort of two bookmarks in the bookmark table
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function changeOrder($bookmark_id1, $bookmark_id2)
|
||||
{
|
||||
|
||||
$result1 = $this->BookmarkModel->load($bookmark_id1);
|
||||
$data1 = $this->getDataOrTerminateWithError($result1);
|
||||
$sort1 = current($data1)->sort;
|
||||
|
||||
$result2 = $this->BookmarkModel->load(["bookmark_id"=>$bookmark_id2]);
|
||||
$data2 = $this->getDataOrTerminateWithError($result2);
|
||||
$sort2 = current($data2)->sort;
|
||||
|
||||
$update_result1 = $this->BookmarkModel->update($bookmark_id1,['sort'=>$sort2,]);
|
||||
$update_result[] = $this->getDataOrTerminateWithError($update_result1);
|
||||
|
||||
$update_result2 = $this->BookmarkModel->update($bookmark_id2,['sort'=>$sort1,]);
|
||||
$update_result[] = $this->getDataOrTerminateWithError($update_result2);
|
||||
|
||||
|
||||
|
||||
$this->terminateWithSuccess($update_result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,17 @@ export default {
|
||||
params: { url, title }
|
||||
};
|
||||
},
|
||||
insert({ url, title, tag }) {
|
||||
insert({ url, title, tag, sort }) {
|
||||
return {
|
||||
method: 'post',
|
||||
url: `/api/frontend/v1/Bookmark/insert`,
|
||||
params: { url, title, tag }
|
||||
params: { url, title, tag, sort }
|
||||
};
|
||||
},
|
||||
changeOrder(bookmark_id1, bookmark_id2) {
|
||||
return {
|
||||
method: 'post',
|
||||
url: `/api/frontend/v1/Bookmark/changeOrder/${bookmark_id1}/${bookmark_id2}`,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
bookmark_id: null,
|
||||
title_input: "",
|
||||
url_input: "",
|
||||
sort: null,
|
||||
validation: {
|
||||
invalidURL: false,
|
||||
invalidTitel: false,
|
||||
@@ -42,6 +43,25 @@ export default {
|
||||
|
||||
return false;
|
||||
},
|
||||
newSort(){
|
||||
if(this.shared.length == 0)
|
||||
return 1;
|
||||
else
|
||||
return Math.max(...this.shared.map(b => b.sort)) + 1;
|
||||
},
|
||||
maxSort(){
|
||||
if(this.shared.length == 0)
|
||||
return 0;
|
||||
else
|
||||
return Math.max(...this.shared.map(b => b.sort));
|
||||
},
|
||||
minSort(){
|
||||
if(this.shared.length == 0)
|
||||
return 0;
|
||||
else
|
||||
return Math.min(...this.shared.map(b => b.sort));
|
||||
},
|
||||
|
||||
},
|
||||
methods: {
|
||||
stopDrag(event){
|
||||
@@ -94,11 +114,15 @@ export default {
|
||||
// early return if validation failed
|
||||
if (!this.isValidationSuccessfull()) return;
|
||||
|
||||
// get highest Sort
|
||||
this.sort = this.newSort;
|
||||
|
||||
this.$api
|
||||
.call(ApiBookmark.insert({
|
||||
tag: this.config.tag,
|
||||
title: this.title_input,
|
||||
url: this.url_input,
|
||||
sort: this.sort
|
||||
}))
|
||||
.then((res) => res.data)
|
||||
.then((result) => {
|
||||
@@ -150,6 +174,42 @@ export default {
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
sortDown(bookmark_id){
|
||||
const current = this.shared.find(b => b.bookmark_id === bookmark_id);
|
||||
|
||||
const next = this.shared
|
||||
.filter(b => b.sort > current.sort)
|
||||
.sort((a, b) => a.sort - b.sort)[0];
|
||||
|
||||
if (!next) {
|
||||
console.log("lowest sort item, no change");
|
||||
return;
|
||||
}
|
||||
this.changeOrder(current.bookmark_id, next.bookmark_id);
|
||||
},
|
||||
sortUp(bookmark_id){
|
||||
const current = this.shared.find(b => b.bookmark_id === bookmark_id);
|
||||
|
||||
const next = this.shared
|
||||
.filter(b => b.sort < current.sort)
|
||||
.sort((a, b) => a.sort + b.sort)[0];
|
||||
|
||||
if (!next) {
|
||||
console.log("highest sort item, no change");
|
||||
return;
|
||||
}
|
||||
this.changeOrder(current.bookmark_id, next.bookmark_id);
|
||||
},
|
||||
changeOrder(bookmark_id_1, bookmark_id_2){
|
||||
this.$api
|
||||
.call(ApiBookmark.changeOrder(bookmark_id_1, bookmark_id_2))
|
||||
.then((res) => res.data)
|
||||
.then((result) => {
|
||||
// refetch the bookmarks to see the updates
|
||||
this.fetchBookmarks();
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchBookmarks();
|
||||
@@ -163,6 +223,7 @@ export default {
|
||||
<div class="d-flex flex-column justify-content-between">
|
||||
<button class="btn btn-outline-secondary btn-sm w-100 mt-2 card" @click="openCreateModal" type="button">{{$p.t('bookmark','newLink')}}</button>
|
||||
|
||||
|
||||
<template v-if="shared">
|
||||
|
||||
<template v-if="!emptyBookmarks">
|
||||
@@ -180,6 +241,29 @@ export default {
|
||||
<a type="button" id="deleteBookmark" href="#" aria-label="delete bookmark" v-tooltip="{showDelay:1000,value:'delete bookmark'}" @click.prevent="removeLink(link.bookmark_id)">
|
||||
<i class="fa fa-regular fa-trash-can" aria-hidden="true"></i>
|
||||
</a>
|
||||
<!--SORT BOOKMARKS-->
|
||||
<a
|
||||
v-if="shared.length > 1"
|
||||
type="button"
|
||||
id="downsortBookmark"
|
||||
href="#"
|
||||
aria-label="sortdown bookmark"
|
||||
v-tooltip="{showDelay:1000,value:'sort down bookmark'}"
|
||||
@click.prevent="sortDown(link.bookmark_id)"
|
||||
>
|
||||
<i :class="[ 'fa', 'fa-arrow-down', 'me-1', link.sort === maxSort ? 'text-light pointer-events-none' : '' ]"></i>
|
||||
</a>
|
||||
<a
|
||||
v-if="shared.length > 1"
|
||||
type="button"
|
||||
id="upsortBookmark"
|
||||
href="#"
|
||||
aria-label="sortup bookmark"
|
||||
v-tooltip="{showDelay:1000,value:'sort up bookmark'}"
|
||||
@click.prevent="sortUp(link.bookmark_id)"
|
||||
>
|
||||
<i :class="[ 'fa', 'fa-arrow-up', 'me-1', link.sort === minSort ? 'text-light pointer-events-none' : '' ]"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -84,6 +84,7 @@ require_once('dbupdate_3.4/60882_lehrfaecherverteilung_favorites.php');
|
||||
require_once('dbupdate_3.4/66982_berufsschule.php');
|
||||
require_once('dbupdate_3.4/40314_electronic_onboarding_anbindung_ida.php');
|
||||
require_once('dbupdate_3.4/47972_pruefungsverwaltung_ects_angabe.php');
|
||||
require_once('dbupdate_3.4/68957_dashboard_bookmark_neue_Spalte_sort.php');
|
||||
|
||||
// *** Pruefung und hinzufuegen der neuen Attribute und Tabellen
|
||||
echo '<H2>Pruefe Tabellen und Attribute!</H2>';
|
||||
@@ -452,7 +453,7 @@ $tabellen=array(
|
||||
"wawi.tbl_rechnungsbetrag" => array("rechnungsbetrag_id","rechnung_id","mwst","betrag","bezeichnung","ext_id"),
|
||||
"wawi.tbl_aufteilung" => array("aufteilung_id","bestellung_id","oe_kurzbz","anteil","insertamum","insertvon","updateamum","updatevon"),
|
||||
"wawi.tbl_aufteilung_default" => array("aufteilung_id","kostenstelle_id","oe_kurzbz","anteil","insertamum","insertvon","updateamum","updatevon"),
|
||||
"dashboard.tbl_bookmark" => array("bookmark_id","uid","url","title","tag","insertamum","insertvon","updateamum","updatevon"),
|
||||
"dashboard.tbl_bookmark" => array("bookmark_id","uid","url","title","tag","insertamum","insertvon","updateamum","updatevon","sort"),
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
if (! defined('DB_NAME')) exit('No direct script access allowed');
|
||||
|
||||
//Add column sort to dashboard.tbl_bookmark
|
||||
if(!@$db->db_query("SELECT sort FROM dashboard.tbl_bookmark LIMIT 1")) {
|
||||
$qry = "ALTER TABLE dashboard.tbl_bookmark ADD COLUMN sort integer DEFAULT NULL;
|
||||
COMMENT ON COLUMN dashboard.tbl_bookmark.sort IS 'Sort Index for Bookmark.';
|
||||
";
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>dashboard.tbl_bookmark ' . $db->db_last_error() . '</strong><br>';
|
||||
else
|
||||
echo '<br>Spalte sort zu Tabelle dashboard.tbl_bookmark hinzugefügt';
|
||||
|
||||
}
|
||||
|
||||
//add preliminary Sort for all bookmarks if NULL
|
||||
//TODO(manu) verfeinern, falls einzelne Werte NULL
|
||||
if(@$db->db_query("SELECT sort FROM dashboard.tbl_bookmark LIMIT 1")) {
|
||||
$qry = "WITH ranked AS (
|
||||
SELECT
|
||||
t1.bookmark_id,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM dashboard.tbl_bookmark t2
|
||||
WHERE t2.uid = t1.uid
|
||||
AND t2.bookmark_id <= t1.bookmark_id
|
||||
) AS rn
|
||||
FROM dashboard.tbl_bookmark t1
|
||||
)
|
||||
UPDATE dashboard.tbl_bookmark t
|
||||
SET sort = ranked.rn
|
||||
FROM ranked
|
||||
WHERE t.bookmark_id = ranked.bookmark_id
|
||||
AND t.sort IS NULL;";
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>dashboard.tbl_bookmark ' . $db->db_last_error() . '</strong><br>';
|
||||
else
|
||||
echo '<br>Tabelle dashboard.tbl_bookmark: Spalte sort mit vorläufiger Sortierung befüllt';
|
||||
}
|
||||
Reference in New Issue
Block a user