Browse Source

Fix issue #39 : actualisation de tous les flux grâce à Ajax

Marien Fressinaud 13 years ago
parent
commit
9b9543109e

+ 6 - 2
app/controllers/feedController.php

@@ -156,9 +156,13 @@ class feedController extends ActionController {
 				'content' => 'Aucun flux n\'a pu être mis à jour'
 			);
 		}
-		Session::_param ('notification', $notif);
 
-		Request::forward (array (), true);
+		if (Request::param ('ajax', 0) == 0) {
+			Session::_param ('notification', $notif);
+			Request::forward (array (), true);
+		} else {
+			$this->view->_useLayout (false);
+		}
 	}
 
 	public function massiveImportAction () {

+ 1 - 0
app/controllers/indexController.php

@@ -8,6 +8,7 @@ class indexController extends ActionController {
 	public function indexAction () {
 		View::appendScript (Url::display ('/scripts/shortcut.js'));
 		View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
+		View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'actualize')));
 
 		$entryDAO = new EntryDAO ();
 		$feedDAO = new FeedDAO ();

+ 6 - 3
app/controllers/javascriptController.php

@@ -5,8 +5,11 @@ class javascriptController extends ActionController {
 		$this->view->_useLayout (false);
 		header('Content-type: text/javascript');
 	}
-	
-	public function mainAction () {
-	
+
+	public function mainAction () {}
+
+	public function actualizeAction () {
+		$feedDAO = new FeedDAO ();
+		$this->view->feeds = $feedDAO->listFeeds ();
 	}
 }

+ 1 - 1
app/layout/nav_menu.phtml

@@ -1,7 +1,7 @@
 <div class="nav_menu">
 	<a class="btn toggle_aside" href="#aside_flux"><i class="icon i_category"></i></a>
 
-	<a class="btn" href="<?php echo _url ('feed', 'actualize'); ?>"><i class="icon i_refresh"></i></a>
+	<a id="actualize" class="btn" href="<?php echo _url ('feed', 'actualize'); ?>"><i class="icon i_refresh"></i></a>
 
 	<?php
 		$get = false;

+ 46 - 0
app/views/javascript/actualize.phtml

@@ -0,0 +1,46 @@
+var feeds = new Array ();
+<?php foreach ($this->feeds as $feed) { ?>
+feeds.push ("<?php echo Url::display (array ('c' => 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>");
+<?php } ?>
+
+function initProgressBar (init) {
+	if (init) {
+		$("body").after ("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
+			Actualisation :\
+			<progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feeds.length + "\"></progress>\
+			<span class=\"progress\">0 / " + feeds.length + "</span>\
+		</div>");
+	} else {
+		window.location.reload ();
+	}
+}
+function updateProgressBar (i) {
+	$("#actualizeProgressBar").val(i);
+	$("#actualizeProgress .progress").html (i + " / " + feeds.length);
+}
+
+function updateFeeds () {
+	initProgressBar (true);
+
+	var i = 0;
+	for (var f in feeds) {
+		$.ajax ({
+			type: 'POST',
+			url: feeds[f],
+		}).done (function (data) {
+			i++;
+			updateProgressBar (i);
+
+			if (i == feeds.length) {
+				initProgressBar (false);
+			}
+		});
+	}
+}
+
+$(document).ready (function () {
+	$("#actualize").click (function () {
+		updateFeeds ();
+		return false;
+	});
+});

+ 20 - 0
public/theme/freshrss.css

@@ -381,6 +381,26 @@
 	display: none;
 }
 
+.actualizeProgress {
+	position: fixed;
+	top: 0; left: 33%; right: 33%;
+	width: 33%;
+	padding: 5px;
+	background: #fff;
+	text-align: center;
+	border: 1px solid #ddd;
+	border-top: none;
+	border-radius: 0 0 5px 5px;
+}
+	.actualizeProgress progress {
+		vertical-align: middle;
+	}
+	.actualizeProgress .progress {
+		color: #999;
+		font-size: 90%;
+		vertical-align: middle;
+	}
+
 @media(max-width: 840px) {
 	.header,
 	.aside .btn-important,