This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
add new entity
LeonZhou edited this page Dec 9, 2015
·
2 revisions
So far adding new entities cause a bit of pain, be patient, better tool is coming soon!
Follow the steps, you can get a new table with awesome features provided by the CWA both in font-end & back-end, then you can bulit you own business logic based on them.
Take ‘computer’ table in demo as an example.
CREATE TABLE `computer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL COMMENT 'importable=1\nexportable=1\nchart-label=1',
`price` decimal(12,2) NOT NULL COMMENT 'importable=1\nexportable=1\nchart-value=1',
`image` int(11) DEFAULT NULL COMMENT 'type-name=image\nhidden-in-grid=1',
`status` varchar(12) DEFAULT NULL COMMENT 'type-name=enum\nenum-group=computer',
`remark` varchar(1024) DEFAULT NULL COMMENT 'type-name=textarea\nhidden-in-grid=1\nimportable=1\nexportable=1',
`creator_id` int(11) DEFAULT NULL COMMENT 'reserved=1\ntype-name=select\nlookup-table=user\nlookup-label=username',
`created_at` datetime DEFAULT NULL COMMENT 'reserved=1',
`updated_at` datetime DEFAULT NULL COMMENT 'reserved=1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8
(defent computer
(k/belongs-to user {:fk :creator_id}))
insert-res-for-entity
insert-res-to-role
(ns clojure-web.routes.computer
(:require [clojure-web.common.routes-helper :refer [defcrud-routes]]
[clojure-web.db.entity :refer [computer]]
[clojure-web.render :as render]))
(defcrud-routes computer-routes computer)
(defapi app-routes
computer-routes
;; omit other routers
)))
register handlers for new entity in handlers.cljs
(def entities ["computer"
;;;omit other tables
])
(ns clojure-web.computer
(:require [clojure-web.components.bs-table :refer [create-bs-table]]))
(def computer-panel (create-bs-table "computer"))
add the new table to menu
(def panels {"computers" computer-panel
;;; omit other panels
})