1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-02-20 17:54:25 +01:00

move related tags getter to tags controller

This commit is contained in:
Arthur Schiwon 2015-12-20 22:01:39 +01:00
parent 4ecd7885ea
commit 1f8ee4d068
5 changed files with 41 additions and 24 deletions

View File

@ -34,9 +34,12 @@ $application->registerRoutes($this, array('routes' => array(
array('name' => 'bookmark#click_bookmark', 'url' => '/bookmark/click', 'verb' => 'POST'),
array('name' => 'bookmark#export_bookmark', 'url' => '/bookmark/export', 'verb' => 'GET'),
array('name' => 'bookmark#import_bookmark', 'url' => '/bookmark/import', 'verb' => 'POST'),
array('name' => 'tags#full_tags', 'url' => '/tag', 'verb' => 'GET'),
array('name' => 'tags#rename_tag', 'url' => '/tag', 'verb' => 'POST'),
array('name' => 'tags#delete_tag', 'url' => '/tag', 'verb' => 'DELETE'),
['name' => 'tags#related_tags', 'url' => '/relatedTags', 'verb' => 'GET'],
//Public Rest Api
array('name' => 'public#return_as_json', 'url' => '/public/rest/v1/bookmark', 'verb' => 'GET'),
//Legacy Routes

View File

@ -32,7 +32,7 @@ class Bookmarks {
/**
* @brief Finds all tags for bookmarks
* @param $userId UserId
* @param string $userId UserId
* @param IDb $db Database Interface
* @param filterTags array of tag to look for if empty then every tag
* @param offset integer offset
@ -104,7 +104,7 @@ class Bookmarks {
/**
* @brief Finds all bookmarks, matching the filter
* @param $userid UserId
* @param string $userid UserId
* @param IDb $db Database Interface
* @param int $offset offset
* @param string $sqlSortColumn result with this column
@ -338,7 +338,7 @@ class Bookmarks {
/**
* @brief Delete a tag
* @param $userid UserId
* @param string $userid UserId
* @param IDb $db Database Interface
* @param string $old Tag Name to delete
* @return boolean Success of operation
@ -587,8 +587,8 @@ class Bookmarks {
/**
* @brief Seperate Url String at comma charachter
* @param $line String of Tags
* @return array Array of Tags
* @param string $line String of Tags
* @return string[] Array of Tags
* */
public static function analyzeTagRequest($line) {
$tags = explode(',', $line);

View File

@ -40,27 +40,26 @@ class BookmarkController extends ApiController {
}
/**
* returns a list of bookmarks
*
* @NoAdminRequired
* @param string $tag
* @param int $page
* @param string $sort
* @return JSONResponse
*/
public function getBookmarks($type = "bookmark", $tag = '', $page = 0, $sort = "bookmarks_sorting_recent") {
public function getBookmarks($tag = '', $page = 0, $sort = "bookmarks_sorting_recent") {
$filterTag = Bookmarks::analyzeTagRequest($tag);
if ($type == 'rel_tags') {
$tags = Bookmarks::analyzeTagRequest($tag);
$qtags = Bookmarks::findTags($this->userId, $this->db, $tags);
return new JSONResponse(array('data' => $qtags, 'status' => 'success'));
} else { // type == bookmark
$filterTag = Bookmarks::analyzeTagRequest($tag);
$offset = $page * 10;
$offset = $page * 10;
if ($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount';
} else {
$sqlSortColumn = 'lastmodified';
}
$bookmarks = Bookmarks::findBookmarks($this->userId, $this->db, $offset, $sqlSortColumn, $filterTag, true);
return new JSONResponse(array('data' => $bookmarks, 'status' => 'success'));
if ($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount';
} else {
$sqlSortColumn = 'lastmodified';
}
$bookmarks = Bookmarks::findBookmarks($this->userId, $this->db, $offset, $sqlSortColumn, $filterTag, true);
return new JSONResponse(array('data' => $bookmarks, 'status' => 'success'));
}
/**

View File

@ -63,4 +63,19 @@ class TagsController extends ApiController {
return new JSONResponse($tags);
}
/**
* @NoAdminRequired
*
* @param string $tag
* @return JSONResponse
*/
public function relatedTags($tag = '') {
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$tags = Bookmarks::analyzeTagRequest($tag);
$qtags = Bookmarks::findTags($this->userId, $this->db, $tags);
return new JSONResponse(array('data' => $qtags, 'status' => 'success'));
}
}

View File

@ -174,8 +174,8 @@ function getBookmarks() {
$.ajax({
type: 'GET',
url: 'bookmark',
data: {type: 'rel_tags', tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
url: 'relatedTags',
data: {tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
success: function (tags) {
$('.tag_list').empty();
for (var i in tags.data) {
@ -193,7 +193,7 @@ function getBookmarks() {
$.ajax({
type: 'GET',
url: 'bookmark',
data: {type: 'bookmark', tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
data: {tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
complete: function () {
decreaseAjaxCallCount();
},