1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-01-31 01:52:11 +01:00

Next step for filter api for ajax

This commit is contained in:
Brice Maron 2012-06-27 22:43:11 +00:00
parent b59cbe425d
commit ca0fa16812
5 changed files with 61 additions and 31 deletions

View File

@ -25,21 +25,28 @@
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('bookmarks');
require_once(OC_App::getAppPath('bookmarks').'/bookmarksHelper.php');
$req_type= isset($_GET['type']) ? $_GET['type'] : 'bookmark';
//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;
if($req_type == 'rel_tags') {
$tags = analyzeTagRequest(isset($_POST['tag']) ? $_POST['tag'] : '');
$qtags = OC_Bookmarks_Bookmarks::findTags($tags);
OCP\JSON::success(array('data' => $qtags));
$sort = isset($_POST['sort']) ? ($_POST['sort']) : 'bookmarks_sorting_recent';
if($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount';
} else {
$sqlSortColumn = 'id';
}
else { // type == bookmark
$filterTag = analyzeTagRequest(isset($_POST['tag']) ? $_POST['tag'] : '');
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
$offset = isset($_POST['page']) ? intval($_POST['page']) * 10 : 0;
OCP\JSON::success(array('data' => $bookmarks));
$sort = isset($_POST['sort']) ? ($_POST['sort']) : 'bookmarks_sorting_recent';
if($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount';
} else {
$sqlSortColumn = 'id';
}
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
OCP\JSON::success(array('data' => $bookmarks));
}

View File

@ -70,6 +70,16 @@ function getURLMetadata($url) {
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) {
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){

View File

@ -12,17 +12,43 @@ $(document).ready(function() {
$('.bookmarks_list').scroll(updateOnBottom).empty().width($('#rightcontent').width());
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() {
if(bookmarks_loading) {
//have patience :)
return;
}
$('#bookmarkFilterTag').val($('#tag_filter input').val());
//Update Rel Tags
$.ajax({
type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'updateList.php'),
data: 'tag=' + encodeURIComponent($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
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({
type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'updateList.php') + '&type=bookmark',
data: {tag: $('#bookmarkFilterTag').val(), page:bookmarks_page, sort:bookmarks_sorting },
success: function(bookmarks){
if (bookmarks.data.length) {
bookmarks_page += 1;

View File

@ -62,7 +62,7 @@ class OC_Bookmarks_Bookmarks{
* @return void
*/
public static function findBookmarks($offset, $sqlSortColumn, $filter, $filterTagOnly){
$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
//$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
$limit = 10;
$params=array(OCP\USER::getUser());
//@TODO replace GROUP_CONCAT for postgresql

View File

@ -13,24 +13,11 @@
</div>
<div id="leftcontent">
<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>
<label><?php echo $l->t('Related Tags'); ?></label>
<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>
<label><?php echo $l->t('Shared with'); ?></label>
<hr />