r9716 - in helma-ng/trunk: apps/filestore apps/filestore/skins apps/googlestore apps/googlestore/skins modules/helma modules/helma/storage
[email protected] Thu, 7 May 2009 15:22:04 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090507132204.769F93D0D6@mia> |
Author: hannes
Date: 2009-05-07 15:22:04 +0200 (Thu, 07 May 2009)
New Revision: 9716
Added:
helma-ng/trunk/modules/helma/storage/filestore.js
helma-ng/trunk/modules/helma/storage/googlestore.js
helma-ng/trunk/modules/helma/storage/memstore.js
helma-ng/trunk/modules/helma/storage/storable.js
Removed:
helma-ng/trunk/modules/helma/filestore.js
helma-ng/trunk/modules/helma/googlestore.js
Modified:
helma-ng/trunk/apps/filestore/main.js
helma-ng/trunk/apps/filestore/model.js
helma-ng/trunk/apps/filestore/skins/index.html
helma-ng/trunk/apps/googlestore/main.js
helma-ng/trunk/apps/googlestore/model.js
helma-ng/trunk/apps/googlestore/skins/index.html
Log:
Unify filestore and googlestore modules around common Storable API, add memstore implementation, move everything to helma/storage/*.
Details at http://dev.helma.org/trac/helma/changeset/9716
Modified: helma-ng/trunk/apps/filestore/main.js
===================================================================
--- helma-ng/trunk/apps/filestore/main.js 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/filestore/main.js 2009-05-07 13:22:04 UTC (rev 9716)
@@ -1,7 +1,7 @@
include('helma/webapp/response');
include('./model');
-export('index', 'edit');
+export('index', 'edit', 'remove');
// the main action is invoked for http://localhost:8080/
// this also shows simple skin rendering
@@ -9,9 +9,6 @@
if (req.params.save) {
return createBook(req);
}
- if (req.params.remove) {
- return removeBook(req);
- }
return SkinnedResponse(getResource('./skins/index.html'), {
title: 'Storage',
books: Book.all(),
@@ -36,19 +33,33 @@
})
}
+function remove(req, id) {
+ var book = Book.get(id);
+ if (req.params.remove && req.isPost) {
+ return removeBook(req, book);
+ }
+ return SkinnedResponse(getResource('./skins/remove.html'), {
+ title: 'Storage',
+ book: book,
+ action: req.path
+ })
+}
+
function createBook(req) {
var author = new Author({name: req.params.author});
var book = new Book({author: author, title: req.params.title});
+ author.books = [book];
// author is saved transitively
+ // author.save();
book.save();
return new RedirectResponse(req.path);
}
-function removeBook(req) {
- var book = Book.get(req.params.remove);
- // author is removed through cascading delete
+function removeBook(req, book) {
+ // no cascading delete
+ book.author.remove();
book.remove();
- return new RedirectResponse(req.path);
+ return new RedirectResponse("../");
}
if (__name__ == "__main__") {
Modified: helma-ng/trunk/apps/filestore/model.js
===================================================================
--- helma-ng/trunk/apps/filestore/model.js 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/filestore/model.js 2009-05-07 13:22:04 UTC (rev 9716)
@@ -1,4 +1,4 @@
-import('helma/filestore', 'filestore');
+include('helma/storage/filestore');
export('Book', 'Author');
@@ -8,58 +8,15 @@
* Book class
* @param properties object containing persistent properties
*/
-function Book(properties) {
- this.properties = properties || {};
+var Book = Storable('Book');
- this.getFullTitle = function() {
- return this.author.name + ": " + this.title;
- };
+Book.prototype.getFullTitle = function() {
+ return this.author.name + ": " + this.title;
+};
- return this;
-}
-
/**
* Author class
* @param properties object containing persistent properties
*/
-function Author(properties) {
- this.properties = properties || {};
- return this;
-}
+var Author = Storable('Author');
-
-// init store instance and register persistent classes.
-var store = new filestore.Store("db");
-
-/*
- The call to registerType installs getters and setters for the
- persistent data fields in the constructor's prototype property.
-
- It also adds the following static methods in the constructor:
-
- Book.get(id) - get a persistent object of this type by id
- Book.all() - get an array containing all objects of this type
- Book.list() - get filtered, ordered and sliced lists of this type
-
- The following instance fields and methods are isntalled in
- the constructor's prototype property:
-
- Book.prototype._type - the type name as String (e.g. "Book")
- Book.prototype.save() - save this instance in the database
- Book.prototype.remove() - remove this instance from the database
- Book.prototype.getKey() - get a key to refer to this persistent instance
-
-*/
-store.registerType(Book, {
- title: filestore.Text(),
- author: filestore.Reference(Author)
-});
-
-store.registerType(Author, {
- name: filestore.Text(),
- books: filestore.List(Book, {
- filter: function(obj) this.equals(obj.properties.author),
- orderBy: "title",
- order: "asc"
- })
-});
Modified: helma-ng/trunk/apps/filestore/skins/index.html
===================================================================
--- helma-ng/trunk/apps/filestore/skins/index.html 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/filestore/skins/index.html 2009-05-07 13:22:04 UTC (rev 9716)
@@ -11,12 +11,14 @@
</form>
<h3>Available Books</h3>
-<p>
+<table cellspacing="0" cellpadding="3">
<% for book in <% books %> render book %>
-</p>
+</table>
<% subskin 'book' ----------------------------------- %>
-<div><% book.author.name %>: <% book.title %>
- <a href="edit/<% book._id %>">[edit]</a>
- <a href="?remove=<% book._id %>">[remove]</a>
-</div>
+<tr style="<% ifEven 'background-color: #eee;' %>">
+ <td><% book.author.name %></td>
+ <td><% book.title %></td>
+ <td><a href="edit/<% book._id %>">[edit]</a></td>
+ <td><a href="remove/<% book._id %>">[remove]</a></td>
+</tr>
Modified: helma-ng/trunk/apps/googlestore/main.js
===================================================================
--- helma-ng/trunk/apps/googlestore/main.js 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/googlestore/main.js 2009-05-07 13:22:04 UTC (rev 9716)
@@ -47,8 +47,10 @@
function createBook(req) {
var author = new Author({name: req.params.author});
- author.save(); // no cascading save yet
var book = new Book({author: author, title: req.params.title});
+ author.books = [book];
+ // author is saved transitively
+ // author.save();
book.save();
return new RedirectResponse(req.path);
}
@@ -59,3 +61,7 @@
book.remove();
return new RedirectResponse("../");
}
+
+if (__name__ == "__main__") {
+ require('helma/webapp').start();
+}
Modified: helma-ng/trunk/apps/googlestore/model.js
===================================================================
--- helma-ng/trunk/apps/googlestore/model.js 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/googlestore/model.js 2009-05-07 13:22:04 UTC (rev 9716)
@@ -1,4 +1,4 @@
-include('helma/googlestore');
+include('helma/storage/googlestore');
export('Book', 'Author');
Modified: helma-ng/trunk/apps/googlestore/skins/index.html
===================================================================
--- helma-ng/trunk/apps/googlestore/skins/index.html 2009-05-06 19:54:38 UTC (rev 9715)
+++ helma-ng/trunk/apps/googlestore/skins/index.html 2009-05-07 13:22:04 UTC (rev 9716)
@@ -19,6 +19,6 @@
<tr style="<% ifEven 'background-color: #eee;' %>">
<td><% book.author.name %></td>
<td><% book.title %></td>
- <td><a href="edit/<% book.getId %>">[edit]</a></td>
- <td><a href="remove/<% book.getId %>">[remove]</a></td>
+ <td><a href="edit/<% book._id %>">[edit]</a></td>
+ <td><a href="remove/<% book._id %>">[remove]</a></td>
</tr>
Deleted: helma-ng/trunk/modules/helma/filestore.js
Deleted: helma-ng/trunk/modules/helma/googlestore.js
Added: helma-ng/trunk/modules/helma/storage/filestore.js
Added: helma-ng/trunk/modules/helma/storage/googlestore.js
Added: helma-ng/trunk/modules/helma/storage/memstore.js
Added: helma-ng/trunk/modules/helma/storage/storable.js