diff --git a/Procfile b/Procfile index e2de4158..9b33f73e 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ server: nodemon server.js -watch: node_modules/.bin/webpack --watch \ No newline at end of file +watch: node_modules/.bin/rollup -c --watch \ No newline at end of file diff --git a/index.js b/index.js index fb519324..98a6bcc1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,3 @@ -require('./scss/main.scss'); - const client = require('frappejs/client'); // start server diff --git a/js/bundle.js b/js/bundle.js index 257a2223..8a0dc15a 100644 --- a/js/bundle.js +++ b/js/bundle.js @@ -1,1568 +1,4 @@ -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = "/"; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 7); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports) { - -module.exports = { - async init() { - if (this._initialized) return; - this.init_config(); - this.init_globals(); - this._initialized = true; - }, - - init_config() { - this.config = { - backend: 'sqlite', - port: 8000 - }; - }, - - init_globals() { - this.meta_cache = {}; - this.modules = {}; - this.docs = {}; - this.flags = { - cache_docs: false - } - }, - - add_to_cache(doc) { - if (!this.flags.cache_docs) return; - - // add to `docs` cache - if (doc.doctype && doc.name) { - if (!this.docs[doc.doctype]) { - this.docs[doc.doctype] = {}; - } - this.docs[doc.doctype][doc.name] = doc; - } - }, - - get_doc_from_cache(doctype, name) { - if (this.docs[doctype] && this.docs[doctype][name]) { - return this.docs[doctype][name]; - } - }, - - get_meta(doctype) { - if (!this.meta_cache[doctype]) { - this.meta_cache[doctype] = new (this.get_meta_class(doctype))(); - } - return this.meta_cache[doctype]; - }, - - get_meta_class(doctype) { - doctype = this.slug(doctype); - if (this.modules[doctype] && this.modules[doctype].Meta) { - return this.modules[doctype].Meta; - } else { - return this.BaseMeta; - } - }, - - async get_doc(data, name) { - if (typeof data==='string' && typeof name==='string') { - let doc = this.get_doc_from_cache(data, name); - if (!doc) { - let controller_class = this.get_controller_class(data); - doc = new controller_class({doctype:data, name: name}); - await doc.load(); - this.add_to_cache(doc); - } - return doc; - } else { - let controller_class = this.get_controller_class(data.doctype); - var doc = new controller_class(data); - } - return doc; - }, - - get_controller_class(doctype) { - doctype = this.slug(doctype); - if (this.modules[doctype] && this.modules[doctype].Document) { - return this.modules[doctype].Document; - } else { - return this.BaseDocument; - } - }, - - async get_new_doc(doctype) { - let doc = await frappe.get_doc({doctype: doctype}); - doc.set_name(); - doc.__not_inserted = true; - this.add_to_cache(doc); - return doc; - }, - - async insert(data) { - const doc = await this.get_doc(data); - return await doc.insert(); - }, - - login(user='guest', user_key) { - this.session = new this._session.Session(user); - if (user && user_key) { - this.authenticate(user_key); - } - }, - - close() { - this.db.close(); - - if (this.server) { - this.server.close(); - } - } -}; - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -const frappe = __webpack_require__(0); - -module.exports = class BaseDocument { - constructor(data) { - this.handlers = {}; - this.setup(); - Object.assign(this, data); - } - - setup() { - // add handlers - } - - clear_handlers() { - this.handlers = {}; - } - - add_handler(key, method) { - if (!this.handlers[key]) { - this.handlers[key] = []; - } - this.handlers[key].push(method || key); - } - - get(fieldname) { - return this[fieldname]; - } - - // set value and trigger change - async set(fieldname, value) { - this[fieldname] = await this.validate_field(fieldname, value); - await this.trigger('change', {doc: this, fieldname: fieldname, value: value}); - } - - set_name() { - // assign a random name by default - // override this to set a name - if (!this.name) { - this.name = Math.random().toString(36).substr(3); - } - } - - set_keywords() { - let keywords = []; - for (let fieldname of this.meta.get_keyword_fields()) { - keywords.push(this[fieldname]); - } - this.keywords = keywords.join(', '); - } - - get meta() { - if (!this._meta) { - this._meta = frappe.get_meta(this.doctype); - } - return this._meta; - } - - append(key, document) { - if (!this[key]) { - this[key] = []; - } - this[key].push(this.init_doc(document)); - } - - init_doc(data) { - if (data.prototype instanceof Document) { - return data; - } else { - return new Document(d); - } - } - - async validate_field (key, value) { - let df = this.meta.get_field(key); - if (df.fieldtype=='Select') { - return this.meta.validate_select(df, value); - } - return value; - } - - get_valid_dict() { - let doc = {}; - for(let df of this.meta.get_valid_fields()) { - doc[df.fieldname] = this.get(df.fieldname); - } - return doc; - } - - set_standard_values() { - let now = new Date(); - if (this.docstatus === null || this.docstatus === undefined) { - this.docstatus = 0; - } - if (!this.owner) { - this.owner = frappe.session.user; - this.creation = now; - } - this.modified_by = frappe.session.user; - this.modified = now; - } - - async load() { - let data = await frappe.db.get(this.doctype, this.name); - if (data.name) { - Object.assign(this, data); - } else { - throw new frappe.errors.NotFound(`Not Found: ${this.doctype} ${this.name}`); - } - } - - async insert() { - this.set_name(); - this.set_standard_values(); - this.set_keywords(); - await this.trigger('validate'); - await this.trigger('before_insert'); - await frappe.db.insert(this.doctype, this.get_valid_dict()); - await this.trigger('after_insert'); - await this.trigger('after_save'); - } - - async delete() { - await this.trigger('before_delete'); - await frappe.db.delete(this.doctype, this.name); - await this.trigger('after_delete'); - } - - async trigger(key, params) { - if (this.handlers[key]) { - for (let method of this.handlers[key]) { - if (typeof method === 'string') { - await this[method](params); - } else { - await method(params); - } - } - } - } - - async update() { - this.set_standard_values(); - this.set_keywords(); - await this.trigger('validate'); - await this.trigger('before_update'); - await frappe.db.update(this.doctype, this.get_valid_dict()); - await this.trigger('after_update'); - await this.trigger('after_save'); - return this; - } -}; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -const frappe = __webpack_require__(0); - -class BaseControl { - constructor(docfield, form) { - Object.assign(this, docfield); - this.form = form; - if (!this.fieldname) { - this.fieldname = frappe.slug(this.label); - } - this.parent = form.form; - if (this.setup) { - this.setup(); - } - } - - bind(doc) { - this.doc = doc; - this.set_doc_value(); - } - - refresh() { - this.make(); - this.set_doc_value(); - } - - set_doc_value() { - if (this.doc) { - this.set_input_value(this.doc.get(this.fieldname)); - } - } - - make() { - if (!this.form_group) { - this.make_form_group(); - this.make_label(); - this.make_input(); - this.set_input_name(); - this.make_description(); - this.bind_change_event(); - } - } - - make_form_group() { - this.form_group = frappe.ui.add('div', 'form-group', this.parent); - } - - make_label() { - this.label_element = frappe.ui.add('label', null, this.form_group); - this.label_element.textContent = this.label; - } - - make_input() { - this.input = frappe.ui.add('input', 'form-control', this.form_group); - this.input.setAttribute('autocomplete', 'off'); - } - - set_input_name() { - this.input.setAttribute('name', this.fieldname); - } - - make_description() { - if (this.description) { - this.description_element = frappe.ui.add('small', 'form-text text-muted', this.form_group); - this.description_element.textContent = this.description; - } - } - - set_input_value(value) { - this.input.value = this.format(value); - } - - format(value) { - if (value === undefined || value === null) { - value = ''; - } - return value; - } - - async get_parsed_value() { - return await this.parse(this.input.value); - } - - get_input_value() { - return this.input.value; - } - - async parse(value) { - return value; - } - - async validate(value) { - return value; - } - - bind_change_event() { - this.input.addEventListener('change', (e) => this.handle_change(e)); - } - - async handle_change(e) { - let value = await this.parse(this.get_input_value()); - value = await this.validate(value); - if (this.doc[this.fieldname] !== value) { - await this.doc.set(this.fieldname, value); - } - } - - disable() { - this.input.setAttribute('disabled', 'disabled'); - } - - enable() { - this.input.removeAttribute('disabled'); - } -} - -module.exports = BaseControl; - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -const BaseDocument = __webpack_require__(1); -const frappe = __webpack_require__(0); - -module.exports = class BaseMeta extends BaseDocument { - constructor(data) { - super(data); - this.event_handlers = {}; - this.list_options = { - fields: ['name', 'modified'] - }; - if (this.setup_meta) { - this.setup_meta(); - } - } - - get_field(fieldname) { - if (!this.field_map) { - this.field_map = {}; - for (let df of this.fields) { - this.field_map[df.fieldname] = df; - } - } - return this.field_map[fieldname]; - } - - on(key, fn) { - if (!this.event_handlers[key]) { - this.event_handlers[key] = []; - } - this.event_handlers[key].push(fn); - } - - async set(fieldname, value) { - this[fieldname] = value; - await this.trigger(fieldname); - } - - get(fieldname) { - return this[fieldname]; - } - - get_valid_fields() { - if (!this._valid_fields) { - this._valid_fields = []; - - const doctype_fields = this.fields.map((df) => df.fieldname); - - // standard fields - for (let df of frappe.model.standard_fields) { - if (frappe.db.type_map[df.fieldtype] && !doctype_fields.includes(df.fieldname)) { - this._valid_fields.push(df); - } - } - - // parent fields - if (this.istable) { - for (let df of frappe.model.child_fields) { - if (frappe.db.type_map[df.fieldtype] && !doctype_fields.includes(df.fieldname)) { - this._valid_fields.push(df); - } - } - } - - // doctype fields - for (let df of this.fields) { - if (frappe.db.type_map[df.fieldtype]) { - this._valid_fields.push(df); - } - } - } - - return this._valid_fields; - } - - get_keyword_fields() { - return this.keyword_fields || this.meta.fields.filter(df => df.reqd).map(df => df.fieldname); - } - - validate_select(df, value) { - let options = df.options; - if (typeof options === 'string') { - // values given as string - options = df.options.split('\n'); - } - if (!options.includes(value)) { - throw new frappe.errors.ValueError(`${value} must be one of ${options.join(", ")}`); - } - return value; - } - - async trigger(key, event = {}) { - Object.assign(event, { - doc: this, - name: key - }); - - if (this.event_handlers[key]) { - for (var handler of this.event_handlers[key]) { - await handler(event); - } - } - } -} - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -const frappe = __webpack_require__(0); - -module.exports = class BaseList { - constructor({doctype, parent, fields}) { - this.doctype = doctype; - this.parent = parent; - this.fields = fields; - - this.meta = frappe.get_meta(this.doctype); - - this.start = 0; - this.page_length = 20; - - this.body = null; - this.rows = []; - this.data = []; - } - - async run() { - this.make_body(); - - let data = await this.get_data(); - - for (let i=0; i< Math.min(this.page_length, data.length); i++) { - this.render_row(this.start + i, data[i]); - } - - if (this.start > 0) { - this.data = this.data.concat(data); - } else { - this.data = data; - } - - this.clear_empty_rows(); - this.update_more(data.length > this.page_length); - } - - async get_data() { - return await frappe.db.get_all({ - doctype: this.doctype, - fields: this.get_fields(), - filters: this.get_filters(), - start: this.start, - limit: this.page_length + 1 - }); - } - - get_fields() { - return ['name']; - } - - async append() { - this.start += this.page_length; - await this.run(); - } - - get_filters() { - let filters = {}; - if (this.search_input.value) { - filters.keywords = ['like', '%' + this.search_input.value + '%']; - } - return filters; - } - - make_body() { - if (!this.body) { - this.make_toolbar(); - //this.make_new(); - this.body = frappe.ui.add('div', 'list-body', this.parent); - this.make_more_btn(); - } - } - - make_toolbar() { - this.toolbar = frappe.ui.add('div', 'list-toolbar', this.parent); - this.toolbar.innerHTML = ` -