1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
Laurent Cozic 2017-05-23 19:58:12 +00:00
parent fde66df646
commit 56dc74c4cc
9 changed files with 77 additions and 48 deletions

View File

@ -3,6 +3,7 @@ import { View, Button, TextInput } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'src/log.js'
import { Note } from 'src/models/note.js'
import { Registry } from 'src/registry.js'
import { ScreenHeader } from 'src/components/screen-header.js';
class NoteScreenComponent extends React.Component {
@ -45,8 +46,9 @@ class NoteScreenComponent extends React.Component {
saveNoteButton_press = () => {
let isNew = !this.state.note.id;
Note.save(this.state.note).then((note) => {
Log.info('NOTE', note);
if (isNew) Note.updateGeolocation(note.id);
if (isNew) return Note.updateGeolocation(note.id);
}).then(() => {
Registry.synchronizer().start();
});
}

View File

@ -15,6 +15,7 @@ function main() {
Registry.setDebugMode(true);
AppRegistry.registerComponent('AwesomeProject', () => Root);
Log.setLevel(Registry.debugMode() ? Log.LEVEL_DEBUG : Log.LEVEL_WARN);
console.ignoredYellowBox = ['Remote debugger'];
Log.info('START ======================================================================================================');
// Note: The final part of the initialization process is in
// AppComponent.componentDidMount(), when the application is ready.

View File

@ -45,7 +45,7 @@ class Note extends BaseModel {
geoData = data;
return Note.load(noteId);
}).then((note) => {
if (!note) return; // Race condition note - has been deleted in the meantime
if (!note) return; // Race condition - note has been deleted in the meantime
note.longitude = geoData.coords.longitude;
note.latitude = geoData.coords.latitude;
note.altitude = geoData.coords.altitude;

View File

@ -136,10 +136,12 @@ class Synchronizer {
});
}
promiseChain(chain).then(() => {
return promiseChain(chain).then(() => {
Log.info('IDs to delete: ', processedChangeIds);
Change.deleteMultiple(processedChangeIds);
});
}).then(() => {
this.processState('idle');
});
}
}

View File

