mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-12 09:54:27 +01:00
Next step for filter api for ajax
This commit is contained in:
parent
b59cbe425d
commit
ca0fa16812
@ -25,12 +25,19 @@
|
|||||||
// Check if we are a user
|
// Check if we are a user
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::checkAppEnabled('bookmarks');
|
OCP\JSON::checkAppEnabled('bookmarks');
|
||||||
|
require_once(OC_App::getAppPath('bookmarks').'/bookmarksHelper.php');
|
||||||
|
|
||||||
|
$req_type= isset($_GET['type']) ? $_GET['type'] : 'bookmark';
|
||||||
|
|
||||||
|
if($req_type == 'rel_tags') {
|
||||||
|
$tags = analyzeTagRequest(isset($_POST['tag']) ? $_POST['tag'] : '');
|
||||||
|
$qtags = OC_Bookmarks_Bookmarks::findTags($tags);
|
||||||
|
OCP\JSON::success(array('data' => $qtags));
|
||||||
|
|
||||||
|
}
|
||||||
|
else { // type == bookmark
|
||||||
|
$filterTag = analyzeTagRequest(isset($_POST['tag']) ? $_POST['tag'] : '');
|
||||||
|
|
||||||
//Filter for tag?
|
|
||||||
$filterTag = isset($_POST['tag']) ? htmlspecialchars_decode($_POST['tag']) : '';
|
|
||||||
$filterTag = explode(',',$filterTag);
|
|
||||||
if($filterTag[0] =='') unset($filterTag[0]);
|
|
||||||
$offset = isset($_POST['page']) ? intval($_POST['page']) * 10 : 0;
|
$offset = isset($_POST['page']) ? intval($_POST['page']) * 10 : 0;
|
||||||
|
|
||||||
$sort = isset($_POST['sort']) ? ($_POST['sort']) : 'bookmarks_sorting_recent';
|
$sort = isset($_POST['sort']) ? ($_POST['sort']) : 'bookmarks_sorting_recent';
|
||||||
@ -39,7 +46,7 @@ if($sort == 'bookmarks_sorting_clicks') {
|
|||||||
} else {
|
} else {
|
||||||
$sqlSortColumn = 'id';
|
$sqlSortColumn = 'id';
|
||||||
}
|
}
|
||||||
|
|
||||||
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
|
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
|
||||||
|
|
||||||
OCP\JSON::success(array('data' => $bookmarks));
|
OCP\JSON::success(array('data' => $bookmarks));
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -70,6 +70,16 @@ function getURLMetadata($url) {
|
|||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function analyzeTagRequest($line) {
|
||||||
|
$tags = explode(',',$line);
|
||||||
|
$filterTag = array();
|
||||||
|
foreach($tags as $tag){
|
||||||
|
if(trim($tag) != '')
|
||||||
|
$filterTag[] = trim($tag);
|
||||||
|
}
|
||||||
|
return $filterTag;
|
||||||
|
}
|
||||||
|
|
||||||
function addBookmark($url, $title, $tags='', $description='', $is_public=false) {
|
function addBookmark($url, $title, $tags='', $description='', $is_public=false) {
|
||||||
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
||||||
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
||||||
|
@ -12,17 +12,43 @@ $(document).ready(function() {
|
|||||||
$('.bookmarks_list').scroll(updateOnBottom).empty().width($('#rightcontent').width());
|
$('.bookmarks_list').scroll(updateOnBottom).empty().width($('#rightcontent').width());
|
||||||
getBookmarks();
|
getBookmarks();
|
||||||
});
|
});
|
||||||
|
function updateTagsList(tag) {
|
||||||
|
$('.tag_list').append('<li><a href="" class="tag">'+tag['tag']+'</a>'+
|
||||||
|
'<p class="tags_actions">'+
|
||||||
|
'<span class="bookmark_edit">'+
|
||||||
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">'+
|
||||||
|
'</span>'+
|
||||||
|
'<span class="bookmark_delete">'+
|
||||||
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">'+
|
||||||
|
'</span>'+
|
||||||
|
'</p>'+
|
||||||
|
'<em>'+tag['nbr']+'</em>'+
|
||||||
|
'</li>');
|
||||||
|
}
|
||||||
function getBookmarks() {
|
function getBookmarks() {
|
||||||
if(bookmarks_loading) {
|
if(bookmarks_loading) {
|
||||||
//have patience :)
|
//have patience :)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$('#bookmarkFilterTag').val($('#tag_filter input').val());
|
||||||
|
|
||||||
|
//Update Rel Tags
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: OC.filePath('bookmarks', 'ajax', 'updateList.php') + '&type=rel_tags',
|
||||||
|
data: {tag: $('#bookmarkFilterTag').val(), page:bookmarks_page, sort:bookmarks_sorting },
|
||||||
|
success: function(tags){
|
||||||
|
$('.tag_list').empty();
|
||||||
|
for(var i in tags.data) {
|
||||||
|
updateTagsList(tags.data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: OC.filePath('bookmarks', 'ajax', 'updateList.php'),
|
url: OC.filePath('bookmarks', 'ajax', 'updateList.php') + '&type=bookmark',
|
||||||
data: 'tag=' + encodeURIComponent($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
|
data: {tag: $('#bookmarkFilterTag').val(), page:bookmarks_page, sort:bookmarks_sorting },
|
||||||
success: function(bookmarks){
|
success: function(bookmarks){
|
||||||
if (bookmarks.data.length) {
|
if (bookmarks.data.length) {
|
||||||
bookmarks_page += 1;
|
bookmarks_page += 1;
|
||||||
|
@ -62,7 +62,7 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function findBookmarks($offset, $sqlSortColumn, $filter, $filterTagOnly){
|
public static function findBookmarks($offset, $sqlSortColumn, $filter, $filterTagOnly){
|
||||||
$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
|
//$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
|
||||||
$limit = 10;
|
$limit = 10;
|
||||||
$params=array(OCP\USER::getUser());
|
$params=array(OCP\USER::getUser());
|
||||||
//@TODO replace GROUP_CONCAT for postgresql
|
//@TODO replace GROUP_CONCAT for postgresql
|
||||||
|
@ -13,24 +13,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="leftcontent">
|
<div id="leftcontent">
|
||||||
<p id="tag_filter">
|
<p id="tag_filter">
|
||||||
<input type="text" placeholder="Filter By tag" value="<?php echo $_['req_tag']; ?>"/>
|
<input type="text" placeholder="Filter By tag" value="<?php echo $_['req_tag']; ?>"/> <a href="javascript:bookmarks_page = 0; $('.bookmarks_list').empty();getBookmarks()">go</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<label><?php echo $l->t('Related Tags'); ?></label>
|
<label><?php echo $l->t('Related Tags'); ?></label>
|
||||||
<ul class="tag_list">
|
<ul class="tag_list">
|
||||||
<?php foreach($_['tags'] as $tag):?>
|
|
||||||
<li><a href="<?php echo OCP\Util::linkToAbsolute( 'bookmarks', 'index.php').'&tag='.$_['req_tag'].','.$tag['tag'];?>" class="tag"><?php echo $tag['tag'];?></a>
|
|
||||||
<p class="tags_actions">
|
|
||||||
<span class="bookmark_edit">
|
|
||||||
<img class="svg" src="<?php echo OCP\image_path('core','actions/rename.svg') ?>" title="Edit">
|
|
||||||
</span>
|
|
||||||
<span class="bookmark_delete">
|
|
||||||
<img class="svg" src="<?php echo OCP\image_path('core','actions/delete.svg') ?>" title="Delete">
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
<em><?php echo $tag['nbr'];?></em>
|
|
||||||
</li>
|
|
||||||
<?php endforeach;?>
|
|
||||||
</ul>
|
</ul>
|
||||||
<label><?php echo $l->t('Shared with'); ?></label>
|
<label><?php echo $l->t('Shared with'); ?></label>
|
||||||
<hr />
|
<hr />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user