Commit 825a5b38 authored by Moises Sacal's avatar Moises Sacal
Browse files

initial commit

parents
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
\ No newline at end of file
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/dist-server
/tmp
/out-tsc
# dependencies
node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# e2e
e2e/*.js
e2e/*.map
# System Files
.DS_Store
Thumbs.db
test/angular
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
## A Sails Hook Redbox Template
In this example template you will find the barebones requirements for a Hook
This Project is divided between folders
## api
Main API of your Hook can be stored in controllers and services
- controllers
- services
## config & form-config
This configurations are redbox-portal dependent. They will allow redbox to be available as a record
If you require to have a form in your portal
- `config/recordtype`
- `config/workflow`
- `form-config/template-1.0-draft`
## index
Main entry point for the hook
### initialize
Init code before it gets hooked.
### routes
Controller routes exposed to the sails front-end
```javascript
'get /your/route' : YourController.method
```
### configure
Add configuration and services to your sails app
```javascript
sails.services['YourService'] = function() { };
sails.config = _.merge(sails.config, {object});
```
## test
First run `npm install`
Test your sails hook with mocha by running `npm test` before adding the hook to your redbox-portal.
It may cause your application to not lift.
```sh
$ npm test
> @uts-ersearch/sails-hook-redbox-template@1.0.0 test /Users/moises/source/code.research/sails-hook-redbox-template
> NODE_ENV=test node_modules/.bin/mocha
Basic tests ::
✓ should have a service
✓ should have a form
✓ should have a route
✓ sails does not crash
4 passing (864ms)
```
For more information on testing your hook go to : https://sailsjs.com/documentation/concepts/testing
const TemplateService = require('../services/TemplateService');
module.exports = {
helloWorld: function (req, res, next) {
const hello = TemplateService.helloWorld();
return res.send(hello);
}
};
module.exports = {
helloWorld: function () {
return 'Hello World';
}
};
module.exports.recordtype = {
"template": {
"packageType": "workspace",
searchFilters: [
{
name: "text_title",
title: "search-refine-title",
type: "exact",
typeLabel: "search-refine-contains"
},
{
name: "text_description",
title: "search-refine-description",
type: "exact",
typeLabel: "search-refine-contains"
},
{
name: "grant_number_name",
title: "search-refine-grant_number_name",
type: "facet",
typeLabel: null,
alwaysActive: true
},
{
name: "finalKeywords",
title: "search-refine-keywords",
type: "facet",
typeLabel: null,
alwaysActive: true
},
{
name: "workflow_stageLabel",
title: "search-refine-workflow_stageLabel",
type: "facet",
typeLabel: null,
alwaysActive: true
}
]
}
};
module.exports.workflow = {
"template": {
"draft": {
config: {
workflow: {
stage: 'draft',
stageLabel: 'Draft',
},
authorization: {
viewRoles: ['Admin', 'Librarians'],
editRoles: ['Admin', 'Librarians']
},
form: 'example-1.0-draft'
},
starting: true
}
}
}
/**
* Template form
*/
module.exports = {
name: 'template-1.0-draft',
type: 'template',
skipValidationOnSave: true,
editCssClasses: 'row col-md-12',
viewCssClasses: 'row col-md-offset-1 col-md-10',
messages: {
'saving': ['@dmpt-form-saving'],
'validationFail': ['@dmpt-form-validation-fail-prefix', '@dmpt-form-validation-fail-suffix'],
'saveSuccess': ['@dmpt-form-save-success'],
'saveError': ['@dmpt-form-save-error']
},
fields: [
{
class: 'Container',
compClass: 'TextBlockComponent',
viewOnly: false,
definition: {
name: 'title',
value: 'Template',
type: 'h2'
}
}
]
};
const _ = require('lodash');
const TemplateController = require('./api/controllers/TemplateController');
const TemplateService = require('./api/services/TemplateService');
const recordTypeConfig = require('./config/recordtype.js');
const workflowConfig = require('./config/workflow.js');
const recordFormConfig = require('./form-config/template-1.0-draft.js');
module.exports = function (sails) {
return {
initialize: function (cb) {
// Do Some initialisation tasks
// This can be for example: copy files or images to the redbox-portal front end
return cb();
},
//If each route middleware do not exist sails.lift will fail during hook.load()
routes: {
before: {},
after: {
'get /:branding/:portal/ws/template/hello': TemplateController.helloWorld
}
},
configure: function () {
sails.services['TemplateService'] = TemplateService;
sails.config = _.merge(sails.config, recordTypeConfig);
sails.config = _.merge(sails.config, workflowConfig);
sails.config['form']['forms'] = _.merge(sails.config['form']['forms'], {'template-1.0-draft': recordFormConfig});
}
}
};
This diff is collapsed.
{
"name": "@uts-ersearch/sails-hook-redbox-template",
"version": "1.0.0",
"description": "A Sails Hook Template",
"main": "index.js",
"sails": {
"isHook": true,
"hookName": "template"
},
"scripts": {
"test": "NODE_ENV=test node_modules/.bin/mocha"
},
"repository": {
"type": "git",
"url": "git@code.research.uts.edu.au:eresearch/sails-hook-redbox-template.git"
},
"keywords": [
"sails",
"hook",
"redbox",
"provisioner"
],
"author": "Moises Sacal",
"license": "GPL-3.0",
"devDependencies": {
"mocha": "^5.1.1",
"sails": "^1.0.2",
"supertest": "^3.0.0"
},
"dependencies": {
"lodash": "^4.17.10"
}
}
const Sails = require('sails').Sails;
const assert = require('assert');
var supertest = require('supertest');
const TemplateService = require('../api/services/TemplateService');
describe('Basic tests ::', function () {
// Var to hold a running sails app instance
var sails;
// Before running any tests, attempt to lift Sails
before(function (done) {
// Hook will timeout in 10 seconds
this.timeout(11000);
// Attempt to lift sails
Sails().lift({
hooks: {
// Load the hook
"sails-hook-redbox-template": require('../'),
// Skip grunt (unless your hook uses it)
"grunt": false
},
form: {forms: {}}, //Mock forms to test hook.configure()
log: {level: "error"}
}, function (err, _sails) {
if (err) return done(err);
sails = _sails;
return done();
});
});
it('should have a service', function (done) {
assert.equal(sails.services['TemplateService'].helloWorld(), 'Hello World');
done();
});
it('should have a form', function (done) {
const type = sails.config['form']['forms']['template-1.0-draft']['type'];
assert.equal(type, 'template');
done();
});
it('should have a route', function (done) {
supertest(sails.hooks.http.app)
.get('/:branding/:portal/ws/template/hello')
.expect(200)
.end(function (err, res) {
assert.equal(res.text, 'Hello World');
done();
});
});
// After tests are complete, lower Sails
after(function (done) {
// Lower Sails (if it successfully lifted)
if (sails) {
return sails.lower(done);
}
// Otherwise just return
return done();
});
// Test that Sails can lift with the hook in place
it('sails does not crash', function () {
return true;
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment