Add feed to feed list instantly on feed adding

Reload is no longer necessary. There are still some issues - especially
the order of the feeds: atm the feed is just inserted at the beginning
This commit is contained in:
Gregor Tätzner 2012-08-02 18:52:33 +02:00
Родитель 1cc2f0c7f0
Коммит bdc5159324
10 изменённых файлов: 38 добавлений и 46 удалений

Просмотреть файл

@ -32,6 +32,10 @@ if(!$feedid) {
exit();
}
//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations
OCP\JSON::success(array('data' => array('message' => $l->t('Feed added!'))));
$tmpl = new OCP\Template("news", "part.listfeed");
$tmpl->assign('child', $feed);
$listitem = $tmpl->fetchPage();
//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations
OCP\JSON::success(array('data' => array('message' => $l->t('Feed added!'), 'listitem' => $listitem)));

Просмотреть файл

@ -2,6 +2,6 @@
include("populateroot.php");
$output = new OCP\Template("news", "part.addfeed");
$output = new OCP\Template("news", "part.feeddialog");
$output->assign('allfeeds', $allfeeds);
$output->printpage();

Просмотреть файл

@ -2,6 +2,6 @@
include("populateroot.php");
$output = new OCP\Template("news", "part.addfolder");
$output = new OCP\Template("news", "part.folderdialog");
$output->assign('allfeeds', $allfeeds);
$output->printpage();

Просмотреть файл

