New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSoc 2016: Admin console and Elasticsearch Integration (WIP) #125
Changes from all commits
eceed3a
715e29e
ce0f765
ee01d57
3b6852c
08ed53e
17b9324
ba96069
39e2512
a43716b
1435aaa
e09db73
47498b1
b5ad116
bdb1d7b
b28a562
dbd2173
eacf6ae
b1d1a73
4054602
d4aa925
45a76ec
b8a0be6
fd3c0bf
912cbc4
030d976
3e4b63d
16319ff
9cbb468
8bc5781
e9aa764
36ac439
9181986
3e86023
ae08e32
9bdbd2f
d457589
b7927d4
f7d20be
38646fd
d4a4909
48f5e38
6d9206b
873fb9e
5005b4c
c911e0f
74b8c18
25fce2d
0f8f830
6ae526a
8b4f9fd
ac476ca
b6466fb
ae555a2
b0d3a13
e02a32a
4b17e90
dda91d5
37fbde5
77e78b7
d8c22c1
2eedd9a
cf9d344
be9ae1a
a77172f
67e54ef
889f59b
7b43fd0
3a32199
f92d2e5
57f90b6
39da2bc
66dc1f8
8ae1cd1
fd2b207
f5fc9b5
2ce5404
24f42c6
c53353a
904634e
300721f
7c2949a
2c8be47
9ab556f
35a3c6f
2779b0b
386ee24
63dbc44
e454897
c96ee68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
##Admin Center | ||
|
||
The controller and views for admin center are pre loaded with the blank-app. So, when you create a new app using `sailor create "app_name"` these files are within the new folders. | ||
|
||
###Admin center structure | ||
|
||
There is one controller named `admin.lua` and a views folder named "admin" inside which are three files. One is `dashboard.lp` which is the views file for the autogen and config editor functions. `index.lp` is for logging into the admin center. Third file is `error.lp`. | ||
|
||
###Getting started | ||
First open `conf/conf.lua`. Change these two parameters: | ||
|
||
-- the default value for this is "false" | ||
enable_admin = "true" | ||
|
||
-- the defaullt password is empty | ||
admin_password = "someDifficultPassword" | ||
|
||
After running the `start-server.lua`, visit <a href="http://localhost:8080/?r=admin">here</a>. Enter the password set it in the config file in the above setup. You would be | ||
re-directed to `localhost:8000/?r=admin/dashboard`. | ||
The autogen functions are located on the left and the fields from the config file are on the right. You can edit any of the config editor values and then press `submit` button | ||
at the bottom of the screen. | ||
|
||
###Autogen Functions | ||
|
||
The first autogen function is to Generate a model based on a table existing in the database. This is a very handy function to automatically generate the model file. | ||
Enter the table name and press enter. | ||
|
||
There would be a success message ` Model generated with success.`. | ||
To create the methods for CRUD operations in the controller, use the next autogen function. | ||
To Generate CRUD, enter the name of the `model` created in the previous step. This would be same as the name of the table. | ||
|
||
###Config editor | ||
|
||
Config editor is basically a long form which when saved, writes data into the config file. The existing values can be edited and then saved at the end. The main file edited here is `conf/conf.lua`. | ||
|
||
After making necessary changes, don't forget to logout and also disable admin in production servers. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
##Reference Manual | ||
### Elastic Search Model | ||
|
||
This module makes it possible to store, retrieve and search data from <a href = "https://www.elastic.co/downloads/elasticsearch">Elasticsearch </a>. It uses the <a href = "github.com/dhavalkapil/elasticsearch-lua">elasticsearch-lua</a> client for Lua. Refer the client <a href="http://elasticsearch-lua.readthedocs.io/en/latest/">here</a> to know the parameters which can be sent through the model functions if any. Return responses are also same as the one offered by this client. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please include in the docs how to install the necessary files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some instructions. Please check 2c8be47 |
||
|
||
###Installation and getting started. | ||
|
||
To get started, install the elasticsearch-lua rock using | ||
|
||
luarocks install --server=http://luarocks.org/dev elasticsearch | ||
|
||
Make sure you have elasticsearch installed and running. Refer to the instructions given on the official <a href = "https://www.elastic.co/downloads/elasticsearch">website</a>. | ||
|
||
The `es_model.lua` file is the main module. After importing "es_model" we proceed to create a new instance of the model. There should be a file inside models/ which contains the keys and types defined for the particular model. | ||
|
||
local es_model = require "sailor.es_model" | ||
-- test.lua should be inside models/ folder. | ||
local contact = es.model.new("test") | ||
|
||
Now, you can assign attributes to `contact` like | ||
|
||
contact.name = "test name" | ||
contact.email = "test@test.com" | ||
|
||
And save it using, | ||
|
||
msg , code = contact.save{id = 1} | ||
|
||
The `arg` represented here is named arguments which have to be passed into the function. For list of args that can be passed check the elasticsearch-lua reference. | ||
|
||
The return value for these functions is same as elasticsearch-lua. | ||
Example: | ||
|
||
local msg , err = contact.save{id = 2, routing = "test.com", timout = "2m"} | ||
|
||
If the call succeeds then `msg` contains the result table and `err` contains the status code. | ||
If the call fails then `msg` contains `nil` and `err` contains the error message. | ||
|
||
###Elasticsearch administration | ||
|
||
To use administrative functionalities, | ||
|
||
local es_model = require("sailor.db.es_model") | ||
-- To use the namespaces | ||
local res, err = es_model.client.cluster:stats() | ||
|
||
Check this <a href="http://elasticsearch-lua.readthedocs.io/en/latest/namespaces/">page</a> for more functions. | ||
|
||
###model.save(arg) | ||
|
||
This function takes a list of paramters which would be same as for the elasticsearch-lua client. It saves the attributes assigned to the model if the `body` parameter is not present. Else it just saves the array passsed in the body parameter. The below example saves the `name` attribute into the ES | ||
|
||
contact.name = "test" | ||
contact.save = {id = 1} | ||
|
||
The index can be preset in the config file which can also be over written when passing the parameters. | ||
|
||
###model.getCount() | ||
|
||
This functions returns the number of documents present in the given index and type. You don't need to pass any parameter. | ||
Example: | ||
|
||
local count = contact.getCount() | ||
|
||
###model.getAll() | ||
|
||
This function returns a table of all the documents present in the given index and type. No parameter is required. It uses the `client:search()` function from elasticsearch-lua on the inside. | ||
|
||
local data, err = contact.getAll() | ||
|
||
###model.update(arg) | ||
|
||
This is used for updating documents already in the index. The id has to be specified. | ||
|
||
contact.update{id = 1, body = {doc = { name = "new name" }}} | ||
|
||
###model.delete(arg) | ||
|
||
Deletes a particular document with the given id. | ||
|
||
contact.delete{id = 1} | ||
|
||
###model.search(arg) | ||
|
||
Search the given index and type. The arg list supports a lot of parameters. Read more about it <a href="https://dhavalkapil.com/elasticsearch-lua/docs/classes/Client.html#Client:search">here.</a> | ||
|
||
contact.search{q = "queryString", size = 15} | ||
|
||
###model.get(arg) | ||
|
||
Get's documents from the database based on the parameters provided. Full list of args can be found <a href="https://dhavalkapil.com/elasticsearch-lua/docs/classes/Client.html#Client:get">here.</a> | ||
|
||
contact.get{id = 1, fields = {name, email}} | ||
|
||
###model.bulkIndex(arg) | ||
|
||
For indexing multiple documents at once. Uses `client:bulk()`. The index and type have to set in the parameters. For a list of parameters check <a href="https://dhavalkapil.com/elasticsearch-lua/docs/classes/Client.html#Client:bulk">here.</a> | ||
|
||
contact.bulkIndex{ | ||
body = { | ||
-- First action | ||
{ | ||
index = { | ||
["_index"] = "my_index1", | ||
["_type"] = "my_type1" | ||
} | ||
}, | ||
-- First body | ||
{ | ||
my_key1 = "my_value1", | ||
}, | ||
-- Second action | ||
{ | ||
index = { | ||
["_index"] = "my_index2", | ||
["_type"] = "my_type2" | ||
} | ||
}, | ||
-- Second body | ||
{ | ||
my_key2 = "my_value2", | ||
} | ||
} | ||
} | ||
|
||
###model.mget(arg) | ||
|
||
You can get multiple documents in the form of nested table using the `client:mget()`. The allowed parameters are <a href="https://dhavalkapil.com/elasticsearch-lua/docs/classes/Client.html#Client:mget">here.</a> | ||
|
||
contact.mget{ | ||
body = { | ||
docs = { | ||
-- First document | ||
{ | ||
["_index"] = "my_index1", | ||
["_type"] = "my_type1", | ||
["_id"] = "my_id1" | ||
}, | ||
-- Second document | ||
{ | ||
["_index"] = "my_index2", | ||
["_type"] = "my_type2", | ||
["_id"] = "my_id2" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ Let's suppose we have a User model and we want to unit test some of the User met | |
|
||
The fixture is a regular Lua script that will be required. This for multiple possibilities, such as making loops for inserting many entries, as long as in the end you return a table containing samples of your model. | ||
|
||
After creating your fixture, you must add this on the bottom of your bootstrap file so they are loaded before running your tests. | ||
After creating your fixture, you must add this on the bottom of your bootstrap file so they are loaded before running your tests. Also don't forget to set the package.path to the sailor directory you want to test. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
--/tests/bootstrap.lua | ||
... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can now use: