2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

add pages

This commit is contained in:
Rushabh Mehta 2018-01-09 19:10:33 +05:30
parent 90b5badec8
commit 60832b1d96
6 changed files with 758 additions and 10530 deletions

2
Procfile Normal file
View File

@ -0,0 +1,2 @@
server: nodemon server.js
watch: node_modules/.bin/webpack --watch

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Sample app for frappe-core
Sample To Do app for frappe-core
### Install
Install dependencies
`yarn install`
### Build
```sh
node_modules/.bin/webpack
```
### Start
To start the app + build process
```sh
yarn global add foreman
nf start
```

View File

@ -1,32 +1,50 @@
require('./scss/main.scss');
window.$ = require('jquery');
const common = require('frappe-core/frappe/common');
const Database = require('frappe-core/frappe/backends/rest_client').Database
const client = require('frappe-core/frappe/client');
window.frappe = require('frappe-core');
const listview = require('frappe-core/frappe/view/list.js');
const ListView = require('frappe-core/frappe/client/view/list').ListView;
const Page = require('frappe-core/frappe/client/view/page').Page;
const Form = require('frappe-core/frappe/client/view/form').Form;
async function start() {
frappe.init();
common.init_libs(frappe);
frappe.db = await new Database({
server: 'localhost:8000',
fetch: window.fetch.bind()
});
window.todo_app = {};
// start server
client.start({
server: 'localhost:8000',
container: document.querySelector('.container'),
}).then(() => {
const todo = require('frappe-core/frappe/models/doctype/todo/todo.js');
frappe.init_controller('todo', todo);
frappe.init_view({container: $('.container')});
}
// make pages
todo_app.edit_page = new Page('Edit To Do');
todo_app.todo_list = new Page('ToDo List');
start().then(() => {
let todo_list = new listview.ListView({
doctype: 'ToDo',
parent: frappe.main
// to do list
frappe.router.add('default', () => {
todo_app.todo_list.show();
if (!todo_app.todo_list.list) {
todo_app.todo_list.list = new ListView({
doctype: 'ToDo',
parent: todo_app.todo_list.body
});
}
todo_app.todo_list.list.run();
});
todo_list.render();
})
// setup todo form
frappe.router.add('todo/:name', async (params) => {
todo_app.edit_page.show();
if (!todo_app.edit_page.form) {
todo_app.edit_page.form = new Form({
doctype: 'ToDo',
parent: todo_app.edit_page.body
});
todo_app.edit_page.form.make();
}
todo_app.doc = await frappe.get_doc('ToDo', params.name);
todo_app.edit_page.form.use(todo_app.doc);
});
frappe.router.show(window.location.hash);
});

11189
js/bundle.js

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,6 @@ html {
}
.wrapper {
margin-top: 20px;
display: grid;
grid-template-columns: 1fr 4fr;
grid-auto-rows: minmax(500px, auto);
@ -25,3 +24,7 @@ html {
.sidebar {
background-color: $gray-100;
}
.hide {
display: none !important;
}

View File

@ -1,10 +1,7 @@
const server = require('frappe-core/frappe/server');
const frappe = require('frappe-core');
const express = require('express');
server.start({
backend: 'sqllite',
connection_params: {db_path: 'test.db'}
}).then(() => {
frappe.app.use(express.static('./'));
connection_params: {db_path: 'test.db'},
static: './'
});