Add Leafcutter addon
This commit is contained in:
parent
4498cc95f6
commit
0190ccdfd3
8 changed files with 92 additions and 5207 deletions
15
packages/zammad-addon-leafcutter/package.json
Normal file
15
packages/zammad-addon-leafcutter/package.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "zammad-addon-leafcutter",
|
||||
"displayName": "Leafcutter",
|
||||
"version": "2.0.0",
|
||||
"description": "Adds a common set of tags for Leafcutter uses.",
|
||||
"scripts": {
|
||||
"build": "node ../../node_modules/zammad-addon-common/dist/build.js",
|
||||
"migrate": "node ../../node_modules/zammad-addon-common/dist/migrate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"zammad-addon-common": "*"
|
||||
},
|
||||
"author": "",
|
||||
"license": "AGPL-3.0-or-later"
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# create core Leafcutter tags
|
||||
class LeafcutterTags1 < ActiveRecord::Migration[5.2]
|
||||
def self.up
|
||||
Tag::Item.create(name: 'example_group:example_tag')
|
||||
end
|
||||
|
||||
def self.down
|
||||
t = Tag::Item.find_by(name: 'example_group:example_tag')
|
||||
return if t.nil?
|
||||
|
||||
t.destroy
|
||||
end
|
||||
end
|
||||
56
packages/zammad-addon-leafcutter/tags.js
Normal file
56
packages/zammad-addon-leafcutter/tags.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
const R = require("ramda");
|
||||
const { TagsV1 } = require("@digiresilience/leafcutter-fields");
|
||||
const {
|
||||
indexOfField,
|
||||
getFieldById,
|
||||
getFieldIds,
|
||||
getOptionsForField,
|
||||
getOptionIdsForField,
|
||||
getSubmitterFields,
|
||||
getAnalystFields,
|
||||
} = require("@digiresilience/leafcutter-fields/src/fields");
|
||||
|
||||
const upTag = (name) => `Tag::Item.create(name: "${name}")`;
|
||||
|
||||
const downTag = (name) => `t = Tag::Item.find_by(name: "${name}")
|
||||
if !t.nil?
|
||||
t.destroy
|
||||
end
|
||||
`;
|
||||
|
||||
const upTagGroup = (field) =>
|
||||
R.map(upTag, getOptionIdsForField(TagsV1, field.id));
|
||||
const downTagGroup = (field) =>
|
||||
R.map(downTag, getOptionIdsForField(TagsV1, field.id));
|
||||
|
||||
const upSection = (children) => `def self.up
|
||||
${children.join("\n")}
|
||||
end`;
|
||||
|
||||
const downSection = (children) => `def self.down
|
||||
${children.join("\n")}
|
||||
end`;
|
||||
|
||||
const migration = (
|
||||
name,
|
||||
ups,
|
||||
downs
|
||||
) => `class ${name} < ActiveRecord::Migration[5.2]
|
||||
${upSection(ups)}
|
||||
|
||||
${downSection(downs)}
|
||||
end
|
||||
`;
|
||||
|
||||
const ups = R.flatten(R.map(upTagGroup, TagsV1));
|
||||
const downs = R.flatten(R.map(downTagGroup, TagsV1));
|
||||
|
||||
const name = process.argv[2];
|
||||
if (!name) throw new Error("Must pass name of migration");
|
||||
|
||||
const re = RegExp("^[a-zA-Z][a-zA-Z0-9]+$");
|
||||
if (!re.test(name))
|
||||
throw new Error("Name must be only alphanumeric and start with a letter");
|
||||
|
||||
const res = migration(name, ups, downs);
|
||||
console.log(res);
|
||||
Loading…
Add table
Add a link
Reference in a new issue