commit 90b5badec86485a632414230ca90f9ec7b6bc758 Author: Rushabh Mehta Date: Mon Jan 8 17:59:49 2018 +0530 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..30197abd --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +node_modules +.DS_Store +Thumbs.db +test.db +*.log +.cache + +/dist +/temp + +# ignore everything in 'app' folder what had been generated from 'src' folder +/app/app.js +/app/background.js +/app/**/*.map diff --git a/.sassrc.js b/.sassrc.js new file mode 100644 index 00000000..dea78962 --- /dev/null +++ b/.sassrc.js @@ -0,0 +1,10 @@ +const path = require('path') + +const CWD = process.cwd() + +module.exports = { + "includePaths": [ + path.resolve(CWD, 'node_modules'), + path.resolve(CWD, 'client/scss') + ] +} diff --git a/index.html b/index.html new file mode 100644 index 00000000..f0dca572 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + +
+
+ + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 00000000..6d300f74 --- /dev/null +++ b/index.js @@ -0,0 +1,32 @@ +require('./scss/main.scss'); +window.$ = require('jquery'); + +const common = require('frappe-core/frappe/common'); +const Database = require('frappe-core/frappe/backends/rest_client').Database + +window.frappe = require('frappe-core'); +const listview = require('frappe-core/frappe/view/list.js'); + +async function start() { + frappe.init(); + common.init_libs(frappe); + + frappe.db = await new Database({ + server: 'localhost:8000', + fetch: window.fetch.bind() + }); + + const todo = require('frappe-core/frappe/models/doctype/todo/todo.js'); + frappe.init_controller('todo', todo); + + frappe.init_view({container: $('.container')}); +} + +start().then(() => { + let todo_list = new listview.ListView({ + doctype: 'ToDo', + parent: frappe.main + }); + todo_list.render(); +}) + diff --git a/js/bundle.js b/js/bundle.js new file mode 100644 index 00000000..92498c89 --- /dev/null +++ b/js/bundle.js @@ -0,0 +1,12032 @@ +/******/ (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 = 3); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +module.exports = { + async init() { + if (this._initialized) return; + this.init_config(); + this.init_errors(); + this.init_globals(); + this._initialized = true; + }, + + init_config() { + this.config = { + backend: 'sqlite', + port: 8000 + }; + }, + + init_errors() { + this.ValueError = class extends Error { }; + }, + + init_globals() { + this.meta_cache = {}; + }, + + init_view({container, main, sidebar}) { + this.container = container; + + if (sidebar) { + this.sidebar = sidebar; + } else { + this.sidebar = $('').appendTo(this.container); + } + + if (main) { + this.main = main; + } else { + this.main = $('
').appendTo(this.container); + } + }, + + get_meta(doctype) { + if (!this.meta_cache[doctype]) { + this.meta_cache[doctype] = new (this.models.get_meta_class(doctype))(this.models.get('DocType', doctype)); + } + return this.meta_cache[doctype]; + }, + + init_controller(doctype, module) { + doctype = this.slug(doctype); + this.models.controllers[doctype] = module[doctype]; + this.models.meta_classes[doctype] = module[doctype + '_meta']; + }, + + async get_doc(data, name) { + if (typeof data==='string' && typeof name==='string') { + let controller_class = this.models.get_controller(data); + var doc = new controller_class({doctype:data, name: name}); + await doc.load(); + } else { + let controller_class = this.models.get_controller(data.doctype); + var doc = new controller_class(data); + } + 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) { + +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +const frappe = __webpack_require__(0); + +class Document { + constructor(data) { + this.handlers = {}; + this.setup(); + Object.assign(this, data); + } + + setup() { + // add handlers + } + + add_handler(key, method) { + if (!this.handlers[key]) { + this.handlers[key] = []; + } + this.handlers[key].push(method || key); + } + + get(key) { + return this[key]; + } + + set(key, value) { + this.validate_field(key, value); + this[key] = 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); + } + } + + 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); + } + } + + validate_field (key, value) { + let df = this.meta.get_field(key); + if (df.fieldtype=='Select') { + this.meta.validate_select(df, 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() { + Object.assign(this, await frappe.db.get(this.doctype, this.name)); + } + + async insert() { + this.set_name(); + this.set_standard_values(); + await this.trigger('validate', 'before_insert'); + await frappe.db.insert(this.doctype, this.get_valid_dict()); + await this.trigger('after_insert', 'after_save'); + } + + async delete() { + await this.trigger('before_delete'); + await frappe.db.delete(this.doctype, this.name); + await this.trigger('after_delete'); + } + + async trigger() { + for(var key of arguments) { + if (this.handlers[key]) { + for (let method of this.handlers[key]) { + if (typeof method === 'string') { + await this[method](); + } else { + await method(this); + } + } + } + } + } + + async update() { + this.set_standard_values(); + await this.trigger('validate', 'before_update'); + await frappe.db.update(this.doctype, this.get_valid_dict()); + await this.trigger('after_update', 'after_save'); + return this; + } +}; + +module.exports = { Document: Document }; + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +__webpack_require__(4); +window.$ = __webpack_require__(9); + +const common = __webpack_require__(10); +const Database = __webpack_require__(16).Database + +window.frappe = __webpack_require__(0); +const listview = __webpack_require__(18); + +async function start() { + frappe.init(); + common.init_libs(frappe); + + frappe.db = await new Database({ + server: 'localhost:8000', + fetch: window.fetch.bind() + }); + + const todo = __webpack_require__(19); + frappe.init_controller('todo', todo); + + frappe.init_view({container: $('.container')}); +} + +start().then(() => { + let todo_list = new listview.ListView({ + doctype: 'ToDo', + parent: frappe.main + }); + todo_list.render(); +}) + + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +// style-loader: Adds some css to the DOM by adding a