Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jul 12, 2018
commit bd1929a3b18ea97bb07fbf400b2f4c3670fa44a5
2 changes: 1 addition & 1 deletion apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
var params;
if (e && e.itemId) {
params = {
view: e.view !== '' ? e.view : e.itemId,
view: typeof e.view === 'string' && e.view !== '' ? e.view : e.itemId,
dir: e.dir ? e.dir : '/'
};
this._changeUrl(params.view, params.dir);
Expand Down
72 changes: 1 addition & 71 deletions apps/files/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
_setupEvents: function () {
this.$el.on('click', 'li a', _.bind(this._onClickItem, this))
this.$el.on('click', 'li button', _.bind(this._onClickMenuButton, this));
this._setOnDrag();

},

/**
Expand Down Expand Up @@ -135,7 +133,7 @@
}
this._activeItem = itemId;
currentItem.children('a').addClass('active');
this.$currentContent = $('#app-content-' + (itemView !== '' ? itemView : itemId));
this.$currentContent = $('#app-content-' + (typeof itemView === 'string' && itemView !== '' ? itemView : itemId));
this.$currentContent.removeClass('hidden');
if (!options || !options.silent) {
this.$currentContent.trigger(jQuery.Event('show'));
Expand Down Expand Up @@ -169,74 +167,6 @@
ev.preventDefault();
},

/**
* Event handler for when dragging an item
*/
_setOnDrag: function () {
var scope = this;
var element = $("#sublist-favorites");
$(function () {
if (document.getElementById(scope.$quickAccessListKey.toString()).hasAttribute("draggable")) {
element.sortable({
axis: "y",
containment: "parent",
scroll: false,
zIndex: 0,
opacity: 0.5,
tolerance: "pointer",
//revert: 0.05,
//delay: 150,
start: function (event, ui) {
//Fix for offset
ui.helper[0].style.left = '0px';

//Change Icon while dragging
var list = document.getElementById(scope.$quickAccessListKey).getElementsByTagName('li');
for (var j = 0; j < list.length; j++) {
if (!(typeof list[j].getElementsByTagName('a')[0] === 'undefined')) {
list[j].getElementsByTagName('a')[0].classList.remove("nav-icon-files");
list[j].getElementsByTagName('a')[0].classList.add('icon-menu');
}
}
},
stop: function (event, ui) {
//Clean up offset
ui.item.removeAttr("style");

//Change Icon back after dragging
var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li');
for (var j = 0; j < list.length; j++) {
if (!(typeof list[j].getElementsByTagName('a')[0] === 'undefined')) {
list[j].getElementsByTagName('a')[0].classList.add("nav-icon-files");
list[j].getElementsByTagName('a')[0].classList.remove('icon-menu');
}
}
},
update: function (event, ui) {
var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li');
var string = [];
for (var j = 0; j < list.length; j++) {
var Object = {
id: j,
name: scope.getCompareValue(list, j, 'alphabet')
};
string.push(Object);
}
var resultorder = JSON.stringify(string);
$.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/CustomSortingOrder"), {
order: resultorder
}, function (data, status) {
});
}
});
} else {
if (scope.$sortingStrategy === 'customorder') {
scope.$sortingStrategy = 'datemodified';
}
}
});
},

/**
* Event handler for clicking a button
*/
Expand Down
6 changes: 6 additions & 0 deletions apps/files/js/tagsplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
var quickAccessList = 'sublist-favorites';
var collapsibleButtonId = 'button-collapse-favorites';
var listULElements = document.getElementById(quickAccessList);
if (!listULElements) {
return;
}
var listLIElements = listULElements.getElementsByTagName('li');

var apppath=appfolder;
Expand Down Expand Up @@ -101,6 +104,9 @@
var quickAccessList = 'sublist-favorites';
var collapsibleButtonId = 'button-collapse-favorites';
var listULElements = document.getElementById(quickAccessList);
if (!listULElements) {
return;
}
var listLIElements = listULElements.getElementsByTagName('li');

var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length);
Expand Down
5 changes: 0 additions & 5 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
// show_Quick_Access stored as string
$defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1';

// see Javascript navigation.js for possible sorting strategies
$quickAccessDraggable = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'alphabet') === 'customorder';


