-Implement localisation for file error messages -Fix CSS -Change dialogs method to OC.dialogs -Create noteservice->getNote method for exception handling instead of doing it in the db entity.
This commit is contained in:
parent
14aab3923f
commit
90b694070c
|
@ -17,7 +17,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|||
use OC\Encryption\Exceptions\DecryptionFailedException;
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCA\Notes\Service\NotesService;
|
||||
use OCA\Notes\Service\NoteDoesNotExistException;
|
||||
|
||||
|
@ -34,20 +34,23 @@ class PageController extends Controller {
|
|||
private $settings;
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var string */
|
||||
private $l10n;
|
||||
/**
|
||||
* @param string $AppName
|
||||
* @param IRequest $request
|
||||
* @param NotesService $notesService
|
||||
* @param IConfig $settings
|
||||
* @param string $UserId
|
||||
* @param IL10N $l10n
|
||||
*/
|
||||
public function __construct($AppName, IRequest $request, $UserId,
|
||||
NotesService $notesService, IConfig $settings){
|
||||
NotesService $notesService, IConfig $settings, IL10N $l10n){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->notesService = $notesService;
|
||||
$this->userId = $UserId;
|
||||
$this->settings = $settings;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,12 +67,9 @@ class PageController extends Controller {
|
|||
try {
|
||||
$this->notesService->get($lastViewedNote, $this->userId);
|
||||
$errorMessage=null;
|
||||
} catch(NoteDoesNotExistException $ex) {
|
||||
} catch(\Exception $ex) {
|
||||
$lastViewedNote = 0;
|
||||
$errorMessage="The last viewed note cannot be accessed. ".$ex->getMessage();
|
||||
} catch(DecryptionFailedException $ex){
|
||||
$lastViewedNote = 0;
|
||||
$errorMessage=$ex->getMessage();
|
||||
$errorMessage=$this->l10n->t('The last viewed note cannot be accessed. ').$ex->getMessage();
|
||||
}
|
||||
|
||||
$response = new TemplateResponse(
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#app-navigation .active a {
|
||||
padding-right: 70px;
|
||||
}
|
||||
#app-navigation > ul > li.note.has-error a{
|
||||
|
||||
#app-navigation > ul > li.has-error a{
|
||||
color:#f00;
|
||||
}
|
||||
.app-content-list-button {
|
||||
|
|
20
db/note.php
20
db/note.php
|
@ -14,7 +14,6 @@ namespace OCA\Notes\Db;
|
|||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OC\Encryption\Exceptions\DecryptionFailedException;
|
||||
use League\Flysystem\FileNotFoundException;
|
||||
/**
|
||||
* Class Note
|
||||
|
@ -52,23 +51,6 @@ class Note extends Entity {
|
|||
$this->addType('modified', 'integer');
|
||||
$this->addType('favorite', 'boolean');
|
||||
}
|
||||
/**
|
||||
* @param File $file
|
||||
* @return static
|
||||
*/
|
||||
public static function fromFileMaybe(File $file, Folder $notesFolder, $tags=[]){
|
||||
|
||||
$id=$file->getId();
|
||||
|
||||
try{
|
||||
$note=self::fromFile($file, $notesFolder, $tags=[]);
|
||||
}catch(FileNotFoundException $e){
|
||||
$note = self::fromException('File error: ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}catch(DecryptionFailedException $e){
|
||||
$note = self::fromException('Encryption Error: ('.$file->getName().')'.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param File $file
|
||||
|
@ -105,7 +87,7 @@ class Note extends Entity {
|
|||
$note->setError(true);
|
||||
$note->setContent($message);
|
||||
$note->setModified(null);
|
||||
$note->setTitle($message); // remove extension
|
||||
$note->setTitle(pathinfo($file->getName(),PATHINFO_FILENAME)); // remove extension
|
||||
$subdir = substr(dirname($file->getPath()), strlen($notesFolder->getPath())+1);
|
||||
$note->setCategory($subdir ? $subdir : null);
|
||||
if(is_array($tags) && in_array(\OC\Tags::TAG_FAVORITE, $tags)) {
|
||||
|
|
|
@ -28,7 +28,7 @@ app.factory('NotesModel', function () {
|
|||
},
|
||||
get: function (id) {
|
||||
if(this.notesIds[id].error) {
|
||||
OCdialogs.alert(this.notesIds[id].errorMessage,'Error!');
|
||||
OC.dialogs.alert(this.notesIds[id].errorMessage,'An error occurred!');
|
||||
return false;
|
||||
}
|
||||
return this.notesIds[id];
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -16,7 +16,8 @@ use OCP\IL10N;
|
|||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\ILogger;
|
||||
|
||||
use OC\Encryption\Exceptions\DecryptionFailedException;
|
||||
use League\Flysystem\FileNotFoundException;
|
||||
use OCA\Notes\Db\Note;
|
||||
|
||||
/**
|
||||
|
@ -65,7 +66,7 @@ class NotesService {
|
|||
|
||||
$notes = [];
|
||||
foreach($filesById as $id=>$file) {
|
||||
$notes[] = Note::fromFileMaybe($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
$notes[] = $this->getNote($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}
|
||||
|
||||
return $notes;
|
||||
|
@ -81,7 +82,7 @@ class NotesService {
|
|||
*/
|
||||
public function get ($id, $userId) {
|
||||
$folder = $this->getFolderForUser($userId);
|
||||
return Note::fromFileMaybe($this->getFileById($folder, $id), $folder, $this->getTags($id));
|
||||
return $this->getNote($this->getFileById($folder, $id), $folder, $this->getTags($id));
|
||||
}
|
||||
|
||||
private function getTags ($id) {
|
||||
|
@ -93,7 +94,21 @@ class NotesService {
|
|||
}
|
||||
return array_key_exists($id, $tags) ? $tags[$id] : [];
|
||||
}
|
||||
private function getNote($file,$notesFolder,$tags=[]){
|
||||
|
||||
$id=$file->getId();
|
||||
|
||||
try{
|
||||
$note=Note::fromFile($file, $notesFolder, $tags);
|
||||
}catch(FileNotFoundException $e){
|
||||
$note = Note::fromException($this->l10n->t('File error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}catch(DecryptionFailedException $e){
|
||||
$note = Note::fromException($this->l10n->t('Encryption Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}catch(\Exception $e){
|
||||
$note = Note::fromException($this->l10n->t('Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
|
||||
}
|
||||
return $note;
|
||||
}
|
||||
/**
|
||||
* Creates a note and returns the empty note
|
||||
* @param string $userId
|
||||
|
@ -110,7 +125,7 @@ class NotesService {
|
|||
$path = $this->generateFileName($folder, $title, "txt", -1);
|
||||
$file = $folder->newFile($path);
|
||||
|
||||
return Note::fromFileMaybe($file, $folder);
|
||||
return $this->getNote($file, $folder);
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,7 +186,7 @@ class NotesService {
|
|||
$file->touch($mtime);
|
||||
}
|
||||
|
||||
return Note::fromFileMaybe($file, $notesFolder, $this->getTags($id));
|
||||
return $this->getNote($file, $notesFolder, $this->getTags($id));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue