summaryrefslogtreecommitdiffstats
path: root/apps/calendar
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-07-03 22:33:24 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-07-03 22:33:24 +0200
commitc036700c5451351a580f9c244b1bf6ad5eb9a3a7 (patch)
treea20335cc7179515dfd4db17d1d3144a58fa96294 /apps/calendar
parent641e77327e0ab21b2c6dbaa981c0e3d97364b358 (diff)
downloadnextcloud-server-c036700c5451351a580f9c244b1bf6ad5eb9a3a7.tar.gz
nextcloud-server-c036700c5451351a580f9c244b1bf6ad5eb9a3a7.zip
some more work on calendar import
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/ajax/import/import.php14
-rw-r--r--apps/calendar/css/import.css5
-rw-r--r--apps/calendar/js/loader.js42
-rw-r--r--apps/calendar/lib/import.php41
-rw-r--r--apps/calendar/templates/part.import.php8
5 files changed, 80 insertions, 30 deletions
diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php
index 63f761dd27f..b5a97e5d123 100644
--- a/apps/calendar/ajax/import/import.php
+++ b/apps/calendar/ajax/import/import.php
@@ -8,6 +8,10 @@
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
session_write_close();
+if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) {
+ echo OCP\JSON::success(array('percent'=>OC_Cache::get($_POST['progresskey'])));
+ exit;
+}
$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
if(!$file){
OCP\JSON::error(array('error'=>'404'));
@@ -16,6 +20,7 @@ $import = new OC_Calendar_Import($file);
$import->setUserID(OCP\User::getUser());
$import->setTimeZone(OC_Calendar_App::$tz);
$import->enableProgressCache();
+$import->setProgresskey($_POST['progresskey']);
if(!$import->isValid()){
OCP\JSON::error(array('error'=>'notvalid'));
exit;
@@ -44,7 +49,12 @@ if($_POST['method'] == 'new'){
$id = $_POST['id'];
}
$import->setCalendarID($id);
-$import->import();
+try{
+ $import->import();
+}catch (Exception $e) {
+ OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('Import failed'), 'debug'=>$e->getMessage()));
+ //write some log
+}
$count = $import->getCount();
if($count == 0){
if($newcal){
@@ -137,4 +147,4 @@ foreach($uids as $uid) {
writeProgress('100');
sleep(3);
OC_Cache::remove($progresskey);
-OCP\JSON::success(); \ No newline at end of file
+OCP\JSON::success();*/ \ No newline at end of file
diff --git a/apps/calendar/css/import.css b/apps/calendar/css/import.css
index d60d54253ad..46bab2b7cf3 100644
--- a/apps/calendar/css/import.css
+++ b/apps/calendar/css/import.css
@@ -7,6 +7,5 @@
#calendar_import_newcalform, #calendar_import_mergewarning, #calendar_import_process, #calendar_import_done{display:none;}
#calendar_import_process_message, #calendar_import_status, #calendar_import_form_message, #calendar_import_mergewarning{text-align:center;}
#calendar_import_form_message{font-weight: bold;}
-#calendar_import_newcalendar{width:480px;}
-.calendar_import_warning{background-color: rgba(216,22,22,0.7);}
-.calendar_import_revertwarning{background-color: #ffffff;} \ No newline at end of file
+#calendar_import_newcalendar{width:96%;}
+.calendar_import_warning{border-color: #fc3333;} \ No newline at end of file
diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js
index 9f18ea87263..77199a53273 100644
--- a/apps/calendar/js/loader.js
+++ b/apps/calendar/js/loader.js
@@ -70,32 +70,46 @@ Calendar_Import={
});
},
update: function(){
- /*$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progress:1,progresskey: progresskey}, function(percent){
- $('#progressbar').progressbar('option', 'value', parseInt(percent));
- if(percent < 100){
- window.setTimeout('Calendar_Import.getimportstatus(\'' + progresskey + '\')', 500);
+ if(Calendar_Import.Store.percentage == 100){
+ return false;
+ }
+ $.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progresskey: Calendar_Import.Store.progresskey, getprogress: true}, function(data){
+ if(data.status == 'success'){
+ if(data.percent == null){
+ return false;
+ }
+ Calendar_Import.Store.percentage = parseInt(data.percent);
+ $('#calendar_import_progressbar').progressbar('option', 'value', parseInt(data.percent));
+ if(data.percent < 100 ){
+ window.setTimeout('Calendar_Import.Dialog.update()', 250);
+ }else{
+ $('#calendar_import_done').css('display', 'block');
+ }
}else{
- $('#import_done').css('display', 'block');
+ $('#calendar_import_progressbar').progressbar('option', 'value', 100);
+ $('#calendar_import_progressbar > div').css('background-color', '#FF2626');
+ $('#calendar_import_status').html(data.message);
}
- });*/
- return 0;
+ });
+ return 0;
},
warning: function(selector){
- $(selector).css('background-color', '#FF2626');
+ $(selector).addClass('calendar_import_warning');
$(selector).focus(function(){
- $(selector).css('background-color', '#F8F8F8');
+ $(selector).removeClass('calendar_import_warning');
});
}
},
Core:{
process: function(){
var validation = Calendar_Import.Core.prepare();
- $('#calendar_import_form').css('display', 'none');
- $('#calendar_import_process').css('display', 'block');
if(validation){
+ $('#calendar_import_form').css('display', 'none');
+ $('#calendar_import_process').css('display', 'block');
$('#calendar_import_newcalendar').attr('readonly', 'readonly');
$('#calendar_import_calendar').attr('disabled', 'disabled');
Calendar_Import.Core.send();
+ window.setTimeout('Calendar_Import.Dialog.update()', 250);
}
},
send: function(){
@@ -103,17 +117,15 @@ Calendar_Import={
{progresskey: Calendar_Import.Store.progresskey, method: String (Calendar_Import.Store.method), calname: String (Calendar_Import.Store.calname), path: String (Calendar_Import.Store.path), file: String (Calendar_Import.Store.file), id: String (Calendar_Import.Store.id)}, function(data){
if(data.status == 'success'){
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
+ Calendar_Import.Store.percentage = 100;
$('#calendar_import_done').css('display', 'block');
$('#calendar_import_status').html(data.message);
}else{
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
- $("#calendar_import_progressbar > div").css('background-color', '#FF2626');
+ $('#calendar_import_progressbar > div').css('background-color', '#FF2626');
$('#calendar_import_status').html(data.message);
}
});
- $('#form_container').css('display', 'none');
- $('#progressbar_container').css('display', 'block');
- window.setTimeout('Calendar_Import.Dialog.update', 500);
},
prepare: function(){
Calendar_Import.Store.id = $('#calendar_import_calendar option:selected').val();
diff --git a/apps/calendar/lib/import.php b/apps/calendar/lib/import.php
index 92bcc312616..f348be37944 100644
--- a/apps/calendar/lib/import.php
+++ b/apps/calendar/lib/import.php
@@ -10,6 +10,11 @@
*/
class OC_Calendar_Import{
/*
+ * @brief counts the absolute number of parsed elements
+ */
+ private $abscount;
+
+ /*
* @brief var saves if the percentage should be saved with OC_Cache
*/
private $cacheprogress;
@@ -45,6 +50,11 @@ class OC_Calendar_Import{
private $progress;
/*
+ * @brief var saves the key for the percentage of the import's progress
+ */
+ private $progresskey;
+
+ /*
* @brief var saves the timezone the events shell converted to
*/
private $tz;
@@ -67,6 +77,7 @@ class OC_Calendar_Import{
public function __construct($ical){
$this->error = null;
$this->ical = $ical;
+ $this->abscount = 0;
$this->count = 0;
try{
$this->calobject = OC_VObject::parse($this->ical);
@@ -86,6 +97,7 @@ class OC_Calendar_Import{
if(!$this->isValid()){
return false;
}
+ $numofcomponents = count($this->calobject->getComponents());
foreach($this->calobject->getComponents() as $object){
if(!($object instanceof Sabre_VObject_Component_VEvent) && !($object instanceof Sabre_VObject_Component_VJournal) && !($object instanceof Sabre_VObject_Component_VTodo)){
continue;
@@ -96,12 +108,15 @@ class OC_Calendar_Import{
$object->DTEND->getDateTime()->setTimezone(new DateTimeZone($this->tz));
$vcalendar = $this->createVCalendar($object->serialize());
$insertid = OC_Calendar_Object::add($this->id, $vcalendar);
+ $this->abscount++;
if($this->isDuplicate($insertid)){
OC_Calendar_Object::delete($insertid);
}else{
- $this->count++;
+ $this->count++;
}
+ $this->updateProgress(intval(($this->abscount / $numofcomponents)*100));
}
+ OC_Cache::remove($this->progresskey);
return true;
}
@@ -115,6 +130,15 @@ class OC_Calendar_Import{
}
/*
+ * @brief sets the progresskey
+ * @return boolean
+ */
+ public function setProgresskey($progresskey){
+ $this->progresskey = $progresskey;
+ return true;
+ }
+
+ /*
* @brief checks if something went wrong while initialization
* @return boolean
*/
@@ -259,12 +283,17 @@ class OC_Calendar_Import{
}
/*
- * @brief
- * @return
+ * @brief updates the progress var
+ * @param integer $percentage
+ * @return boolean
*/
- //private function (){
-
- //}
+ private function updateProgress($percentage){
+ $this->progress = $percentage;
+ if($this->cacheprogress){
+ OC_Cache::set($this->progresskey, $this->progress, 300);
+ }
+ return true;
+ }
/*
* public methods for (pre)rendering of X-... Attributes
diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php
index c7156c79d75..1029cdd9254 100644
--- a/apps/calendar/templates/part.import.php
+++ b/apps/calendar/templates/part.import.php
@@ -17,7 +17,7 @@ $calendar_options[] = array('id'=>'newcal', 'displayname'=>$l->t('create a new c
<input type="hidden" id="calendar_import_filename" value="<?php echo $_['filename'];?>">
<input type="hidden" id="calendar_import_path" value="<?php echo $_['path'];?>">
<input type="hidden" id="calendar_import_progresskey" value="<?php echo rand() ?>">
- <span id="calendar_import_form_message"><?php echo $l->t('Please choose a calendar'); ?></span>
+ <div id="calendar_import_form_message"><?php echo $l->t('Please choose a calendar'); ?></div>
<select style="width:100%;" id="calendar_import_calendar" name="calendar_import_calendar">
<?php
for($i = 0;$i<count($calendar_options);$i++){
@@ -27,15 +27,15 @@ $calendar_options[] = array('id'=>'newcal', 'displayname'=>$l->t('create a new c
?>
</select>
<div id="calendar_import_newcalform">
- <input id="calendar_import_newcalendar" type="text" placeholder="<?php echo $l->t('Name of new calendar'); ?>" value="<?php echo $newcalendarname ?>"><br>
+ <input id="calendar_import_newcalendar" class="" type="text" placeholder="<?php echo $l->t('Name of new calendar'); ?>" value="<?php echo $newcalendarname ?>"><br>
<!--<input id="calendar_import_generatename" type="button" class="button" value="<?php echo $l->t('Take an available name!'); ?>"><br>-->
- <span id="calendar_import_mergewarning" class="hint"><?php echo $l->t('A Calendar with this name already exists. If you continue anyhow, these calendars will be merged.'); ?></span>
+ <div id="calendar_import_mergewarning" class="hint"><?php echo $l->t('A Calendar with this name already exists. If you continue anyhow, these calendars will be merged.'); ?></div>
</div>
<input id="calendar_import_submit" type="button" class="button" value="&raquo; <?php echo $l->t('Import'); ?> &raquo;" id="startimport">
<form>
</div>
<div id="calendar_import_process">
- <span id="calendar_import_process_message"></span>
+ <div id="calendar_import_process_message"></div>
<div id="calendar_import_progressbar"></div>
<br>
<div id="calendar_import_status" class="hint"></div>