Skip to content

Commit

Permalink
Merge pull request #109 from Fliplet/release/ID-4064
Browse files Browse the repository at this point in the history
  • Loading branch information
simonchapman1986 authored Mar 15, 2024
2 parents 2a3a732 + 5dcfd5f commit 3dec410
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 99 deletions.
8 changes: 4 additions & 4 deletions interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ <h4 class="panel-title trash-link">
<div class="spinner-overlay">Loading...</div>
</div>
<div class="search-holder">
<select class="form-control search-type">
<option value="all">This organization</option>
<select class="form-control search-type" id="search-type">
<option value="organization">This organization</option>
<option value="this-folder" selected>This folder</option>
</select>
<input type="text" class="form-control search-term" placeholder="Search...">
Expand Down Expand Up @@ -294,7 +294,7 @@ <h2>Did you know?</h2>
-->
<div class="file-cell search-result-cell file-path-cell">
<span>
<a href="javascript:;" class="path-link" data-folder data-id="\{{parentItemId}}" data-type="\{{parentItemType}}" title="\{{relativePath}}">\{{relativePath}}</a>
<a href="javascript:;" class="path-link" data-folder data-id="\{{id}}" data-parent-id="\{{parentItemId}}" data-type="\{{parentItemType}}" title="\{{relativePath}}">\{{relativePath}}</a>
</span>
</div>
<div class="file-cell search-result-cell file-size-cell">
Expand Down Expand Up @@ -353,7 +353,7 @@ <h2>Did you know?</h2>
-->
<div class="file-cell search-result-cell file-path-cell">
<span>
<a href="javascript:;" class="path-link" data-folder data-id="\{{parentItemId}}" data-type="\{{parentItemType}}" title="\{{relativePath}}">\{{relativePath}}</a>
<a href="javascript:;" class="path-link" data-folder data-id="\{{id}}" data-parent-id="\{{parentItemId}}" data-type="\{{parentItemType}}" title="\{{relativePath}}">\{{relativePath}}</a>
</span>
</div>
<div class="file-cell search-result-cell file-size-cell">
Expand Down
163 changes: 68 additions & 95 deletions js/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var appList;
// eslint-disable-next-line no-undef
var appIcons = new Map();
var currentOrganizationId;
let currentOrganizationNavItem;
var currentFolderId;
var currentAppId;
var currentFolders;
Expand Down Expand Up @@ -747,6 +748,7 @@ function addOrganizations(organizations) {

backItem.type = 'organizationId';
navStack.push(backItem);
currentOrganizationNavItem = backItem;

$('.header-breadcrumbs .current-folder-title').html('<span class="bread-link"><a href="#">' + orgName + '</a></span>');

Expand Down Expand Up @@ -974,38 +976,21 @@ function updatePaths() {
}

function resetUpTo(element) {
var backItem;

navStack = [];
const { id, type, appId, orgId } = element[0].dataset;

if (element.attr('data-type') === 'app') {
backItem = {
id: element.data('app-id'),
name: element.find('.list-text-holder span').first().text(),
tempElement: element
};
backItem.type = 'appId';
} else if (element.attr('data-type') === 'organization') {
backItem = {
id: element.data('org-id'),
name: element.find('.list-text-holder span').first().text(),
tempElement: element
};
backItem.type = 'organizationId';
} else {
backItem = {
id: element.data('id'),
name: element.find('.list-text-holder span').first().text(),
tempElement: element
};
backItem.type = 'folderId';
}
const backItem = {
id: type === 'app' && appId || type === 'organization' && orgId || id,
name: element.find('.list-text-holder span').first().text(),
tempElement: element,
type: type === 'app' && 'appId' || type === 'organization' && 'organizationId' || 'folderId'
};

backItem.back = function() {
getFolderContents(backItem.tempElement);
};

navStack.push(backItem);
navStack = [...(type === 'app' ? [currentOrganizationNavItem ] : []), backItem];

updatePaths();
}

Expand All @@ -1017,34 +1002,6 @@ function resetToTop() {

function getFoldersData(options, filterFiles, filterFolders) {
return Fliplet.Media.Folders.get(options).then(function(response) {
var navItem = navStack[navStack.length - 1];

switch (navItem.type) {
case 'organizationId':
// User is no longer browsing the organization folder
if (options.hasOwnProperty('folderId') || !options.hasOwnProperty('organizationId') || parseInt(options.organizationId, 10) !== navItem.id) {
return;
}

break;
case 'appId':
// User is no longer browsing the app folder
if (!options.hasOwnProperty('appId') || parseInt(options.appId, 10) !== navItem.id) {
return;
}

break;
case 'folderId':
// User is no longer browsing the folder
if (!options.hasOwnProperty('folderId') || parseInt(options.folderId, 10) !== navItem.id) {
return;
}

break;
default:
break;
}

if (!$folderContents.is(':empty')) {
// Content already rendered from a recent request. Do nothing.
return;
Expand Down Expand Up @@ -1285,7 +1242,7 @@ function search(type, term) {
if (currentFolderId) {
query.folderId = currentFolderId;
}
} else if (type === 'all') {
} else if (type !== 'this-folder') {
if (currentAppId) {
query.appId = currentAppId;
} else {
Expand Down Expand Up @@ -1319,7 +1276,7 @@ function renderSearchResult(result, searchType) {
return;
}

if (searchType === 'all') {
if (searchType !== 'this-folder') {
resetToTop();
}

Expand All @@ -1329,18 +1286,18 @@ function renderSearchResult(result, searchType) {
return item.deletedAt;
}

if (currentAppId || currentFolderId || searchType === 'all') {
if (currentAppId || currentFolderId || searchType !== 'this-folder') {
return !item.deletedAt;
}

return !item.deletedAt && !item.mediaFolderId && !item.appId;
})
.map(function(item) {
item.relativePath = calculatePath(item);
item.relativePath = calculatePath({ item, showApp: searchType === 'organization' });

if (item.parentId || item.mediaFolderId) {
if (item.parentFolder) {
item.parentItemType = 'folder';
item.parentItemId = item.parentId || item.mediaFolderId;
item.parentItemId = item.parentFolder.id;
} else if (item.appId) {
item.parentItemType = 'app';
item.parentItemId = item.appId;
Expand Down Expand Up @@ -1391,23 +1348,19 @@ function renderSearchResult(result, searchType) {
}

// Builds a relative path to folder or file
function calculatePath(item) {
var path = [];
var separator = '/';
var isLast = false;
function calculatePath({ item, showApp }) {
const rootApp = showApp && (item.parentFolder || item).app;
const path = [...(rootApp ? [rootApp.name] : [])];
const separator = '/';

var getNames = function(item) {
const getNames = function(item) {
if (!item) {
return;
}

if (item.parentFolder) {
getNames(item.parentFolder);
} else {
isLast = true;
}

if (isLast && item.id === +currentFolderId) {
} else if (item.id === +currentFolderId) {
return;
}

Expand Down Expand Up @@ -1450,17 +1403,24 @@ function updateBreadcrumbsBySearchItem(item) {
return;
}

var nav = [];
var isLast = false;
const { app } = item.parentFolder || item;

var getParents = function(parent) {
const nav = [
currentOrganizationNavItem,
...(app ? [{
id: app.id,
name: app.name,
type: 'appId',
back: function() {
getFolderContentsById(app.id, 'app');
}
}] : [])
];

const getParents = function(parent) {
if (parent.parentFolder) {
getParents(parent.parentFolder);
} else {
isLast = true;
}

if (isLast && parent.id === +currentFolderId) {
} else if (parent.id === +currentFolderId) {
return;
}

Expand All @@ -1476,7 +1436,7 @@ function updateBreadcrumbsBySearchItem(item) {

getParents(item);

navStack = navStack.concat(nav);
navStack = nav;
updatePaths();
}

Expand Down Expand Up @@ -1506,13 +1466,27 @@ function removePagination() {
}

function updateSearchTypeOptions(type) {
var optionName = 'This organization';

if (type === 'app') {
optionName = 'This app';
}
const select = document.getElementById('search-type');
const options = [
...(type === 'app'
? [
{
value: 'app',
label: 'This app'
}
]
: [
{
value: 'organization',
label: 'This organization'
}
]),
{ value: 'this-folder', label: 'This folder' }
];

$searchType.find('option:first').text(optionName);
select.innerHTML = options.map(option =>
`<option value="${option.value}" ${option.value === 'this-folder' ? 'selected' : ''}>${option.label}</option>`
).join('');
}

// Shows content of the last folder before run search
Expand Down Expand Up @@ -2215,6 +2189,7 @@ $('.file-manager-wrapper')

navStack.splice(position, 9999);
navStack[index].back();
updateSearchTypeOptions(navStack[index].type);
updatePaths();
})
.on('show.bs.collapse', '.panel-collapse', function() {
Expand Down Expand Up @@ -2246,6 +2221,7 @@ $('.file-manager-wrapper')
})
.catch(function(error) {
showSpinner(false);
console.log(error);
Fliplet.Modal.alert({
title: 'Error on search files',
message: Fliplet.parseError(error, 'Unknown error. Please try again later.')
Expand All @@ -2257,19 +2233,16 @@ $('.file-manager-wrapper')
$searchTermClearBtn.addClass('hide');
})
.on('click', '.path-link', function() {
var $el = $(this);
var type = $el.data('type');
var id = $el.data('id');
const { id, parentId, type } = this.dataset;

if (type === 'app' || type === 'organization') {
resetToTop();
} else {
var item = _.find(currentSearchResult, ['id', id]);
const numId = +id;
const item = currentSearchResult.find(item => item.id === numId);

updateBreadcrumbsBySearchItem(item);
if (item) {
updateBreadcrumbsBySearchItem(item.parentFolder || item);
}

getFolderContentsById(id, type, true);
getFolderContentsById(parentId, type, true);

removeSelection();
hideSideActions();
Expand All @@ -2282,7 +2255,7 @@ $('.file-manager-wrapper')

var type = $searchType.val();

if (type === 'all') {
if (type !== 'this-folder') {
currentFolderId = null;
}

Expand Down

0 comments on commit 3dec410

Please sign in to comment.