diff --git a/en/_sidebar.md b/en/_sidebar.md index a4bacba..19f977e 100644 --- a/en/_sidebar.md +++ b/en/_sidebar.md @@ -2,20 +2,39 @@ * [Get Ready](install) -* [Quick Start](init-project) +* [Quick Start](quick_start) * Plugins * [How To Use Plugins](plugins/plugins) * [How To Use Admin Plugin](plugins/admin) +* Admin Plugins + + * Data Table + * [Basic Usage](admin/table/basic) + * [Column Usage](admin/table/column_usage) + * Data Form + * [Basic Usage](admin/form/basic) + * [Form Components](admin/form/components) + * [Menus](admin/menus) + * [Permissions](admin/rbac) + * [File Upload](admin/file) + * [Cli](admin/cli) + * Pages * [Page Modules](pages/modules) - * [Customize your page](pages/pages) + * [Customize Your Page](pages/pages) + * [Customize Login Page](pages/login) + +* Architecture + + * [Introduction](architecture/introduction) * Development + * [Code Style](development/code_style) * [Adapter Development](development/adapter) * [Plugins Development](development/plugins) * Template Development @@ -24,6 +43,4 @@ * [Form Development](development/template/form) * [Components](development/template/components) -* [Menus](menu) - -* [Permissions](rbac) \ No newline at end of file +* [Plan](plan) \ No newline at end of file diff --git a/en/admin/cli.md b/en/admin/cli.md new file mode 100644 index 0000000..c00ad7a --- /dev/null +++ b/en/admin/cli.md @@ -0,0 +1,43 @@ +# Cli Introduction +--- + +GoAdmin provides a command line tool to increase development efficiency and streamline the development process. + +## Install + + +Download the binary of the corresponding system: + +| File name | OS | Arch | Size | +| ---- | ---- | ---- |---- | +| [admincli_darwin_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_darwin_x86_64_v1.0.1.zip) | macOs | x86-64 | 4.77 MB +| [admincli_linux_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_x86_64_v1.0.1.zip) | Linux | x86-64 | 6.52 MB +| [admincli_linux_armel_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_armel_v1.0.1.zip) | Linux | x86 | 6.06 MB +| [admincli_windows_i386_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_i386_v1.0.1.zip) | Windows | x86 |6.16 MB +| [admincli_windows_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_x86_64_v1.0.1.zip) | Windows | x86-64 |6.38 MB + + +Or use the command to install: + +``` +go install github.com/GoAdminGroup/go-admin/admincli +``` + +## Usage + +Use + +``` +admincli --help +``` + +Will list help information. + +| Command | Subcommand | Options | Function | +| ---- | ---- | ---- | ---- | +| generate | - | - | generate a data model file. +| compile | asset| **-s, --src** front-end resource folder path
**-o, --out** output go file path | compile all resource files into one single go file. +| compile | tpl | **-s, --src** the input golang tmpl template folder path
**-o, --out** output go file path | compile all template files into one single go file. +| combine | css| **-s, --src** the input css folder path
**-o, --out** the output css file path | combine the css files into one single css file. +| combine | js | **-s, --src** the input js folder path
**-o, --out** the output js file path | combine the js files into one single js file. +| develop | tpl | **-m, --module** golang module name or path under $GOPATH
**-n, --name** theme name | fetch remotely theme development templates to local. diff --git a/en/admin/file.md b/en/admin/file.md new file mode 100644 index 0000000..84e5373 --- /dev/null +++ b/en/admin/file.md @@ -0,0 +1,118 @@ +# File Upload Engine +--- + +By default, GoAdmin provides a local file upload engine that supports uploading files to the server. Use the directory that needs to be set up in the global configuration and the prefix for uploading file access. + +```go +package config + +// Storage directory: store avatar and other uploaded files +type Store struct { + Path string // relative or absolute path, the file will be stored here + Prefix string // access url prefix +} + +type Config struct { + + ... + + // Upload file storage location + Store Store `json:"store"` + + // File upload engine + FileUploadEngine FileUploadEngine `json:"file_upload_engine"` + + ... +} + +type FileUploadEngine struct { + Name string + Config map[string]interface{} +} +``` + +If you want to customize the upload location, such as uploading to cloud, aws cloud and other cloud platforms, then you need to write an upload engine yourself. Here's how to write your own engine: + +### Type of engine + +```go +package file + +type Uploader interface { + Upload(*multipart.Form) error +} + +type UploaderGenerator func() Uploader + +func AddUploader(name string, up UploaderGenerator) { + ... +} +``` + +### How to + +We need to call the **AddUploader** method to add an upload engine. The first parameter is the name of the engine (which will be used in the global configuration) and the second parameter is the engine generation function. + +Suppose we want to add a aws cloud upload engine, then it can be similar like this: + +```go +package main + +import ( + ... + "github.com/GoAdminGroup/go-admin/modules/file" + ... +) + +type AwsUploader struct { + Bucket string + Region string + SecretId string + SecretKey string + + Prefix string + Path string +} + +func (q AwsUploader) Upload(*multipart.Form) error { + // 接收一个表单类型,这里实现上传逻辑 +} + +func main() { + + ... + + file.AddUploader("aws", func() file.Uploader { + return &AwsUploader{ + Bucket: config.Get().FileUploadEngine.Config["bucket"].(string), + Region: config.Get().FileUploadEngine.Config["region"].(string), + SecretId: config.Get().FileUploadEngine.Config["secret_id"].(string), + SecretKey: config.Get().FileUploadEngine.Config["secret_key"].(string), + Prefix: config.Get().FileUploadEngine.Config["prefix"].(string), + Path: config.Get().FileUploadEngine.Config["path"].(string), + } + }) + + cfg := config.Config{ + ... + + FileUploadEngine: config.FileUploadEngine{ + Name: "aws", + Config: map[string]interface{}{ + "bucket": "xxx", + "region": "xxx", + "secret_id": "xxx", + "secret_key": "xxx", + "prefix": "xxx", + "path": "xxx", + }, + } + + ... + } + + ... +} +``` + +Finish a aws cloud upload file engine!🍺🍺 \ No newline at end of file diff --git a/en/admin/form/basic.md b/en/admin/form/basic.md new file mode 100644 index 0000000..6d9cbc0 --- /dev/null +++ b/en/admin/form/basic.md @@ -0,0 +1,74 @@ +# Basic Usage +--- + +Use the cli to generate a data form type for the sql table, such as: + +```sql +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `gender` tinyint(4) DEFAULT NULL, + `city` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ip` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` + +Generated: + +```go +package datamodel + +import ( + ... +) + +func GetUserTable() (userTable table.Table) { + + // config the table model. + userTable = table.NewDefaultTable(...) + + ... + + formList := userTable.GetForm() + + // set id editable is false. + formList.AddField("ID", "id", db.Int, form.Default).FieldNotAllowEdit() + formList.AddField("Ip", "ip", db.Varchar, form.Text) + formList.AddField("Name", "name", db.Varchar, form.Text) + + ... + + return +} +``` + +### Add Fields + +```go + +// Add a field with the field title ID, field name id, field type int, form type Default +formList.AddField("ID", "id", db.Int, form.Default) + +// Add a second field with the field title Ip, the field name ip, the field type varchar, and the form type Text +formList.AddField("Ip", "ip", db.Varchar, form.Text) + +// Add a third field, a field that does not exist in the sql table +formList.AddField("Custom", "custom", db.Varchar, form.Text) + +``` + +### Prohibit editing + +```go + +``` + +### No new additions + +```go + +``` \ No newline at end of file diff --git a/en/admin/form/components.md b/en/admin/form/components.md new file mode 100644 index 0000000..62cda91 --- /dev/null +++ b/en/admin/form/components.md @@ -0,0 +1,111 @@ +# Usage Of Form Components +--- + +## Default + +```go +// usage +``` + +## Text + +```go +// usage +``` + +## SelectSingle + +```go +// usage +``` + +## Select + +```go +// usage +``` + +## IconPicker + +```go +// usage +``` + +## SelectBox + +```go +// usage +``` + +## File + +```go +// usage +``` + +## Password + +```go +// usage +``` + +## RichText + +```go +// usage +``` + +## Datetime + +```go +// usage +``` + +## Radio + +```go +// usage +``` + +## Email + +```go +// usage +``` + +## Url + +```go +// usage +``` + +## Ip + +```go +// usage +``` + +## Color + +```go +// usage +``` + +## Currency + +```go +// usage +``` + +## Number + +```go +// usage +``` + +## TextArea + +```go +// usage +``` + diff --git a/en/admin/menus.md b/en/admin/menus.md new file mode 100644 index 0000000..b441c88 --- /dev/null +++ b/en/admin/menus.md @@ -0,0 +1,8 @@ +# Setting menu +--- + +GoAdmin has built-in menu management module. After entering the home page as a super administrator, expand the management of the left sidebar, there is a management panel below: + +![rbac](http://quick.go-admin.cn/docs/menus.png) + +Click inside to set up the menu you need. \ No newline at end of file diff --git a/en/admin/rbac.md b/en/admin/rbac.md new file mode 100644 index 0000000..8c4d8f6 --- /dev/null +++ b/en/admin/rbac.md @@ -0,0 +1,6 @@ +# Authority management +--- + +GoAdmin has built in [RBAC] (https://www.google.com/search?oq=rbac) permission control module. After entering the home page as a super administrator, expand the management of the left sidebar. There are three management panels for users, roles, and permissions: + +![rbac](http://quick.go-admin.cn/docs/rbac.png) \ No newline at end of file diff --git a/en/admin/table/basic.md b/en/admin/table/basic.md new file mode 100644 index 0000000..57d9d48 --- /dev/null +++ b/en/admin/table/basic.md @@ -0,0 +1,140 @@ +# Basic Usage +--- + +Use the command line to generate a data table type for the sql table, such as: + +```sql +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `gender` tinyint(4) DEFAULT NULL, + `city` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ip` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` + +Generated: + +```go +package datamodel + +import ( + ... +) + +func GetUserTable() (userTable table.Table) { + + // config the table model. + userTable = table.NewDefaultTable(table.Config{...}) + + info := userTable.GetInfo() + + // set id sortable. + info.AddField("ID", "id", db.Int).FieldSortable(true) + info.AddField("Name", "name", db.Varchar) + + ... + + // set the title and description of table page. + info.SetTable("users").SetTitle("Users").SetDescription("Users"). + SetAction(template.HTML(``)) // custom operation button + + ... +} +``` + +### Add Field + +```go + +// Add a field with the field title ID, field name id, field type int +info.AddField("ID", "id", db.Int) + +// Add the second field, the field title is Name, the field name is name, and the field type is varchar +info.AddField("Name", "name", db.Varchar) + +// Add a third field, a field that does not exist in the sql table +info.AddField("Custom", "custom", db.Varchar) + +``` + +### Modify display output + +```go + +// Output the corresponding content according to the value of the field +info.AddField("Gender", "gender", db.Tinyint).FieldDisplay(func(model types.FieldModel) interface{} { + if model.Value == "0" { + return "men" + } + if model.Value == "1" { + return "women" + } + return "unknown" +}) + +// Output html +info.AddField("Name", "name", db.Varchar).FieldDisplay(func(model types.FieldModel) interface{} { + return "" + model.Value + "" +}) +``` + +The anonymous function received by the **FieldDisplay** method binds the data object of the current row, and can call other field data of the current row in it. + +```go +info.AddField("First Name", "first_name", db.Varchar).FieldHide() +info.AddField("Last Name", "last_name", db.Varchar).FieldHide() + +// non-existing field columns +info.AddField("Full Name", "full_name", db.Varchar).FieldDisplay(func(model types.FieldModel) interface{} { + return model.Row["first_name"].(string) + " " + model.Row["last_name"].(string) +}) +``` + +### Hide create button + +```go +info.HideNewButton() +``` + +### Hide edit button + +```go +info.HideEditButton() +``` + +### Hide export button + +```go +info.HideExportButton() +``` + +### Hide delete button + +```go +info.HideDeleteButton() +``` + +## Join Table + +The table needs to set the table name and the table field + +```go + +info.AddField("Role Name", "role_name", db.Varchar).FieldJoin(types.Join{ + Table: "role", // table name which you want to join + Field: "id", // table field name of your own + JoinField: "user_id", // table field name of the table which you want to join +}) + +``` + +It will generate a sql statement like this: + +```sql +select ..., role.`role_name` from users left join role on users.`id` = role.`user_id` where ... +``` \ No newline at end of file diff --git a/en/admin/table/column_usage.md b/en/admin/table/column_usage.md new file mode 100644 index 0000000..11f6e24 --- /dev/null +++ b/en/admin/table/column_usage.md @@ -0,0 +1,74 @@ +# Usage Of Column +--- + +**InfoPanel** has a lot of built-in operation methods for columns, which can be used to manipulate column data very flexibly. + +### Set Width + +```go +info.AddField("Name", "name", db.Varchar).FieldWidth(100) +``` + +### Hide + +```go +info.AddField("Name", "name", db.Varchar).FieldHide() +``` + +### Be Sortable + +```go +info.AddField("Name", "name", db.Varchar).FieldSortable() +``` + +### Be Fixed + +```go +info.AddField("Name", "name", db.Varchar).FieldFixed() +``` + +### Be Filterable + +```go +info.AddField("Name", "name", db.Varchar).FieldFilterable() +``` + +## Help Methods + +### String manipulation + +Limit the output length + +```go +info.AddField("Name", "name", db.Varchar).FieldLimit(10) +``` + +Title + +```go +info.AddField("Name", "name", db.Varchar).FieldToTitle() +``` + +Trim space + +```go +info.AddField("Name", "name", db.Varchar).FieldTrimSpace() +``` + +String interception + +```go +info.AddField("Name", "name", db.Varchar).FieldSubstr(0, 3) +``` + +String to uppercase + +```go +info.AddField("Name", "name", db.Varchar).FieldToUpper() +``` + +String to lowercase + +```go +info.AddField("Name", "name", db.Varchar).FieldToLower() +``` \ No newline at end of file diff --git a/en/architecture/introduction.md b/en/architecture/introduction.md new file mode 100644 index 0000000..8beda42 --- /dev/null +++ b/en/architecture/introduction.md @@ -0,0 +1,20 @@ +# Introduction +--- + +The GoAdmin project module is as follows: + +| Name | Function | Path | +| ---- | ---- | ---- | +| engine | Engine is the core module of GoAdmin. The function of this module is to use the web framework adapter to inject the mapping between the plugin's routing and controller methods into the framework. | ./engine/engine.go +| adapter | The function of the adapter is to realize the mutual conversion between the context of the web framework and the context of GoAdmin. | ./adapter/adapter.go +| context | Context is the context of a request, the record includes the routing parameters and method information of the request, the context will be passed to the method of the plugin | ./context/context.go +| plugin | Each plugin has its own routing and controller method. After receiving the context converted by the adapter, it is processed by the controller method and returned to the adapter and then output to the web framework. | ./plugins/plugins.go +| template | Template is the golang materialization corresponding to the front-end code, and the component parts corresponding to the front-end code, such as forms, rows, columns, etc., are instantiated as an interface of golang, so the html code of the component can be obtained by calling the interface method, and this function is provided to Plugin to call | ./template/template.go +| auth | Auth implements the management of cookies, stores and converts the front-end cookie to the logged-in user, and implements the interception of the privilege. | ./modules/auth/auth.go +| config | Config is the global configuration of the system | ./modules/config/config.go +| db | db is a sql connection library, connected to the sql database to provide query and other help methods, support for multiple drivers | ./modules/db/connection.go +| language | Language implements a simple language mapping to support language localization | ./modules/language/language.go +| file | File implements a file upload engine | ./modules/file/file.go +| logger | The logger is the log module of the project | ./modules/logger/logger.go +| menu | Menu is the management of the project menu | ./modules/menu/menu.go +| cli | Cli command line module, including some basic commands for generating files and development | ./admincli/cli.go \ No newline at end of file diff --git a/en/development/adapter.md b/en/development/adapter.md index eaf6636..4301e00 100644 --- a/en/development/adapter.md +++ b/en/development/adapter.md @@ -1,2 +1,58 @@ # Adapter Development ---- \ No newline at end of file +--- + +The role of the adapter is to achieve the conversion of the web framework context and GoAdmin's own context. +To make a Adapter, you need implemente three methods: + +```go +package adapter + +import ( + "github.com/GoAdminGroup/go-admin/plugins" + "github.com/GoAdminGroup/go-admin/template/types" +) + +// WebFrameWork is a interface which is used as an adapter of +// framework and goAdmin. It must implement two methods. Use registers +// the routes and the corresponding handlers. Content writes the +// response to the corresponding context of framework. +type WebFrameWork interface { + Use(interface{}, []plugins.Plugin) error + Content(interface{}, types.GetPanel) +} +``` + +In addition to ```Use``` and ```Content```, you need to implement ```init``` + +## Use + +**Use** receives two parameters, the first parameter type is **interface{}**, which is the context of the web framework, and the second parameter is the plugin array. The return value is a **error**. +The role of **Use** is to use the incoming plugin array to associate the routing of the web framework with the controller methods in the plugin array to implement the correspondence between the web framework and the GoAdmin plugin method. For example, in the plugin example: + +```go +"/admin/example" => ShowExample(ctx *context.Context) +``` + +After processing by ```Use```, it will be injected into the web framework. + +## Content + +The **Content** method takes two arguments, the first argument type is **interface{}**, which is the context of the web framework, and the second argument is the **types.GetPanel** type. + +As follow: + +```go +type GetPanel func(ctx interface{}) (Panel, error) +``` + +The role of **Content** is to pass the web framework's context when customizing the page, and then write the return of the custom page content to the web framework's context. + +## init + +The **init** method injects the adapter into the engine so it can be used by others. + +```go +func init() { + engine.Register(new(Beego)) +} +``` \ No newline at end of file diff --git a/en/development/code_style.md b/en/development/code_style.md new file mode 100644 index 0000000..bb81769 --- /dev/null +++ b/en/development/code_style.md @@ -0,0 +1,6 @@ +# Code Style +--- + +``` +make lint +``` \ No newline at end of file diff --git a/en/pages/login.md b/en/pages/login.md new file mode 100644 index 0000000..dff77c0 --- /dev/null +++ b/en/pages/login.md @@ -0,0 +1,50 @@ +# 更改登录界面 +--- + +通过组件的方式可以修改登录界面,如下例子: + +更多登录界面组件[看这里](https://github.com/GoAdminGroup/components/blob/master/login/README.md);加载后引入即可。 + +```go +package main + +import ( + "github.com/GoAdminGroup/demo/ecommerce" + "github.com/GoAdminGroup/demo/login" + "github.com/GoAdminGroup/demo/pages" + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/examples/datamodel" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/plugins/example" + "github.com/GoAdminGroup/go-admin/template" + "github.com/GoAdminGroup/go-admin/template/types" + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + eng := engine.Default() + + adminPlugin := admin.NewAdmin(datamodel.Generators) + adminPlugin.AddGenerator("user", datamodel.GetUserTable) + + // 增加登录组件 + template.AddLoginComp(login.GetLoginComponent()) + + // you can custom a plugin like: + + examplePlugin := example.NewExample() + + rootPath := "/data/www/go-admin" + + if err := eng.AddConfigFromJson(rootPath+"/config.json").AddPlugins(adminPlugin, examplePlugin).Use(r); err != nil { + panic(err) + } + + r.Static("/uploads", rootPath+"/uploads") + + _ = r.Run(":9033") +} +``` diff --git a/en/plan.md b/en/plan.md new file mode 100644 index 0000000..b90d467 --- /dev/null +++ b/en/plan.md @@ -0,0 +1,62 @@ +# 发展计划 +--- + +GoAdmin的定位不只是一个管理后台中心构建框架,目前在1.0基础版本已经实现了一个能快速构建简单的crud以及有权限管理功能的管理后台的基础构建框架。在此基础上,可以对主题以及插件等进行一定程度的定制。以下分三点阐述这个项目以后的发展计划: + +## 项目功能规划 + +GoAdmin的目标是实现无代码化或某种程度的无代码化可视化操作,内置插件会至少包括:简单与复杂商业化crud管理中心极速构建,支持多数据源的监控体系的搭建等等。以下是对版本的初步规划: + +### 1.0.0 版本 + +- 实现基础的框架,同时提供一个内置插件能够满足快速构建crud管理后台。 +- 这个基础框架可以实现前端主题的自由定制,以及对插件的加载。 + +### 2.0.0 版本 + +- 在 1.0 版本的基础上,此版本将完善内置插件的功能,基本达到商业化水平(能够提供一个ec商城后台/saas系统的所有功能) +- 完善主题和插件的开发工具链,使得非项目开发人员都能够轻松的上手主题与插件的开发 +- 提供更多样化的内置主题与内置插件 +- 监控体系的初步支持(实时监控系统,数据前端展示,定制数据源) +- 项目性能的评估与优化 + +### 3.0.0 版本 + +- 可生产环境商业化的监控体系支持 +- 初步实现界面数据化以及实现一个界面拖拽定制框架 + +### 4.0.0 版本 + +- 实现无代码化的界面拖拽框架 + +## 人才社区构建 + +GoAdmin项目需要更多的人才一同加入。 + +目前由我 [@cg33](https://github.com/chenhg5) 一人维护此项目,本人是国内某知名985/211大学计算机系本科毕业,两年的gopher。 + +目前项目需要的工作有: + +- [项目开发](https://github.com/GoAdminGroup/go-admin),需掌握一定的```golang```开发能力 +- 社区项目开发(暂未开源,暂不对外开放) +- [文档的维护改进与翻译](https://github.com/GoAdminGroup/docs) +- 项目的宣传与社区文化的组织 + +GoAdmin始终秉持开放开源的态度,欢迎有志有能力之士加入一块共谋项目和社区的发展,社区与个人相辅相成。 + +如果你看好GoAdmin的发展,并且愿意为他赌一把,用时间换取未来可能的财务或名誉度回报,而且你对你自己的能力有足够信心,那么你可以尝试充分阅读GoAdmin的代码,并理解GoAdmin的发展规划,为此做出你的贡献。前期代码缺陷漏洞大,可修改空间多,如果你有能力做出足够的贡献,将成为项目的**联合创始人**或**核心开发者**。到后期,代码完善度高,也仍然有改进空间,你可以通过提交修复成为**贡献者**。团队将会一直保持开放态度,接纳新成员。团队每一个付出努力的成员也会在将来根据付出比例公平地去收获项目给大家带来的一定的回报。 + +如果你没有足够的时间和精力,但有一定的资金,且同样看好GoAdmin发展,虽然GoAdmin尚未就此加入的方案拟定计划。但只要你有足够大的兴趣,也可以带上你的计划与我们进行洽谈。 + +## 商业项目计划 + +GoAdmin会逐步实现商业化,但核心基础功能是免费开源的。 +GoAdmin的资金收入模式主要是: + +- 接受捐助 +- 售卖主题 +- 售卖插件 +- 提供saas定制化开发 +- 提供收费的商业化版本 + +收入资金主要用于维护社区的发展,与开发人员的薪酬回报,促使项目更好的成长。 \ No newline at end of file diff --git a/en/init-project.md b/en/quick_start.md similarity index 100% rename from en/init-project.md rename to en/quick_start.md diff --git a/fr/README.md b/fr/README.md new file mode 100644 index 0000000..647f035 --- /dev/null +++ b/fr/README.md @@ -0,0 +1,44 @@ +# Introduction +------ + +GoAdmin is a data visualization management platform, providing a complete set of visual ui calls to golang programs, and a built-in sql relational database management backend plugin. +
+
+Before we build a management backend, we needed at least one back office engineer, a front-end engineer, to take at least a week. +Now with GoAdmin, we don't need front-end engineers. Our back-end engineers don't even need to know the front-end knowledge. We can build a complete back-end management system in half an hour. +If your requirements are not complicated, just simple crud, then all you need are serveral golang files, and all files can be packaged into a single binary file, which is very convenient for distribution and deployment. + +here is very simple example which show you how it work: [https://github.com/GoAdminGroup/example](https://github.com/GoAdminGroup/example) + + +## Features + +- Build-in RBAC Access Authentication System +- Support most web framework +- Support plug-ins(working on it) +- Provided different ui theme(only Adminlte now, others are coming soon.) + +## Demo + +[http://demo.go-admin.cn/admin](http://demo.go-admin.cn/admin) + +## Dependencies + +- [Datetimepicker](http://eonasdan.github.io/bootstrap-datetimepicker/) +- [font-awesome](http://fontawesome.io/) +- [bootstrap-fileinput](https://github.com/kartik-v/bootstrap-fileinput) +- [jquery-pjax](https://github.com/defunkt/jquery-pjax) +- [Nestable](http://dbushell.github.io/Nestable/) +- [toastr](http://codeseven.github.io/toastr/) +- [bootstrap-number-input](https://github.com/wpic/bootstrap-number-input) +- [fontawesome-iconpicker](https://github.com/itsjavi/fontawesome-iconpicker) + +## Community + +[Community](http://forum.go-admin.cn) + +## Backers + +Your support will help me do better! + + \ No newline at end of file diff --git a/fr/_sidebar.md b/fr/_sidebar.md new file mode 100644 index 0000000..19f977e --- /dev/null +++ b/fr/_sidebar.md @@ -0,0 +1,46 @@ +* [Introducation](README) + +* [Get Ready](install) + +* [Quick Start](quick_start) + +* Plugins + + * [How To Use Plugins](plugins/plugins) + * [How To Use Admin Plugin](plugins/admin) + +* Admin Plugins + + * Data Table + * [Basic Usage](admin/table/basic) + * [Column Usage](admin/table/column_usage) + * Data Form + * [Basic Usage](admin/form/basic) + * [Form Components](admin/form/components) + * [Menus](admin/menus) + * [Permissions](admin/rbac) + * [File Upload](admin/file) + * [Cli](admin/cli) + +* Pages + + * [Page Modules](pages/modules) + * [Customize Your Page](pages/pages) + * [Customize Login Page](pages/login) + +* Architecture + + * [Introduction](architecture/introduction) + +* Development + + * [Code Style](development/code_style) + * [Adapter Development](development/adapter) + * [Plugins Development](development/plugins) + * Template Development + + * [Template Introducation](development/template/template) + * [Form Development](development/template/form) + * [Components](development/template/components) + +* [Plan](plan) \ No newline at end of file diff --git a/fr/admin/cli.md b/fr/admin/cli.md new file mode 100644 index 0000000..c00ad7a --- /dev/null +++ b/fr/admin/cli.md @@ -0,0 +1,43 @@ +# Cli Introduction +--- + +GoAdmin provides a command line tool to increase development efficiency and streamline the development process. + +## Install + + +Download the binary of the corresponding system: + +| File name | OS | Arch | Size | +| ---- | ---- | ---- |---- | +| [admincli_darwin_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_darwin_x86_64_v1.0.1.zip) | macOs | x86-64 | 4.77 MB +| [admincli_linux_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_x86_64_v1.0.1.zip) | Linux | x86-64 | 6.52 MB +| [admincli_linux_armel_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_armel_v1.0.1.zip) | Linux | x86 | 6.06 MB +| [admincli_windows_i386_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_i386_v1.0.1.zip) | Windows | x86 |6.16 MB +| [admincli_windows_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_x86_64_v1.0.1.zip) | Windows | x86-64 |6.38 MB + + +Or use the command to install: + +``` +go install github.com/GoAdminGroup/go-admin/admincli +``` + +## Usage + +Use + +``` +admincli --help +``` + +Will list help information. + +| Command | Subcommand | Options | Function | +| ---- | ---- | ---- | ---- | +| generate | - | - | generate a data model file. +| compile | asset| **-s, --src** front-end resource folder path
**-o, --out** output go file path | compile all resource files into one single go file. +| compile | tpl | **-s, --src** the input golang tmpl template folder path
**-o, --out** output go file path | compile all template files into one single go file. +| combine | css| **-s, --src** the input css folder path
**-o, --out** the output css file path | combine the css files into one single css file. +| combine | js | **-s, --src** the input js folder path
**-o, --out** the output js file path | combine the js files into one single js file. +| develop | tpl | **-m, --module** golang module name or path under $GOPATH
**-n, --name** theme name | fetch remotely theme development templates to local. diff --git a/fr/admin/file.md b/fr/admin/file.md new file mode 100644 index 0000000..84e5373 --- /dev/null +++ b/fr/admin/file.md @@ -0,0 +1,118 @@ +# File Upload Engine +--- + +By default, GoAdmin provides a local file upload engine that supports uploading files to the server. Use the directory that needs to be set up in the global configuration and the prefix for uploading file access. + +```go +package config + +// Storage directory: store avatar and other uploaded files +type Store struct { + Path string // relative or absolute path, the file will be stored here + Prefix string // access url prefix +} + +type Config struct { + + ... + + // Upload file storage location + Store Store `json:"store"` + + // File upload engine + FileUploadEngine FileUploadEngine `json:"file_upload_engine"` + + ... +} + +type FileUploadEngine struct { + Name string + Config map[string]interface{} +} +``` + +If you want to customize the upload location, such as uploading to cloud, aws cloud and other cloud platforms, then you need to write an upload engine yourself. Here's how to write your own engine: + +### Type of engine + +```go +package file + +type Uploader interface { + Upload(*multipart.Form) error +} + +type UploaderGenerator func() Uploader + +func AddUploader(name string, up UploaderGenerator) { + ... +} +``` + +### How to + +We need to call the **AddUploader** method to add an upload engine. The first parameter is the name of the engine (which will be used in the global configuration) and the second parameter is the engine generation function. + +Suppose we want to add a aws cloud upload engine, then it can be similar like this: + +```go +package main + +import ( + ... + "github.com/GoAdminGroup/go-admin/modules/file" + ... +) + +type AwsUploader struct { + Bucket string + Region string + SecretId string + SecretKey string + + Prefix string + Path string +} + +func (q AwsUploader) Upload(*multipart.Form) error { + // 接收一个表单类型,这里实现上传逻辑 +} + +func main() { + + ... + + file.AddUploader("aws", func() file.Uploader { + return &AwsUploader{ + Bucket: config.Get().FileUploadEngine.Config["bucket"].(string), + Region: config.Get().FileUploadEngine.Config["region"].(string), + SecretId: config.Get().FileUploadEngine.Config["secret_id"].(string), + SecretKey: config.Get().FileUploadEngine.Config["secret_key"].(string), + Prefix: config.Get().FileUploadEngine.Config["prefix"].(string), + Path: config.Get().FileUploadEngine.Config["path"].(string), + } + }) + + cfg := config.Config{ + ... + + FileUploadEngine: config.FileUploadEngine{ + Name: "aws", + Config: map[string]interface{}{ + "bucket": "xxx", + "region": "xxx", + "secret_id": "xxx", + "secret_key": "xxx", + "prefix": "xxx", + "path": "xxx", + }, + } + + ... + } + + ... +} +``` + +Finish a aws cloud upload file engine!🍺🍺 \ No newline at end of file diff --git a/fr/admin/form/basic.md b/fr/admin/form/basic.md new file mode 100644 index 0000000..6d9cbc0 --- /dev/null +++ b/fr/admin/form/basic.md @@ -0,0 +1,74 @@ +# Basic Usage +--- + +Use the cli to generate a data form type for the sql table, such as: + +```sql +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `gender` tinyint(4) DEFAULT NULL, + `city` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ip` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` + +Generated: + +```go +package datamodel + +import ( + ... +) + +func GetUserTable() (userTable table.Table) { + + // config the table model. + userTable = table.NewDefaultTable(...) + + ... + + formList := userTable.GetForm() + + // set id editable is false. + formList.AddField("ID", "id", db.Int, form.Default).FieldNotAllowEdit() + formList.AddField("Ip", "ip", db.Varchar, form.Text) + formList.AddField("Name", "name", db.Varchar, form.Text) + + ... + + return +} +``` + +### Add Fields + +```go + +// Add a field with the field title ID, field name id, field type int, form type Default +formList.AddField("ID", "id", db.Int, form.Default) + +// Add a second field with the field title Ip, the field name ip, the field type varchar, and the form type Text +formList.AddField("Ip", "ip", db.Varchar, form.Text) + +// Add a third field, a field that does not exist in the sql table +formList.AddField("Custom", "custom", db.Varchar, form.Text) + +``` + +### Prohibit editing + +```go + +``` + +### No new additions + +```go + +``` \ No newline at end of file diff --git a/fr/admin/form/components.md b/fr/admin/form/components.md new file mode 100644 index 0000000..62cda91 --- /dev/null +++ b/fr/admin/form/components.md @@ -0,0 +1,111 @@ +# Usage Of Form Components +--- + +## Default + +```go +// usage +``` + +## Text + +```go +// usage +``` + +## SelectSingle + +```go +// usage +``` + +## Select + +```go +// usage +``` + +## IconPicker + +```go +// usage +``` + +## SelectBox + +```go +// usage +``` + +## File + +```go +// usage +``` + +## Password + +```go +// usage +``` + +## RichText + +```go +// usage +``` + +## Datetime + +```go +// usage +``` + +## Radio + +```go +// usage +``` + +## Email + +```go +// usage +``` + +## Url + +```go +// usage +``` + +## Ip + +```go +// usage +``` + +## Color + +```go +// usage +``` + +## Currency + +```go +// usage +``` + +## Number + +```go +// usage +``` + +## TextArea + +```go +// usage +``` + diff --git a/fr/admin/menus.md b/fr/admin/menus.md new file mode 100644 index 0000000..b441c88 --- /dev/null +++ b/fr/admin/menus.md @@ -0,0 +1,8 @@ +# Setting menu +--- + +GoAdmin has built-in menu management module. After entering the home page as a super administrator, expand the management of the left sidebar, there is a management panel below: + +![rbac](http://quick.go-admin.cn/docs/menus.png) + +Click inside to set up the menu you need. \ No newline at end of file diff --git a/fr/admin/rbac.md b/fr/admin/rbac.md new file mode 100644 index 0000000..8c4d8f6 --- /dev/null +++ b/fr/admin/rbac.md @@ -0,0 +1,6 @@ +# Authority management +--- + +GoAdmin has built in [RBAC] (https://www.google.com/search?oq=rbac) permission control module. After entering the home page as a super administrator, expand the management of the left sidebar. There are three management panels for users, roles, and permissions: + +![rbac](http://quick.go-admin.cn/docs/rbac.png) \ No newline at end of file diff --git a/fr/admin/table/basic.md b/fr/admin/table/basic.md new file mode 100644 index 0000000..57d9d48 --- /dev/null +++ b/fr/admin/table/basic.md @@ -0,0 +1,140 @@ +# Basic Usage +--- + +Use the command line to generate a data table type for the sql table, such as: + +```sql +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `gender` tinyint(4) DEFAULT NULL, + `city` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ip` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` + +Generated: + +```go +package datamodel + +import ( + ... +) + +func GetUserTable() (userTable table.Table) { + + // config the table model. + userTable = table.NewDefaultTable(table.Config{...}) + + info := userTable.GetInfo() + + // set id sortable. + info.AddField("ID", "id", db.Int).FieldSortable(true) + info.AddField("Name", "name", db.Varchar) + + ... + + // set the title and description of table page. + info.SetTable("users").SetTitle("Users").SetDescription("Users"). + SetAction(template.HTML(``)) // custom operation button + + ... +} +``` + +### Add Field + +```go + +// Add a field with the field title ID, field name id, field type int +info.AddField("ID", "id", db.Int) + +// Add the second field, the field title is Name, the field name is name, and the field type is varchar +info.AddField("Name", "name", db.Varchar) + +// Add a third field, a field that does not exist in the sql table +info.AddField("Custom", "custom", db.Varchar) + +``` + +### Modify display output + +```go + +// Output the corresponding content according to the value of the field +info.AddField("Gender", "gender", db.Tinyint).FieldDisplay(func(model types.FieldModel) interface{} { + if model.Value == "0" { + return "men" + } + if model.Value == "1" { + return "women" + } + return "unknown" +}) + +// Output html +info.AddField("Name", "name", db.Varchar).FieldDisplay(func(model types.FieldModel) interface{} { + return "" + model.Value + "" +}) +``` + +The anonymous function received by the **FieldDisplay** method binds the data object of the current row, and can call other field data of the current row in it. + +```go +info.AddField("First Name", "first_name", db.Varchar).FieldHide() +info.AddField("Last Name", "last_name", db.Varchar).FieldHide() + +// non-existing field columns +info.AddField("Full Name", "full_name", db.Varchar).FieldDisplay(func(model types.FieldModel) interface{} { + return model.Row["first_name"].(string) + " " + model.Row["last_name"].(string) +}) +``` + +### Hide create button + +```go +info.HideNewButton() +``` + +### Hide edit button + +```go +info.HideEditButton() +``` + +### Hide export button + +```go +info.HideExportButton() +``` + +### Hide delete button + +```go +info.HideDeleteButton() +``` + +## Join Table + +The table needs to set the table name and the table field + +```go + +info.AddField("Role Name", "role_name", db.Varchar).FieldJoin(types.Join{ + Table: "role", // table name which you want to join + Field: "id", // table field name of your own + JoinField: "user_id", // table field name of the table which you want to join +}) + +``` + +It will generate a sql statement like this: + +```sql +select ..., role.`role_name` from users left join role on users.`id` = role.`user_id` where ... +``` \ No newline at end of file diff --git a/fr/admin/table/column_usage.md b/fr/admin/table/column_usage.md new file mode 100644 index 0000000..11f6e24 --- /dev/null +++ b/fr/admin/table/column_usage.md @@ -0,0 +1,74 @@ +# Usage Of Column +--- + +**InfoPanel** has a lot of built-in operation methods for columns, which can be used to manipulate column data very flexibly. + +### Set Width + +```go +info.AddField("Name", "name", db.Varchar).FieldWidth(100) +``` + +### Hide + +```go +info.AddField("Name", "name", db.Varchar).FieldHide() +``` + +### Be Sortable + +```go +info.AddField("Name", "name", db.Varchar).FieldSortable() +``` + +### Be Fixed + +```go +info.AddField("Name", "name", db.Varchar).FieldFixed() +``` + +### Be Filterable + +```go +info.AddField("Name", "name", db.Varchar).FieldFilterable() +``` + +## Help Methods + +### String manipulation + +Limit the output length + +```go +info.AddField("Name", "name", db.Varchar).FieldLimit(10) +``` + +Title + +```go +info.AddField("Name", "name", db.Varchar).FieldToTitle() +``` + +Trim space + +```go +info.AddField("Name", "name", db.Varchar).FieldTrimSpace() +``` + +String interception + +```go +info.AddField("Name", "name", db.Varchar).FieldSubstr(0, 3) +``` + +String to uppercase + +```go +info.AddField("Name", "name", db.Varchar).FieldToUpper() +``` + +String to lowercase + +```go +info.AddField("Name", "name", db.Varchar).FieldToLower() +``` \ No newline at end of file diff --git a/fr/architecture/introduction.md b/fr/architecture/introduction.md new file mode 100644 index 0000000..8beda42 --- /dev/null +++ b/fr/architecture/introduction.md @@ -0,0 +1,20 @@ +# Introduction +--- + +The GoAdmin project module is as follows: + +| Name | Function | Path | +| ---- | ---- | ---- | +| engine | Engine is the core module of GoAdmin. The function of this module is to use the web framework adapter to inject the mapping between the plugin's routing and controller methods into the framework. | ./engine/engine.go +| adapter | The function of the adapter is to realize the mutual conversion between the context of the web framework and the context of GoAdmin. | ./adapter/adapter.go +| context | Context is the context of a request, the record includes the routing parameters and method information of the request, the context will be passed to the method of the plugin | ./context/context.go +| plugin | Each plugin has its own routing and controller method. After receiving the context converted by the adapter, it is processed by the controller method and returned to the adapter and then output to the web framework. | ./plugins/plugins.go +| template | Template is the golang materialization corresponding to the front-end code, and the component parts corresponding to the front-end code, such as forms, rows, columns, etc., are instantiated as an interface of golang, so the html code of the component can be obtained by calling the interface method, and this function is provided to Plugin to call | ./template/template.go +| auth | Auth implements the management of cookies, stores and converts the front-end cookie to the logged-in user, and implements the interception of the privilege. | ./modules/auth/auth.go +| config | Config is the global configuration of the system | ./modules/config/config.go +| db | db is a sql connection library, connected to the sql database to provide query and other help methods, support for multiple drivers | ./modules/db/connection.go +| language | Language implements a simple language mapping to support language localization | ./modules/language/language.go +| file | File implements a file upload engine | ./modules/file/file.go +| logger | The logger is the log module of the project | ./modules/logger/logger.go +| menu | Menu is the management of the project menu | ./modules/menu/menu.go +| cli | Cli command line module, including some basic commands for generating files and development | ./admincli/cli.go \ No newline at end of file diff --git a/fr/development/adapter.md b/fr/development/adapter.md new file mode 100644 index 0000000..4301e00 --- /dev/null +++ b/fr/development/adapter.md @@ -0,0 +1,58 @@ +# Adapter Development +--- + +The role of the adapter is to achieve the conversion of the web framework context and GoAdmin's own context. +To make a Adapter, you need implemente three methods: + +```go +package adapter + +import ( + "github.com/GoAdminGroup/go-admin/plugins" + "github.com/GoAdminGroup/go-admin/template/types" +) + +// WebFrameWork is a interface which is used as an adapter of +// framework and goAdmin. It must implement two methods. Use registers +// the routes and the corresponding handlers. Content writes the +// response to the corresponding context of framework. +type WebFrameWork interface { + Use(interface{}, []plugins.Plugin) error + Content(interface{}, types.GetPanel) +} +``` + +In addition to ```Use``` and ```Content```, you need to implement ```init``` + +## Use + +**Use** receives two parameters, the first parameter type is **interface{}**, which is the context of the web framework, and the second parameter is the plugin array. The return value is a **error**. +The role of **Use** is to use the incoming plugin array to associate the routing of the web framework with the controller methods in the plugin array to implement the correspondence between the web framework and the GoAdmin plugin method. For example, in the plugin example: + +```go +"/admin/example" => ShowExample(ctx *context.Context) +``` + +After processing by ```Use```, it will be injected into the web framework. + +## Content + +The **Content** method takes two arguments, the first argument type is **interface{}**, which is the context of the web framework, and the second argument is the **types.GetPanel** type. + +As follow: + +```go +type GetPanel func(ctx interface{}) (Panel, error) +``` + +The role of **Content** is to pass the web framework's context when customizing the page, and then write the return of the custom page content to the web framework's context. + +## init + +The **init** method injects the adapter into the engine so it can be used by others. + +```go +func init() { + engine.Register(new(Beego)) +} +``` \ No newline at end of file diff --git a/fr/development/code_style.md b/fr/development/code_style.md new file mode 100644 index 0000000..bb81769 --- /dev/null +++ b/fr/development/code_style.md @@ -0,0 +1,6 @@ +# Code Style +--- + +``` +make lint +``` \ No newline at end of file diff --git a/fr/development/plugins.md b/fr/development/plugins.md new file mode 100644 index 0000000..8b0fec9 --- /dev/null +++ b/fr/development/plugins.md @@ -0,0 +1,7 @@ +# Plugins Development +--- + +Example:
+ +- [develop a plugin used by source code](https://github.com/GoAdminGroup/go-admin/blob/master/plugins/example/example.go) +- [develop a plugin used by golang plugin](https://github.com/GoAdminGroup/go-admin/blob/master/plugins/example/go_plugin/main.go) diff --git a/fr/development/template/components.md b/fr/development/template/components.md new file mode 100644 index 0000000..eb63087 --- /dev/null +++ b/fr/development/template/components.md @@ -0,0 +1,97 @@ +# Components Development +--- + +Component development, taking the image component as an example. + +## New types and methods of upper interface + +- Create a new ```ImgAttribute``` type + +```go +type ImgAttribute interface { + SetWidth(value string) ImgAttribute + SetHeight(value string) ImgAttribute + SetSrc(value string) ImgAttribute + GetContent() template.HTML +} +``` + +- In the ```Template``` interface, add a method: + +```go +type Template interface { + ... + Image() types.ImgAttribute + ... +} +``` + +## Specific implementation, with ```adminlte``` as an example + +- ```ImgAttribute``` + +Create a new ```image.go``` file under ```./template/adminlte/components```, as follows: + +```go +package components + +import ( + "github.com/GoAdminGroup/go-admin/template/types" + "html/template" +) + +type ImgAttribute struct { + Name string + Witdh string + Height string + Src string +} + +func (compo *ImgAttribute) SetWidth(value string) types.ImgAttribute { + compo.Witdh = value + return compo +} + +func (compo *ImgAttribute) SetHeight(value string) types.ImgAttribute { + compo.Height = value + return compo +} + +func (compo *ImgAttribute) SetSrc(value string) types.ImgAttribute { + compo.Src = value + return compo +} + +func (compo *ImgAttribute) GetContent() template.HTML { + return ComposeHtml(compo.TemplateList, *compo, "image") +} +``` + +- ```Image()``` + +In ```.template/adminlte/adminlte.go```, add a function: + +```go +func (*Theme) Image() types.ImgAttribute { + return &components.ImgAttribute{ + Name: "image", + Witdh: "50", + Height: "50", + Src: "", + } +} +``` + +Still not completed here, you need to add static resource files. + +- Add the static resource file + +Add ```image.tmpl``` file to ```.template/adminlte/resource/pages/components``` + +Annoying, and the last step + +- Execute in the root directory: + +```shell +admincli assets +``` \ No newline at end of file diff --git a/fr/development/template/form.md b/fr/development/template/form.md new file mode 100644 index 0000000..7323cb4 --- /dev/null +++ b/fr/development/template/form.md @@ -0,0 +1,2 @@ +# Form Development +--- \ No newline at end of file diff --git a/fr/development/template/template.md b/fr/development/template/template.md new file mode 100644 index 0000000..97c9160 --- /dev/null +++ b/fr/development/template/template.md @@ -0,0 +1,41 @@ +# Template Introducation +--- + +The theme template is an abstract representation of ui, including a collection of components and static resources that are called in the plugin. The type in go-admin is ```Template```, as follows: + +```go +type Template interface { + // Components + Form() types.FormAttribute + Box() types.BoxAttribute + Col() types.ColAttribute + Image() types.ImgAttribute + SmallBox() types.SmallBoxAttribute + Label() types.LabelAttribute + Row() types.RowAttribute + Table() types.TableAttribute + DataTable() types.DataTableAttribute + Tree() types.TreeAttribute + InfoBox() types.InfoBoxAttribute + Paginator() types.PaginatorAttribute + AreaChart() types.AreaChartAttribute + ProgressGroup() types.ProgressGroupAttribute + LineChart() types.LineChartAttribute + BarChart() types.BarChartAttribute + ProductList() types.ProductListAttribute + Description() types.DescriptionAttribute + Alert() types.AlertAttribute + PieChart() types.PieChartAttribute + ChartLegend() types.ChartLegendAttribute + Tabs() types.TabsAttribute + Popup() types.PopupAttribute + + // Builder methods + GetTmplList() map[string]string + GetAssetList() []string + GetAsset(string) ([]byte, error) + GetTemplate(bool) (*template.Template, string) +} +``` + +To develop a ui theme template, you need to implement the above ```Template``` interface. \ No newline at end of file diff --git a/fr/index.html b/fr/index.html new file mode 100644 index 0000000..c17f286 --- /dev/null +++ b/fr/index.html @@ -0,0 +1,46 @@ + + + + + GoAdmin Document + + + + + + +
+ + + + + + + + + + diff --git a/fr/install.md b/fr/install.md new file mode 100644 index 0000000..c4bbccc --- /dev/null +++ b/fr/install.md @@ -0,0 +1,41 @@ +# Get Ready +--- + +This program is based on ```golang```. It is recommended to use ```golang``` with version higher than 1.11. Please visit: [https://golang.org](https://golang.org) + +## Import the program required sql to the corresponding self-built database + +The contents of the sql file are the data tables required by the framework. Suppose your business database is: database_a; then you can import the framework sql into ```database_a```, or you can create another database ```database_b``` Import, can be a different driver database, for example, your business database is ```mysql```, the framework database is ```sqlite```. The framework currently supports multiple database connection operations. How to configure, will be described in detail later. + +- [mysql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.sql) +- [sqlite](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.db) +- [postgresql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.pgsql) + +## Install command line tools + +Download the binary excecute file: + +| File name | OS | Arch | Size | +| ---- | ---- | ---- |---- | +| [admincli_darwin_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_darwin_x86_64_v1.0.1.zip) | macOs | x86-64 | 4.77 MB +| [admincli_linux_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_x86_64_v1.0.1.zip) | Linux | x86-64 | 6.52 MB +| [admincli_linux_armel_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_linux_armel_v1.0.1.zip) | Linux | x86 | 6.06 MB +| [admincli_windows_i386_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_i386_v1.0.1.zip) | Windows | x86 |6.16 MB +| [admincli_windows_x86_64_v1.0.1.zip](http://file.go-admin.cn/go_admin/cli/v1_0_1/admincli_windows_x86_64_v1.0.1.zip) | Windows | x86-64 |6.38 MB + + +Or Use the command: + +``` +go install github.com/GoAdminGroup/go-admin/admincli +``` + +
+ +🍺🍺 Get ready to work here, next to the [Quick start](init-project) + +
+ +> English is not my main language. If any typo or wrong translation you found, you can help to translate in [github here](https://github.com/GoAdminGroup/docs). I will very appreciate it. + + diff --git a/fr/pages/components.md b/fr/pages/components.md new file mode 100644 index 0000000..a293caf --- /dev/null +++ b/fr/pages/components.md @@ -0,0 +1,2 @@ +# Components +---- \ No newline at end of file diff --git a/fr/pages/login.md b/fr/pages/login.md new file mode 100644 index 0000000..dff77c0 --- /dev/null +++ b/fr/pages/login.md @@ -0,0 +1,50 @@ +# 更改登录界面 +--- + +通过组件的方式可以修改登录界面,如下例子: + +更多登录界面组件[看这里](https://github.com/GoAdminGroup/components/blob/master/login/README.md);加载后引入即可。 + +```go +package main + +import ( + "github.com/GoAdminGroup/demo/ecommerce" + "github.com/GoAdminGroup/demo/login" + "github.com/GoAdminGroup/demo/pages" + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/examples/datamodel" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/plugins/example" + "github.com/GoAdminGroup/go-admin/template" + "github.com/GoAdminGroup/go-admin/template/types" + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + eng := engine.Default() + + adminPlugin := admin.NewAdmin(datamodel.Generators) + adminPlugin.AddGenerator("user", datamodel.GetUserTable) + + // 增加登录组件 + template.AddLoginComp(login.GetLoginComponent()) + + // you can custom a plugin like: + + examplePlugin := example.NewExample() + + rootPath := "/data/www/go-admin" + + if err := eng.AddConfigFromJson(rootPath+"/config.json").AddPlugins(adminPlugin, examplePlugin).Use(r); err != nil { + panic(err) + } + + r.Static("/uploads", rootPath+"/uploads") + + _ = r.Run(":9033") +} +``` diff --git a/fr/pages/modules.md b/fr/pages/modules.md new file mode 100644 index 0000000..80eb238 --- /dev/null +++ b/fr/pages/modules.md @@ -0,0 +1,80 @@ +# Page Modules +--- + +Page customization needs to call the engine's ```Content``` method, which needs to return an object ```types.Panel``` + +The following is the definition of ```types.Panel```: + +```go +type Panel struct { + Content template.HTML + Title string + Description string + Url string +} +``` + +Corresponding ui, you can see the following picture: + +![](http://quizfile.dadadaa.cn/everyday/app/jlds/img/006tNbRwly1fxoz5bm02oj31ek0u0wtz.jpg) + +## How to use + +```go +package datamodel + +import ( + "github.com/GoAdminGroup/go-admin/modules/config" + template2 "github.com/GoAdminGroup/go-admin/template" + "github.com/GoAdminGroup/go-admin/template/types" + "html/template" +) + +func GetContent() (types.Panel, error) { + + components := template2.Get(config.Get().THEME) + colComp := components.Col() + + infobox := components.InfoBox(). + SetText("CPU TRAFFIC"). + SetColor("blue"). + SetNumber("41,410"). + SetIcon("ion-ios-gear-outline"). + GetContent() + + var size = map[string]string{"md": "3", "sm": "6", "xs": "12"} + infoboxCol1 := colComp.SetSize(size).SetContent(infobox).GetContent() + row1 := components.Row().SetContent(infoboxCol1).GetContent() + + return types.Panel{ + Content: row1, + Title: "Dashboard", + Description: "this is a example", + }, nil +} +``` + +## Col + +A col is type of ```ColAttribute```, has three methods: + +```go +type ColAttribute interface { + SetSize(value map[string]string) ColAttribute + SetContent(value template.HTML) ColAttribute + GetContent() template.HTML +} +``` + +About the ```size```,example is ```map[string]string{"md": "3", "sm": "6", "xs": "12"}``` + +## Row + +A row is type of ```RowAttribute```, has two methods: + +```go +type RowAttribute interface { + SetContent(value template.HTML) RowAttribute + GetContent() template.HTML +} +``` diff --git a/fr/pages/pages.md b/fr/pages/pages.md new file mode 100644 index 0000000..66db8a0 --- /dev/null +++ b/fr/pages/pages.md @@ -0,0 +1,85 @@ +# Customize your page +--- + +call the method ```Content```of the engine: + +```go +package main + +import ( + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/examples/datamodel" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/plugins/example" + "github.com/GoAdminGroup/go-admin/template/types" + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + eng := engine.Default() + + cfg := config.Config{} + + adminPlugin := admin.NewAdmin(datamodel.Generators) + + examplePlugin := example.NewExample() + + if err := eng.AddConfig(cfg).AddPlugins(adminPlugin, examplePlugin).Use(r); err != nil { + panic(err) + } + + r.Static("/uploads", "./uploads") + + // here to custom a page. + + r.GET("/"+cfg.PREFIX+"/custom", func(ctx *gin.Context) { + engine.Content(ctx, func() (types.Panel, error) { + return datamodel.GetContent() + }) + }) + + r.Run(":9033") +} +``` + +```Content```will write the contents into the ```context``` of the framework. + +here is the code of ```GetContent```: + +```go +package datamodel + +import ( + "github.com/GoAdminGroup/go-admin/modules/config" + template2 "github.com/GoAdminGroup/go-admin/template" + "github.com/GoAdminGroup/go-admin/template/types" + "html/template" +) + +func GetContent() (types.Panel, error) { + + components := template2.Get(config.Get().THEME) + colComp := components.Col() + + infobox := components.InfoBox(). + SetText("CPU TRAFFIC"). + SetColor("blue"). + SetNumber("41,410"). + SetIcon("ion-ios-gear-outline"). + GetContent() + + var size = map[string]string{"md": "3", "sm": "6", "xs": "12"} + infoboxCol1 := colComp.SetSize(size).SetContent(infobox).GetContent() + row1 := components.Row().SetContent(infoboxCol1).GetContent() + + return types.Panel{ + Content: row1, + Title: "Dashboard", + Description: "this is a example", + }, nil +} +``` diff --git a/fr/plan.md b/fr/plan.md new file mode 100644 index 0000000..b90d467 --- /dev/null +++ b/fr/plan.md @@ -0,0 +1,62 @@ +# 发展计划 +--- + +GoAdmin的定位不只是一个管理后台中心构建框架,目前在1.0基础版本已经实现了一个能快速构建简单的crud以及有权限管理功能的管理后台的基础构建框架。在此基础上,可以对主题以及插件等进行一定程度的定制。以下分三点阐述这个项目以后的发展计划: + +## 项目功能规划 + +GoAdmin的目标是实现无代码化或某种程度的无代码化可视化操作,内置插件会至少包括:简单与复杂商业化crud管理中心极速构建,支持多数据源的监控体系的搭建等等。以下是对版本的初步规划: + +### 1.0.0 版本 + +- 实现基础的框架,同时提供一个内置插件能够满足快速构建crud管理后台。 +- 这个基础框架可以实现前端主题的自由定制,以及对插件的加载。 + +### 2.0.0 版本 + +- 在 1.0 版本的基础上,此版本将完善内置插件的功能,基本达到商业化水平(能够提供一个ec商城后台/saas系统的所有功能) +- 完善主题和插件的开发工具链,使得非项目开发人员都能够轻松的上手主题与插件的开发 +- 提供更多样化的内置主题与内置插件 +- 监控体系的初步支持(实时监控系统,数据前端展示,定制数据源) +- 项目性能的评估与优化 + +### 3.0.0 版本 + +- 可生产环境商业化的监控体系支持 +- 初步实现界面数据化以及实现一个界面拖拽定制框架 + +### 4.0.0 版本 + +- 实现无代码化的界面拖拽框架 + +## 人才社区构建 + +GoAdmin项目需要更多的人才一同加入。 + +目前由我 [@cg33](https://github.com/chenhg5) 一人维护此项目,本人是国内某知名985/211大学计算机系本科毕业,两年的gopher。 + +目前项目需要的工作有: + +- [项目开发](https://github.com/GoAdminGroup/go-admin),需掌握一定的```golang```开发能力 +- 社区项目开发(暂未开源,暂不对外开放) +- [文档的维护改进与翻译](https://github.com/GoAdminGroup/docs) +- 项目的宣传与社区文化的组织 + +GoAdmin始终秉持开放开源的态度,欢迎有志有能力之士加入一块共谋项目和社区的发展,社区与个人相辅相成。 + +如果你看好GoAdmin的发展,并且愿意为他赌一把,用时间换取未来可能的财务或名誉度回报,而且你对你自己的能力有足够信心,那么你可以尝试充分阅读GoAdmin的代码,并理解GoAdmin的发展规划,为此做出你的贡献。前期代码缺陷漏洞大,可修改空间多,如果你有能力做出足够的贡献,将成为项目的**联合创始人**或**核心开发者**。到后期,代码完善度高,也仍然有改进空间,你可以通过提交修复成为**贡献者**。团队将会一直保持开放态度,接纳新成员。团队每一个付出努力的成员也会在将来根据付出比例公平地去收获项目给大家带来的一定的回报。 + +如果你没有足够的时间和精力,但有一定的资金,且同样看好GoAdmin发展,虽然GoAdmin尚未就此加入的方案拟定计划。但只要你有足够大的兴趣,也可以带上你的计划与我们进行洽谈。 + +## 商业项目计划 + +GoAdmin会逐步实现商业化,但核心基础功能是免费开源的。 +GoAdmin的资金收入模式主要是: + +- 接受捐助 +- 售卖主题 +- 售卖插件 +- 提供saas定制化开发 +- 提供收费的商业化版本 + +收入资金主要用于维护社区的发展,与开发人员的薪酬回报,促使项目更好的成长。 \ No newline at end of file diff --git a/fr/plugins/admin.md b/fr/plugins/admin.md new file mode 100644 index 0000000..ed12ba8 --- /dev/null +++ b/fr/plugins/admin.md @@ -0,0 +1,536 @@ +# How To Use Admin Plugin +--- + +The Admin plugin can help you to quickly generate a database data table for adding, deleting, and changing database data tables. + +## Quick Start + +Following the steps: + +- Generate a configuration file corresponding to the data table +- Set access routing +- Initialize and load in the engine +- Set access menu + +### Generate configuration file + +Suppose you have a data table users in your database, such as: + +```sql +CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `gender` tinyint(4) DEFAULT NULL, + `city` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ip` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` + +Use the command line tools - admincli to help you quickly generate configuration files: + +- install + +```bash +go install github.com/GoAdminGroup/go-admin/admincli +``` + +- generate + +
+Execute in the project folder + +```bash +admincli generate +``` + +Fill in the information according to the prompts. After the run, a file ```users.go``` will be generated. This is the configuration file corresponding to the data table. How to configure it is described in detail later. + +### Set access url + +After the configuration file is generated, a routing configuration file ```tables.go``` will also be generated : + +```go +package main + +import "github.com/GoAdminGroup/go-admin/plugins/admin/models" + +// The key of Generators is the prefix of table info url. +// The corresponding value is the Form and Table data. +// +// http://{{config.DOMAIN}}:{{PORT}}/{{config.PREFIX}}/info/{{key}} +// +// example: +// +// "user" => http://localhost:9033/admin/info/user +// +var Generators = map[string]models.TableGenerator{ + "user": GetUserTable, +} +``` + +```"user"``` is the corresponding access route prefix, ```GetUserTable``` is the table data generation method. +The corresponding access routing address is: http://localhost:9033/admin/info/users + +### Initialize and load in the engine + +To initialize, you need to call the ```NewAdmin``` method, and then pass the ```Generators``` above. Then call the engine's ```AddPlugins``` method to load the engine. + +```go +package main + +import ( + "github.com/gin-gonic/gin" + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + _ "github.com/GoAdminGroup/themes/adminlte" + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/modules/language" +) + +func main() { + r := gin.Default() + eng := engine.Default() + cfg := config.Config{ + Databases: config.DatabaseList{ + "default": { + Host: "127.0.0.1", + Port: "3306", + User: "root", + Pwd: "root", + Name: "godmin", + MaxIdleCon: 50, + MaxOpenCon: 150, + Driver: config.DriverMysql, + }, + }, + UrlPrefix: "admin", + Store: config.Store{ + Path: "./uploads", + Prefix: "uploads", + }, + Language: language.CN, + } + + adminPlugin := admin.NewAdmin(Generators) + + // AddGenerator can also be used to load the Generator, like: + // adminPlugin.AddGenerator("user", GetUserTable) + + eng.AddConfig(cfg). + AddPlugins(adminPlugin). // 加载插件 + Use(r) + + r.Run(":9033") +} +``` + +### Set access menu + +After running, access the login URL, enter the menu management page, and set the management menu of the data table to enter in the sidebar. + +> PS: +> +> In the above example, the login URL is http://localhost:9033/admin/login +> +> The menu management page is http://localhost:9033/admin/menu + +## Introduction to the business data table generation method file + +```go +package datamodel + +import ( + "fmt" + "github.com/GoAdminGroup/go-admin/modules/db" + form2 "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form" + "github.com/GoAdminGroup/go-admin/plugins/admin/modules/table" + "github.com/GoAdminGroup/go-admin/template/types" + "github.com/GoAdminGroup/go-admin/template/types/form" +) + +func GetUserTable() (userTable table.Table) { + + // config the table model. + userTable = table.NewDefaultTable(table.Config{ + Driver: db.DriverMysql, + CanAdd: true, + Editable: true, + Deletable: true, + Exportable: true, + Connection: table.DefaultConnectionName, + PrimaryKey: table.PrimaryKey{ + Type: db.Int, + Name: table.DefaultPrimaryKeyName, + }, + }) + + info := userTable.GetInfo() + + // set id sortable. + info.AddField("ID", "id", db.Int).FieldSortable(true) + info.AddField("Name", "name", db.Varchar) + + // use FieldDisplay. + info.AddField("Gender", "gender", db.Tinyint).FieldDisplay(func(model types.FieldModel) interface{} { + if model.Value == "0" { + return "men" + } + if model.Value == "1" { + return "women" + } + return "unknown" + }) + + info.AddField("Phone", "phone", db.Varchar) + info.AddField("City", "city", db.Varchar) + info.AddField("CreatedAt", "created_at", db.Timestamp) + info.AddField("UpdatedAt", "updated_at", db.Timestamp) + + // set the title and description of table page. + info.SetTable("users").SetTitle("Users").SetDescription("Users"). + SetAction(template.HTML(``)) // custom operation button + + formList := userTable.GetForm() + + // set id editable is false. + formList.AddField("ID", "id", db.Int, form.Default).FieldNotAllowEdit() + formList.AddField("Ip", "ip", db.Varchar, form.Text) + formList.AddField("Name", "name", db.Varchar, form.Text) + + // use FieldOptions. + formList.AddField("Gender", "gender", db.Tinyint, form.Radio). + FieldOptions([]map[string]string{ + { + "field": "gender", + "label": "male", + "value": "0", + "selected": "true", + }, { + "field": "gender", + "label": "female", + "value": "1", + "selected": "false", + }, + }) + formList.AddField("Phone", "phone", db.Varchar, form.Text) + formList.AddField("City", "city", db.Varchar, form.Text) + + // add a custom field and use FieldPostFilterFn to do more things. + formList.AddField("Custom Field", "role", db.Varchar, form.Text). + FieldPostFilterFn(func(value types.PostFieldModel) string { + fmt.Println("user custom field", value) + return "" + }) + + formList.AddField("UpdatedAt", "updated_at", db.Timestamp, form.Default).FieldNotAllowAdd(true) + formList.AddField("CreatedAt", "created_at", db.Timestamp, form.Default).FieldNotAllowAdd(true) + + // use SetTabGroups to group a form into tabs. + formList.SetTabGroups(types. + NewTabGroups("id", "ip", "name", "gender", "city"). + AddGroup("phone", "role", "created_at", "updated_at")). + SetTabHeaders("profile1", "profile2") + + // set the title and description of form page. + formList.SetTable("users").SetTitle("Users").SetDescription("Users") + + // use SetPostHook to add operation when form posted. + formList.SetPostHook(func(values form2.Values) { + fmt.Println("userTable.GetForm().PostHook", values) + }) + + return +} +``` + +Initialize by calling ```models.NewDefaultTable(models.DefaultTableConfig)``` method to pass data table model configuration. The data table model is configured as: + +```go +type Config struct { + Driver string // database driver + Connection string // database connection name, defined in the global configuration + CanAdd bool // Can I add data + Editable bool // Can I edit + Deletable bool // Can I delete it + Exportable bool // Whether it can be exported + PrimaryKey PrimaryKey // primary key of the data table +} + +type PrimaryKey struct { + Type db.DatabaseType // primary key type + Name string // primary key name +} +``` + +The business data table generation method is a function that returns a type object of ```models.Table```. The following is the definition of ```models.Table```: + +```go +type Table interface { + GetInfo() *types.InfoPanel + GetForm() *types.FormPanel + GetCanAdd() bool + GetEditable() bool + GetDeletable() bool + GetFiltersMap() []map[string]string + GetDataFromDatabase(path string, params *Parameters) PanelInfo + GetDataFromDatabaseWithId(id string) ([]types.Form, string, string) + UpdateDataFromDatabase(dataList map[string][]string) + InsertDataFromDatabase(dataList map[string][]string) + DeleteDataFromDatabase(id string) +} +``` + +It mainly includes ```GetInfo()``` and ```GetForm()```. The ui corresponding to the type returned by these two functions is the table for displaying data and the form for editing new data. The screenshots are as follows: + +- This is the ```Info```. + +
+ +![](http://quizfile.dadadaa.cn/everyday/app/jlds/img/006tNbRwly1fxoy26qnc5j31y60u0q91.jpg) + +- This is the ```Form```. + +
+ +![](http://quizfile.dadadaa.cn/everyday/app/jlds/img/006tNbRwly1fxoy2w3cobj318k0ooabv.jpg) + +### Info + +```go +type InfoPanel struct { + FieldList []Field + curFieldListIndex int + + Table string + Title string + Description string + + // Warn: may be deprecated future. + TabGroups TabGroups // tabs contents + TabHeaders TabHeadersq // tabs headers + + Sort Sort + + Action template.HTML + HeaderHtml template.HTML + FooterHtml template.HTML +} + +type Field struct { + FilterFn FieldFilterFn // filter function + Field string // field name + TypeName db.DatabaseType // field type + Head string // title + Width int // width, unit is px + Join Join // join table setting + Sortable bool // can be sorted or not + Filterable bool // can be filtered or not + Hide bool // hide or not +} + +// Field is the table field. +type Field struct { + Head string // title + Field string // field name + TypeName db.DatabaseType // field type + + Join Join // join table setting + + Width int // width, unit is px + Sortable bool // can be sorted or not + Fixed bool // can be sorted or not + Filterable bool // can be filtered or not + Hide bool // hide or not + + Display FieldFilterFn // field display filter function + DisplayProcessChains DisplayProcessFnChains // field value process function list +} + + +// join table setting +// example: left join Table on Table.JoinField = Field +type Join struct { + Table string + Field string + JoinField string +} +``` + +### Form + +```go +type FormPanel struct { + FieldList FormFields // form field list + curFieldListIndex int + + // Warn: may be deprecated future. + TabGroups TabGroups // tabs, [example](https://github.com/GoAdminGroup/go-admin/blob/master/examples/datamodel/user.go#L76) + TabHeaders TabHeaders // tabs headers, [example](https://github.com/GoAdminGroup/go-admin/blob/master/examples/datamodel/user.go#L78) + + Table string + Title string + Description string + + Validator FormValidator // form post validator function + PostHook FormPostHookFn // form post hook function + + HeaderHtml template.HTML // header custom html content + FooterHtml template.HTML // footer custom html content +} + +// form validator function type +type PostValidator func(values form.Values) error + +// form hook function type +type PostHookFn func(values form.Values) + +type FormField struct { + Field string + TypeName db.DatabaseType + Head string + FormType form.Type + + Default string + Value string + Options []map[string]string + DefaultOptionDelimiter string + + Editable bool + NotAllowAdd bool + Must bool + + Display FieldFilterFn // field display filter function + DisplayProcessChains DisplayProcessFnChains // field value process function list + PostFilterFn PostFieldFilterFn +} +``` + +The currently supported form types are: + +- default +- normal text +- Single selection +- Password +- rich text +- File +- double selection box +- Multiple choices +- icon drop-down selection box +- time selection box +- radio selection box +- email input box +- url input box +- ip input box +- color selection box +- Currency input box +- Digital input box + +
+ +Can be used like this: + +``` + +import "github.com/GoAdminGroup/go-admin/template/types/form" + +... +FormType: form.File, +... + +``` + +For the selection type: single selection, multiple selection, selection box, you need to specify the Options value. The format is: + +``` +... +Options: []map[string]string{ + { + "field": "name", + "value": "joe", + },{ + "field": "name", + "value": "jane", + }, +} +... +``` + +Where field is the name of the field and value is the value corresponding to the selection. + +### Filter function FilterFn and processing function PostFn description + +```go +// FieldModel contains ID and value of the single query result. +type FieldModel struct { + ID string + Value string +} + +// FieldFilterFn determines the value that is retrieved from the database +// and passes to the format displayed by the front end. +// +// The type currently accepted for return is: template.HTML, string, []string +// +// For tables, you can return the template.HTML type, including html and css +// styles, so that the fields in the table can be personalized, such as: +// +// FilterFn: func(model types.FieldModel) interface{} { +// return template.Get("adminlte").Label().SetContent(template2.HTML(model.Value)).GetContent() +// }, +// +// For forms, note that if it is a select box type: Select/SelectSingle/SelectBox, +// you need to return an array: []string, such as: +// +// FilterFn: func(model types.FieldModel) interface{} { +// return strings.Split(model.Value, ",") +// }, +// +// For other form types, return the string type +// +type FieldFilterFn func(value FieldModel) interface{} + +// PostFieldModel contains ID and value of the single query result. +type PostFieldModel struct { + ID string + Value FieldModelValue + Row map[string]interface{} +} + +type FieldModelValue []string + +// PostFieldFilterFn is used to process the form data when submitting the form. +// The form data is passed over, processed by the form submission filter +// function and then stored in the database. +// +// If it is for the select type: Select/SelectSingle/SelectBox,you need to +// convert the array type to a string type, such as: +// +// PostFilterFn: func(model types.PostFieldModel) string { +// return strings.Join(model.Value, ",") +// }, +// +// Also it can be used for the processing of non-form fields, which can be used to update +// or insert data with tables. +// +// Custom fields, such as the role of the user table, need to be updated. +// Here, the table update can be performed based on the passed primary key +// ID and the form data Value. Such as: +// +// PostFilterFn: func(model types.PostFieldModel) { +// db.Table("role").Insert(dialect.H{ +// "user_id": model.ID, +// "role_id": model.Value.Value(), +// }) +// }, +// +type PostFieldFilterFn func(value PostFieldModel) string + +
+ +> English is not my main language. If any typo or wrong translation you found, you can help to translate in [github here](https://github.com/GoAdminGroup/docs). I will very appreciate it. + diff --git a/fr/plugins/plugins.md b/fr/plugins/plugins.md new file mode 100644 index 0000000..a32fc1e --- /dev/null +++ b/fr/plugins/plugins.md @@ -0,0 +1,81 @@ +# How To Use Plugins +--- + +The framework's plugins include: controllers, routing, and views. The specific plug-in development will be discussed in the project development part, here just show you how to use it. + +The example plugin is our demo. + +Using plugins are divided into: using the third package source code plugin and use the dynamic link library plugin (.so file, currently only supports linux and mac platforms) + +## Using the third package source code plugin + +For example: + +```go +package main + +import ( + "github.com/gin-gonic/gin" + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + _ "github.com/GoAdminGroup/themes/adminlte" + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/plugins/example" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/examples/datamodel" +) + +func main() { + r := gin.Default() + eng := engine.Default() + cfg := config.Config{} + + adminPlugin := admin.NewAdmin(datamodel.Generators) + examplePlugin := example.NewExample() + + eng.AddConfig(cfg). + AddPlugins(adminPlugin, examplePlugin). // loading + Use(r) + + r.Run(":9033") +} +``` + + +## Using the binary plugin + +Load the ```.so```file, and call```plugins.LoadFromPlugin```. + +如: + +```go +package main + +import ( + "github.com/gin-gonic/gin" + _ "github.com/GoAdminGroup/go-admin/adapter/gin" + _ "github.com/GoAdminGroup/themes/adminlte" // Import the theme + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/GoAdminGroup/go-admin/plugins" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/examples/datamodel" +) + +func main() { + r := gin.Default() + eng := engine.Default() + cfg := config.Config{} + + adminPlugin := admin.NewAdmin(datamodel.Generators) + + // load plugin from .so file. + examplePlugin := plugins.LoadFromPlugin("../datamodel/example.so") + + eng.AddConfig(cfg). + AddPlugins(adminPlugin, examplePlugin). + Use(r) + + r.Run(":9033") +} +``` \ No newline at end of file diff --git a/fr/quick_start.md b/fr/quick_start.md new file mode 100644 index 0000000..9bfbb2e --- /dev/null +++ b/fr/quick_start.md @@ -0,0 +1,234 @@ +# Quick Start +--- + +go-admin makes it easy to use in various web frameworks through various adapters. Currently supported web frameworks are: + +- [gin](http://github.com/gin-gonic/gin) +- [beego](https://github.com/astaxie/beego) +- [fasthttp](https://github.com/valyala/fasthttp) +- [buffalo](https://github.com/gobuffalo/buffalo) +- [echo](https://github.com/labstack/echo) +- [gorilla/mux](http://github.com/gorilla/mux) +- [iris](https://github.com/kataras/iris) +- [chi](https://github.com/go-chi/chi) + +
+ +You can choose the framework you are using or the business project is using. If there is no framework you like, please feel free to give us an issue or pr! + +Let's take the gin framework as an example to demonstrate the build process. + +## main.go + +Create a new ```main.go``` file in your project folder with the following contents: + +```go +package main + +import ( + _ "github.com/GoAdminGroup/go-admin/adapter/gin" // Import the adapter, it must be imported. If it is not imported, you need to define it yourself. + _ "github.com/GoAdminGroup/themes/adminlte" // Import the theme + "github.com/GoAdminGroup/go-admin/engine" + "github.com/GoAdminGroup/go-admin/examples/datamodel" + "github.com/GoAdminGroup/go-admin/modules/config" + "github.com/GoAdminGroup/go-admin/modules/language" + "github.com/GoAdminGroup/go-admin/plugins/admin" + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + // Instantiate a go-admin engine object. + eng := engine.Default() + + // go-admin global configuration, can also be written as a json, imported by json. + cfg := config.Config{ + Databases: []config.Database{ + { + Host: "127.0.0.1", + Port: "3306", + User: "root", + Pwd: "root", + Name: "godmin", + MaxIdleCon: 50, + MaxOpenCon: 150, + Driver: "mysql", + }, + }, + UrlPrefix: "admin", // The url prefix of the website. + // Store must be set and guaranteed to have write access, otherwise new administrator users cannot be added. + Store: config.Store{ + Path: "./uploads", + Prefix: "uploads", + }, + Language: language.EN, + } + + // Import the business table configuration you need to manage here. + // About Generators,see: https://github.com/GoAdminGroup/go-admin/blob/master/examples/datamodel/tables.go + adminPlugin := admin.NewAdmin(datamodel.Generators) + + // Add configuration and plugins, use the Use method to mount to the web framework. + _ = eng.AddConfig(cfg).AddPlugins(adminPlugin).Use(r) + + _ = r.Run(":9033") +} +``` + +Please pay attention to the above code and comments, the corresponding steps are added to the comments, it is simple to use, the following steps: + +- Introducing an adapter +- Set global configuration items +- Initialize the plugin +- Set up plugins and configurations +- Mounted to the web framework + +
+ +Then execute ```go run main.go``` to run the code and access: [http://localhost:9033/admin/login](http://localhost:9033/admin/login)
+
+default account: admin
+default password: admin + +more web framework example: [https://github.com/GoAdminGroup/go-admin/tree/master/examples](https://github.com/GoAdminGroup/go-admin/tree/master/examples) + +## Add your own business table for management + +See:

+1 [How To Use Plugins](plugins/plugins)
+2 [How To Use Admin Plugin](plugins/admin) + +## Global configuration item description + +[https://github.com/GoAdminGroup/go-admin/blob/master/modules/config/config.go](https://github.com/GoAdminGroup/go-admin/blob/master/modules/config/config.go) + +```go +package config + +import ( + "html/template" +) + +// Database is a type of database connection config. +// Because a little difference of different database driver. +// The Config has multiple options but may be not used. +// Such as the sqlite driver only use the FILE option which +// can be ignored when the driver is mysql. +type Database struct { + Host string + Port string + User string + Pwd string + Name string + MaxIdleCon int + MaxOpenCon int + Driver string + File string +} + +// Database configuration +// which is a map where key is the name of the database connection and +// value is the corresponding data configuration. +// The key is the default database is the default database, but also +// the database used by the framework, and you can configure multiple +// databases to be used by your business tables to manage different databases. +type DatabaseList map[string]Database + +// Store is the file store config. Path is the local store path. +// and prefix is the url prefix used to visit it. +type Store struct { + Path string + Prefix string +} + + +// Config type is the global config of goAdmin. It will be +// initialized in the engine. +type Config struct { + // An map supports multi database connection. The first + // element of Databases is the default connection. See the + // file connection.go. + Databases DatabaseList `json:"database"` + + // The cookie domain used in the auth modules. see + // the session.go. + Domain string `json:"domain"` + + // Used to set as the localize language which show in the + // interface. + Language string `json:"language"` + + // The global url prefix. + UrlPrefix string `json:"prefix"` + + // The theme name of template. + Theme string `json:"theme"` + + // The path where files will be stored into. + Store Store `json:"store"` + + // The title of web page. + Title string `json:"title"` + + // Logo is the top text in the sidebar. + Logo template.HTML `json:"logo"` + + // Mini-logo is the top text in the sidebar when folding. + MiniLogo template.HTML `json:"mini_logo"` + + // The url redirect to after login + IndexUrl string `json:"index"` + + // Debug mode + Debug bool `json:"debug"` + + // Env is the environment, which maybe local, test, prod. + Env string + + // Info log path + InfoLogPath string `json:"info_log"` + + // Error log path + ErrorLogPath string `json:"error_log"` + + // Access log path + AccessLogPath string `json:"access_log"` + + // Sql operator record log switch + SqlLog bool `json:"sql_log"` + + AccessLogOff bool + InfoLogOff bool + ErrorLogOff bool + + // Color scheme + ColorScheme string `json:"color_scheme"` + + // Session life time, unit is second. + SessionLifeTime int `json:"session_life_time"` + + // Cdn link of assets + AssetUrl string `json:"asset_url"` + + // File upload engine, default "local" + FileUploadEngine FileUploadEngine `json:"file_upload_engine"` + + // Custom html in the tag head. + CustomHeadHtml template.HTML `json:"custom_head_html"` + + // Custom html after body. + CustomFootHtml template.HTML `json:"custom_foot_html"` + + // Login page title + LoginTitle string `json:"login_title"` + + // Login page logo + LoginLogo template.HTML `json:"login_logo"` +} + +``` + +
+ +> English is not my main language. If any typo or wrong translation you found, you can help to translate in [github here](https://github.com/GoAdminGroup/docs). I will very appreciate it. \ No newline at end of file diff --git a/zh/admin/form/basic.md b/zh/admin/form/basic.md index 61e3d44..183f60c 100644 --- a/zh/admin/form/basic.md +++ b/zh/admin/form/basic.md @@ -59,4 +59,16 @@ formList.AddField("Ip", "ip", db.Varchar, form.Text) // 添加第三个字段,一个sql表不存在的字段 formList.AddField("Custom", "custom", db.Varchar, form.Text) +``` + +### 不允许编辑 + +```go + +``` + +### 不允许新增 + +```go + ``` \ No newline at end of file