@ -1,5 +1,4 @@
.collapsable { background: url('%webroot%/core/img/places/folder.svg') no-repeat left center; padding: 0 0 0 20px; }
.news_input { float:left; font-size:12px; padding:4px 2px; border:solid 1px #aacfe4; width:200px; }
.svg { border: inherit; background: inherit; }
@ -8,8 +7,8 @@
#feeds { background: #fff; width: 19.7em; left: 12.5em; top: 3.7em; bottom:3em; position: fixed; overflow: auto; padding: 0; margin: 0 0 0 0.3em;}
/* #feeds a { height: 23px; display: block; margin: 0 0 0 0; padding: 0 0 0 25px; } */
#bottomcontrols { padding: 0; bottom:0px; overflow:visible; height:2.8em; width: 20em; margin:0; background:#eee; border-top:1px solid #ccc; position:fixed; -moz-box-shadow: 0 -3px 3px -3px #000; -webkit-box-shadow: 0 -3px 3px -3px #000; box-shadow: 0 -3px 3px -3px #000;}
#feeds_delete { position: absolute; right: 0px; background: url('%webroot%/core/img/actions/delete.svg') no-repeat center; display: inline; }
#feeds_edit { position: absolute; right: 1.6em; background: url('%webroot%/core/img/actions/rename.svg') no-repeat center; display: inline; }
#feeds_delete { position: absolute; right: 0px; background: url('%webroot%/core/img/actions/delete.svg') no-repeat center; display: none; }
#feeds_edit { position: absolute; right: 1.6em; background: url('%webroot%/core/img/actions/rename.svg') no-repeat center; display: none; }
#dropdownBtn { width: 9em; padding-left: 0; padding-right:20px; background: url('%webroot%/core/img/actions/triangle-s.svg') no-repeat right center; }
@ -58,14 +57,14 @@ li.menuItem { margin-left:0.7em; margin-right:0.7em; float: none !important; tex
li.feeds_list { margin-left: 16px !important; text-align: right; border-radius: 5px; padding-left: 5px !important; background-color: rgb(255,255,255) !important; }
li.feeds_list a { padding: 0 0 0 20px !important; overflow: hidden; text-overflow: ellipsis; text-align: left; width: 65%; }
li.folder_list { background-color: rgb(255,255,255) !important; }
div.collapsable_container { padding-left: 5px !important; border-radius: 5px; }
div.collapsable { background: url('%webroot%/core/img/places/folder.svg') no-repeat 5px; padding: 0 0 0 25px; border-radius: 5px; }
ul.folders { margin-left: 16px !important; }
li.folder_list:hover { color: rgb(0, 0, 0) !important; background-color: rgb(255,255,255) !important; }
li.feeds_list:hover { background-color: rgb(221, 221, 221) !important; }
div.collapsable_container:hover { background-color: rgb(221, 221, 221); }
div.collapsable:hover { background-color: rgb(221, 221, 221); }
div.add_parentfolder { position: relative; }
div.dialog { overflow: visible; }

Просмотреть файл

@ -108,6 +108,8 @@ News={
$.post(OC.filePath('news', 'ajax', 'createfeed.php'), { feedurl: feedurl, folderid: folderid },
function(jsondata){
if(jsondata.status == 'success'){
$('div[data-id="' + folderid + '"] > ul').before(jsondata.data.listitem);
setupFeedList();
OC.dialogs.alert(jsondata.data.message, t('news', 'Success!'));
} else {
OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
@ -203,9 +205,8 @@ News={
}
function setupFeedList() {
$('.collapsable_container').click(function(){
$(this).parent().children().toggle();
$(this).toggle();
$('.collapsable').click(function(){
$(this).parent().children('ul').toggle();
});
var list = $('.collapsable,.feeds_list').hover(
@ -228,6 +229,7 @@ $(document).ready(function(){
$('#addfeed').click(function() {
News.UI.overview('#addfeed_dialog','feeddialog.php');
});
$('#addfolder').click(function() {
News.UI.overview('#addfolder_dialog','folderdialog.php');
});
@ -245,13 +247,13 @@ $(document).ready(function(){
$('#addfeedfolder').click(function(event) {
event.stopPropagation();
});
$('#settingsbtn').on('click keydown', function() {
try {
OC.appSettings({appid:'news', loadJS:true});
} catch(e) {
alert(e);
}
}
});
setupFeedList();
@ -259,7 +261,6 @@ $(document).ready(function(){
News.Feed.updateAll();
var updateInterval = 200000; //how often the feeds should update (in msec)
setInterval('News.Feed.updateAll()', updateInterval);
});
$(document).click(function(event) {

Просмотреть файл

@ -34,6 +34,15 @@ class OC_News_FolderMapper {
*/
public function populate($name, $id){
$root = new OC_News_Folder($name, $id);
// first add child feeds
$feedmapper = new OC_News_FeedMapper();
$feeds = $feedmapper->findByFolderId($id);
foreach ($feeds as $feed){
$root->addChild($feed);
}
// and second child folders
$stmt = OCP\DB::prepare('SELECT *
FROM ' . self::tableName .
' WHERE user_id = ? AND parent_id = ?');
@ -44,12 +53,6 @@ class OC_News_FolderMapper {
$root->addChild($child);
}
$feedmapper = new OC_News_FeedMapper();
$feeds = $feedmapper->findByFolderId($id);
foreach ($feeds as $feed){
$root->addChild($feed);
}
return $root;
}

Просмотреть файл

@ -19,22 +19,22 @@ class OC_News_Utils {
/**
* @brief Fetch a feed from remote
* @param url remote url of the feed
* @returns
* @returns an instance of OC_News_Feed
*/
public static function fetch($url){
$spfeed = new SimplePie_Core();
$spfeed->set_feed_url( $url );
$spfeed->enable_cache( false );
if (!$spfeed->init()) {
return null;
}
//I understand this try-catch sucks, but SimplePie gives weird errors sometimes
try {
$spfeed->handle_content_type();
$title = $spfeed->get_title();
$items = array();
if ($spitems = $spfeed->get_items()) {
foreach($spitems as $spitem) { //FIXME: maybe we can avoid this loop
@ -45,7 +45,7 @@ class OC_News_Utils {
$items[] = new OC_News_Item($itemUrl, $itemTitle, $itemGUID, $itemBody);
}
}
$feed = new OC_News_Feed($url, $title, $items);
$favicon = $spfeed->get_image_url();

Просмотреть файл

Просмотреть файл

@ -1,38 +1,23 @@
<?php
function print_folder(OC_News_Folder $folder, $depth){
$l = new OC_l10n('news');
include("part.listfolder.php");
echo '<ul class="folders"' . (($depth == 0) ? 'style="margin-left: 0px !important;"' : '') .'> <li class="folder_list" >' .
'<div class="collapsable_container">' .
'<div class="collapsable" >' . strtoupper($folder->getName()) .
( ($depth != 0) ? '<button class="svg action" id="feeds_delete" onClick="(News.Folder.delete(' . $folder->getId(). '))" title="' . $l->t('Delete folder') . '"></button>' .
'<button class="svg action" id="feeds_edit" title="' . $l->t('Rename folder') . '"></button>': '' ) .
'</div>' .
'</div>';
echo '<ul>';
$children = $folder->getChildren();
foreach($children as $child) {
if ($child instanceOf OC_News_Folder){
print_folder($child, $depth+1);
}
elseif ($child instanceOf OC_News_Feed) { //onhover $(element).attr('id', 'newID');
$favicon = $child->getFavicon();
if ($favicon == null) {
$favicon = OCP\Util::imagePath('news', 'rss.svg');
}
echo '<li class="feeds_list" data-id="' . $child->getId() . '"><a href="' . OCP\Util::linkTo('news', 'index.php'). '?feedid=' . $child->getId() . '" style="background: url(' . $favicon . ') left center no-repeat; background-size:16px 16px;">' . $child->getTitle() .'</a>';
countUnreadItems($child->getId());
echo '<button class="svg action" id="feeds_delete" onClick="(News.Feed.delete(' . $child->getId(). '))" title="' . $l->t('Delete feed') . '"></button>';
echo '<button class="svg action" id="feeds_edit" title="' . $l->t('Edit feed') . '"></button>';
echo '</li>';
$tmpl = new OCP\Template("news", "part.listfeed");
$tmpl->assign('child', $child);
$tmpl->printpage();
}
else {
//TODO:handle error in this case
}
}
echo '</ul></li></ul>';
echo '</ul></div></li></ul>';
}
include("part.itemcounter.php");
print_folder($_['allfeeds'], 0);
?>

Просмотреть файл