Skip to content

Instantly share code, notes, and snippets.

View arnaudbesnier's full-sized avatar
🏠
Working from home

Arnaud Besnier arnaudbesnier

🏠
Working from home
View GitHub Profile
@arnaudbesnier
arnaudbesnier / forest-express-mongoose-dropdown-dynamic-route.js
Last active April 9, 2019 08:26
Forest Express Mongoose Dropdown Dynamic Options
// Step 1: Create the file below
// Step 2: Configure the dropdown in dynamic mode using this path: /forest/orders/shippingStatusOptions
// decorators/routes/orders.js
const express = require('express');
const router = express.Router();
const Liana = require('forest-express-mongoose');
const models = require('../../models');
@arnaudbesnier
arnaudbesnier / forest-express-sequelize-dropdown-dynamic-route.js
Last active April 9, 2019 08:01
Forest Express Sequelize Dropdown Dynamic Options
// Step 1: Create the file below
// Step 2: Configure the dropdown in dynamic mode using this path: /forest/orders/shippingStatusOptions
// decorators/routes/orders.js
const Liana = require('forest-express-sequelize');
const models = require('../../models');
const STATUS_OPTION_DEFAULT = 'Being processed';
const STATUS_TRANSITIONS = {
'Being processed': ['Ready for shipping'],
const Liana = require('forest-express-sequelize');
const models = require('../../models');
const { Op } = models.Sequelize;
Liana.collection('guest', {
fields: [{
field: 'googleAccessToken',
type: 'String',
get: async (guest) => {
@arnaudbesnier
arnaudbesnier / forest_smart_action_reference_field_options.rb
Last active August 21, 2018 07:50
Forest Rails - Admin API - Override on the records list for a Smart Action context
# /lib/forest_liana/collections/movie.rb
class Forest::Movie
include ForestLiana::Collection
collection :Movie
action 'Approve comment', fields: [{
field: 'comment',
type: 'Number',
reference: 'Comment.id',
@arnaudbesnier
arnaudbesnier / forestSmartActionReferenceFieldOptions.js
Last active August 12, 2020 15:13
Forest Express - Admin API - Override on the records list for a Smart Action context
// forest/order.js (Smart Action declaration)
const Liana = require('forest-express-sequelize');
Liana.collection('order', {
actions: [{
name: 'Test product',
fields: [{
field: 'product',
type: 'Number',
@arnaudbesnier
arnaudbesnier / forest-associated-record-search-override.js
Last active March 30, 2020 14:06
Forest Express - Admin API - Override on the associated records search
const Liana = require('forest-express-sequelize');
const models = require('./models');
// NOTICE: "collection" has to be replaced by the collection/model you want to customize.
app.get('/forest/collection', (request, response, next) => {
if (!request.query.searchToEdit) {
// NOTICE: Seach for collection list, keep the current behaviour.
return next();
}
@arnaudbesnier
arnaudbesnier / smart-action-for-deep-creation.js
Created January 23, 2018 17:33
Smart Action for "deep" creation
// See documentation at https://doc.forestadmin.com/developer-guide/lumber.html#actions
// Smart Action declaration example in forest/request.js
const Liana = require('forest-express-sequelize');
Liana.collection('request', {
actions: [{
name: 'Add offer with child objects',
fields: [{
field: 'offerStatus',
require 'jsonapi-serializers'
require 'csv'
class Forest::PaymentsController < ForestLiana::ApplicationController
def index
@payments = [
Forest::Payment.new(
id: 1,
amount: 1000,
currency: 'USD'
@arnaudbesnier
arnaudbesnier / search-field-names.js
Last active July 5, 2017 13:48
Example of a Forest Smart Search on Express Sequelize
'use strict';
var Liana = require('forest-express-sequelize');
Liana.collection('Address', {
searchFields: ['id', 'user.email']
});
'use strict';
const _ = require('lodash');
const moment = require('moment');
const liana = require('forest-express-sequelize');
const models = require('../../../../models');
function values(request, response) {
// NOTICE: To access to the current recordId => request.body.record_id
const query = `RAW SQL QUERY HERE`;