Skip to content

Commit

Permalink
grid view, use SearchableText, levelInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Mar 15, 2024
1 parent a4b62f3 commit 260d642
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
44 changes: 38 additions & 6 deletions src/pat/contentbrowser/src/ContentBrowser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
allowPathSelection: false,
hiddenInputContainer: ".upload-wrapper",
success: (fileUpload, obj) => {
contentItems.get($currentPath, null, null, true);
contentItems.get($currentPath, null, true);
},
});
}
Expand Down Expand Up @@ -127,7 +127,7 @@
$: {
if ($config.vocabularyUrl) {
contentItems.get($currentPath, null, currentLevelData);
contentItems.get($currentPath);
}
}
Expand Down Expand Up @@ -199,9 +199,19 @@
</button>
{/if}
<div class="levelActions">
<!-- <button class="btn btn-link btn-sm grid-view">
{#if !level.gridView}
<button class="btn btn-link btn-sm grid-view"
on:click={() => (level.gridView = true)}
>
<svg use:resolveIcon={{ iconName: "grid" }} />
</button> -->
</button>
{:else}
<button class="btn btn-link btn-sm grid-view"
on:click={() => (level.gridView = false)}
>
<svg use:resolveIcon={{ iconName: "list" }} />
</button>
{/if}
</div>
</div>
{#each level.results as item, n}
Expand All @@ -218,6 +228,20 @@
on:keydown={() => changePath(item)}
on:click={() => changePath(item)}
>
{#if level.gridView}
<div class="grid-preview">
{#if item.getIcon}
<img src={`${item.getURL}/@@images/image/thumb`} alt={item.Title}>
{:else}
<svg
use:resolveIcon={{
iconName: `contenttype/${item.portal_type.toLowerCase().replace(/\.| /g, "-")}`,
}}
/>
{/if}
{item.Title}
</div>
{:else}
<div title={item.portal_type}>
<svg
use:resolveIcon={{
Expand All @@ -226,6 +250,7 @@
/>
{item.Title}
</div>
{/if}
{#if item.is_folderish}
<svg
use:resolveIcon={{
Expand Down Expand Up @@ -285,8 +310,7 @@
background-color: rgba(0, 0, 0, 0.25);
}
.content-browser {
height: 99vh;
/* padding: 1rem; */
height: 100vh;
min-width: 550px;
background-color: var(--bs-light-bg-subtle);
border-left: var(--bs-border-style) var(--bs-border-width) #fff;
Expand Down Expand Up @@ -387,6 +411,13 @@
max-width: 100%;
}
.contentItem .grid-preview > img {
width:95px;
height:95px;
object-fit:cover;
float: left;
margin-right: 1rem;
}
.preview {
min-width: 320px;
max-width: 500px;
Expand All @@ -397,6 +428,7 @@
}
.preview .info {
padding: 0.5rem;
width: 100%;
}
.preview h4 {
font-size: 1.2 rem;
Expand Down
46 changes: 34 additions & 12 deletions src/pat/contentbrowser/src/ContentStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writable, get } from "svelte/store";
import { cache } from "./stores";
import { pathCache } from "./stores";


export default function (config) {
Expand All @@ -11,6 +11,7 @@ export default function (config) {
uids = null,
params = null,
searchTerm = null,
levelInfoPath = null,
selectableTypes = [],

Check failure on line 15 in src/pat/contentbrowser/src/ContentStore.js

View workflow job for this annotation

GitHub Actions / test

'selectableTypes' is assigned a value but never used
}) => {
let vocabQuery = {
Expand All @@ -29,6 +30,17 @@ export default function (config) {
sort_order: "ascending",
};
}
if (levelInfoPath) {
vocabQuery = {
criteria: [
{
i: "path",
o: "plone.app.querystring.operation.string.path",
v: `${levelInfoPath}::0`,
},
],
};
}
if (uids) {
vocabQuery = {
criteria: [
Expand All @@ -42,7 +54,7 @@ export default function (config) {
}
if(searchTerm) {
vocabQuery.criteria.push({
i: "Title",
i: "SearchableText",
o: "plone.app.querystring.operation.string.contains",
v: `${searchTerm}`,

Expand Down Expand Up @@ -92,7 +104,7 @@ export default function (config) {
}
};

store.get = async (path, searchTerm, levelData, skipCache) => {
store.get = async (path, searchTerm, skipCache) => {
let parts = path.split("/") || [];
const depth = parts.length >= config.maxDepth ? config.maxDepth : parts.length;
let paths = [];
Expand All @@ -111,14 +123,15 @@ export default function (config) {

let levels = [];
let pathCounter = 0;

for (var p of paths) {
pathCounter++;
const isFirstPath = pathCounter == 1;
if(typeof skipCache === "undefined") {
skipCache = isFirstPath || searchTerm;
skipCache = isFirstPath && searchTerm;
}
let level = {};
const c = get(cache);
const c = get(pathCache);
if (Object.keys(c).indexOf(p) === -1 || skipCache) {
let query = {
method: "GET"
Expand All @@ -130,22 +143,31 @@ export default function (config) {
queryPath = queryPath + p;
query["path"] = queryPath;
if(isFirstPath && searchTerm){
query["searchTerm"] = searchTerm + "*";
query["searchTerm"] = "*" + searchTerm + "*";
}
if(config.selectableTypes.length) {
query["selectableTypes"] = config.selectableTypes;
}
level = await store.request(query);
cache.update((n) => {
n[p] = level;
return n;
const levelInfo = await store.request({
"levelInfoPath": queryPath,
});
if (levelInfo.total) {
level.UID = levelInfo.results[0].UID;
level.Title = levelInfo.results[0].Title;
}
level.gridView = false;
level.path = p;
// do not update cache when searching
if(!searchTerm) {
pathCache.update((n) => {
n[p] = level;
return n;
});
}
} else {
level = c[p];
}
level.path = p;
level.UID = levelData?.UID;
level.Title = levelData?.Title;
levels = [level, ...levels];
}
store.set(levels);
Expand Down
6 changes: 1 addition & 5 deletions src/pat/contentbrowser/src/SelectedItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@
selectedItemsNode.value = node_val;
}
function openContentBrowser() {
$showContentBrowser = true;
}
$: {
$selectedItems;
console.log(
Expand Down Expand Up @@ -169,7 +165,7 @@
style="border-radius:0 var(--bs-border-radius) var(--bs-border-radius) 0"
disabled={$config.maximumSelectionSize > 0 &&
($selectedItems.length || 0) >= $config.maximumSelectionSize}
on:click|preventDefault={openContentBrowser}
on:click|preventDefault={() => ($showContentBrowser = true)}
>{#if config.maximumSelectionSize == 1}choose{:else}add{/if}</button
>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/pat/contentbrowser/src/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { setContext } from 'svelte';
import { writable } from 'svelte/store';

export const currentPath = writable('/');
export const cache = writable({});
export const gridView = writable(false);
export const pathCache = writable({});

// reactive context stores
export function setSelectedItems() {
Expand Down

0 comments on commit 260d642

Please sign in to comment.