@ -47,7 +47,7 @@ class FoldersController extends ApiController {
if ($request->isMethod('PUT')) {
$isNew = !$folder;
if ($isNew) $folder = new Folder();
$folder->fromPublicArray($this->putParameters());
$folder->fromPublicArray(Folder::filter($this->putParameters()));
$folder->id = Folder::unhex($id);
$folder->owner_id = $this->user()->id;
$folder->setIsNew($isNew);
@ -57,7 +57,7 @@ class FoldersController extends ApiController {
if ($request->isMethod('PATCH')) {
$data = $this->patchParameters();
$folder->fromPublicArray($this->patchParameters());
$folder->fromPublicArray(Folder::filter($this->patchParameters()));
$folder->id = Folder::unhex($id);
$folder->save();
return static::successResponse($folder);

View File

@ -39,7 +39,8 @@ class NotesController extends ApiController {
if ($request->isMethod('PUT')) {
$isNew = !$note;
if ($isNew) $note = new Note();
$note->fromPublicArray($this->putParameters());
$data = Note::filter($this->putParameters());
$note->fromPublicArray($data);
$note->id = Note::unhex($id);
$note->owner_id = $this->user()->id;
$note->setIsNew($isNew);
@ -48,8 +49,8 @@ class NotesController extends ApiController {
}
if ($request->isMethod('PATCH')) {
$data = $this->patchParameters();
$note->fromPublicArray($this->patchParameters());
$data = Note::filter($this->patchParameters());
$note->fromPublicArray($data);
$note->id = Note::unhex($id);
$note->save();
return static::successResponse($note);

View File

@ -149,8 +149,8 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
$this->revId = $v;
} else if (in_array($k, array('parent_id', 'client_id', 'item_id', 'user_id', 'owner_id'))) {
$this->{$k} = self::unhex($v);
} else if (in_array($k, $this->diffableFields)) {
$this->changedDiffableFields[$k] = $v;
} else if ($this->isDiffableField($k)) {
$this->setDiffableField($k, $v);
} else {
$this->{$k} = $v;
}
@ -190,45 +190,16 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
return $this->useUuid ? self::hex($this->id) : (string)$this->id;
}
// private function cachePrefix() {
// return 'Model.' . $this->classItemTypeName() . '.' . $this->idString();
// }
// public function cacheSet($key, $value) {
// return self::cache()->set($this->cachePrefix() . '.' . $key, $value);
// }
// public function cacheGet($key) {
// return self::cache()->get($this->cachePrefix() . '.' . $key);
// }
// public function cacheDelete($key) {
// self::cache()->delete($this->cachePrefix() . '.' . $key);
// }
// public function cacheGetOrSet($key, $func, $expiryTime = null) {
// return self::cache()->getOrSet($this->cachePrefix() . '.' . $key, $func, $expiryTime);
// }
// public function cacheClear() {
// $p = $this->cachePrefix();
// $this->cacheDelete('diffableField.title');
// $this->cacheDelete('diffableField.body');
// }
public function diffableField($fieldName) {
return Change::fullFieldText($this->id, $fieldName);
}
// $r = $this->cacheGet('diffableField.' . $fieldName);
// if ($r !== null) return $r . '*';
// $r = Change::fullFieldText($this->id, $fieldName);
// $this->cacheSet('diffableField.' . $fieldName, $r);
// return $r;
public function isDiffableField($fieldName) {
return in_array($fieldName, $this->diffableFields);
}
public function setDiffableField($fieldName, $fieldValue) {
//$this->cacheDelete('diffableField.' . $fieldName);
if ($this->diffableField($fieldName) == $fieldValue) return;
$this->changedDiffableFields[$fieldName] = $fieldValue;
}
@ -265,6 +236,20 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
return User::find($this->owner_id);
}
static public function isValidField($f) {
return array_key_exists($f, static::$fields);
}
static public function filter($data, $keepId = false) {
$output = array();
foreach ($data as $k => $v) {
if (!static::isValidField($k)) continue;
$output[$k] = $v;
}
if (!$keepId) unset($output['id']);
return $output;
}
static public function validate($data, $rules = null) {
if (!$rules) $rules = static::$defaultValidationRules;
@ -375,8 +360,6 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
unset($changedFields['updated_time']);
}
//if ($this->parent_id
$output = parent::save($options);
$this->isNew = null;
@ -392,8 +375,6 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
}
public function delete() {
//$this->cacheClear();
$output = parent::delete();
if (count($this->isVersioned)) {

View File

@ -7,6 +7,17 @@ class Folder extends BaseItem {
protected $diffableFields = array('title');
protected $isVersioned = true;
static protected $fields = array(
'id' => null,
'created_time' => null,
'updated_time' => null,
'parent_id' => null,
'owner_id' => null,
'is_encrypted' => null,
'encryption_method' => null,
'is_default' => null,
);
public function add($ids) {
$notes = Note::find($ids);
foreach ($notes as $note) {

View File

@ -7,4 +7,35 @@ class Note extends BaseItem {
protected $diffableFields = array('title', 'body');
protected $isVersioned = true;
static protected $fields = array(
'id' => null,
'completed' => null,
'created_time' => null,
'updated_time' => null,
'latitude' => null,
'longitude' => null,
'altitude' => null,
'parent_id' => null,
'owner_id' => null,
'is_encrypted' => null,
'encryption_method' => null,
'order' => null,
'is_todo' => null,
'todo_due' => null,
'todo_completed' => null,
'application_data' => null,
'author' => null,
'source' => null,
'source_application' => null,
'source_url' => null,
);
static public function filter($data) {
$output = parent::filter($data);
if (array_key_exists('longitude', $output)) $output['longitude'] = (string)number_format($output['longitude'], 8);
if (array_key_exists('latitude', $output)) $output['latitude'] = (string)number_format($output['latitude'], 8);
if (array_key_exists('altitude', $output)) $output['altitude'] = (string)number_format($output['altitude'], 4);
return $output;
}
}