\OCA\Files\App::getNavigationManager()->add(
[
'id' => 'favorites',
Expand All @@ -219,7 +215,6 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
'order' => 5,
'name' => $this->l10n->t('Favorites'),
'sublist' => $favoritesSublistArray,
'draggableSublist' => $quickAccessDraggable,
'defaultExpandedState' => $defaultExpandedState,
'enableMenuButton' => 0,
]
Expand Down
2 changes: 1 addition & 1 deletion apps/files/templates/appnavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class="nav-icon-<?php p($item['icon'] !== '' ? $item['icon'] : $item['id']) ?> s
?>
<button id="button-collapse-<?php p($item['id']); ?>"
class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
<ul id="sublist-<?php p($item['id']); ?>" <?php if ($item['draggableSublist'] === 'true') { ?> draggable="true" style="resize: none;"<?php } ?>>
<ul id="sublist-<?php p($item['id']); ?>">
<?php
foreach ($item['sublist'] as $item) {
$pinned = NavigationListElements($item, $l, $pinned);
Expand Down
24 changes: 12 additions & 12 deletions apps/files/tests/js/appSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,38 +239,38 @@ describe('OCA.Files.App tests', function() {
expect(App.navigation.getActiveItem()).toEqual('other');
expect($('#app-content-files').hasClass('hidden')).toEqual(true);
expect($('#app-content-other').hasClass('hidden')).toEqual(false);
expect($('li[data-id=files]').hasClass('active')).toEqual(false);
expect($('li[data-id=other]').hasClass('active')).toEqual(true);
expect($('li[data-id=files] > a').hasClass('active')).toEqual(false);
expect($('li[data-id=other] > a').hasClass('active')).toEqual(true);

App._onPopState({view: 'files', dir: '/somedir'});

expect(App.navigation.getActiveItem()).toEqual('files');
expect($('#app-content-files').hasClass('hidden')).toEqual(false);
expect($('#app-content-other').hasClass('hidden')).toEqual(true);
expect($('li[data-id=files]').hasClass('active')).toEqual(true);
expect($('li[data-id=other]').hasClass('active')).toEqual(false);
expect($('li[data-id=files] > a').hasClass('active')).toEqual(true);
expect($('li[data-id=other] > a').hasClass('active')).toEqual(false);
});
it('clicking on navigation switches the panel visibility', function() {
$('li[data-id=other]>a').click();
$('li[data-id=other] > a').click();
expect(App.navigation.getActiveItem()).toEqual('other');
expect($('#app-content-files').hasClass('hidden')).toEqual(true);
expect($('#app-content-other').hasClass('hidden')).toEqual(false);
expect($('li[data-id=files]').hasClass('active')).toEqual(false);
expect($('li[data-id=other]').hasClass('active')).toEqual(true);
expect($('li[data-id=files] > a').hasClass('active')).toEqual(false);
expect($('li[data-id=other] > a').hasClass('active')).toEqual(true);

$('li[data-id=files]>a').click();
$('li[data-id=files] > a').click();
expect(App.navigation.getActiveItem()).toEqual('files');
expect($('#app-content-files').hasClass('hidden')).toEqual(false);
expect($('#app-content-other').hasClass('hidden')).toEqual(true);
expect($('li[data-id=files]').hasClass('active')).toEqual(true);
expect($('li[data-id=other]').hasClass('active')).toEqual(false);
expect($('li[data-id=files] > a').hasClass('active')).toEqual(true);
expect($('li[data-id=other] > a').hasClass('active')).toEqual(false);
});
it('clicking on navigation sends "show" and "urlChanged" event', function() {
var handler = sinon.stub();
var showHandler = sinon.stub();
$('#app-content-other').on('urlChanged', handler);
$('#app-content-other').on('show', showHandler);
$('li[data-id=other]>a').click();
$('li[data-id=other] > a').click();
expect(handler.calledOnce).toEqual(true);
expect(handler.getCall(0).args[0].view).toEqual('other');
expect(handler.getCall(0).args[0].dir).toEqual('/');
Expand All @@ -281,7 +281,7 @@ describe('OCA.Files.App tests', function() {
var showHandler = sinon.stub();
$('#app-content-files').on('urlChanged', handler);
$('#app-content-files').on('show', showHandler);
$('li[data-id=files]>a').click();
$('li[data-id=files] > a').click();
expect(handler.calledOnce).toEqual(true);
expect(handler.getCall(0).args[0].view).toEqual('files');
expect(handler.getCall(0).args[0].dir).toEqual('/');
Expand Down