Skip to content

Commit

Permalink
feat: add way to add copyright notice to templates/generators
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Sep 7, 2024
1 parent 758abaa commit be89d17
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 36 deletions.
1 change: 1 addition & 0 deletions frontend/src/js/types/basic-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type BasicInfo = {
author: string;
description: string;
version: string;
copyrightNotice?: string;
};

export default BasicInfo;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/js/types/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function createEmptyGenerator(): Generator {
return {
name: 'Your Generator Name',
description: '',
copyrightNotice: '',
author: 'username',
slug: 'your-generator-name',
version: '',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/js/types/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function createEmptyTemplate(): Template {
return {
name: 'Your Template Name',
description: '',
copyrightNotice: '',
author: 'username',
slug: 'your-template-name',
version: '',
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/js/ui/components/editor/basic-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default <T extends Object>(): m.Component<BasicInfoProps<T>> => ({
m(PropertyEdit<BasicInfo & T>, {
properties: attrs.info,
onChange: onChange,
show: ['name', 'description', 'author', 'slug'].filter((p) => !attrs.hide?.includes(p)),
show: ['name', 'description', 'copyrightNotice', 'author', 'slug'].filter((p) => !attrs.hide?.includes(p)),
annotations: {
name: {
label: 'Name',
Expand All @@ -48,6 +48,12 @@ export default <T extends Object>(): m.Component<BasicInfoProps<T>> => ({
largeInput: true,
fullSize: true,
},
copyrightNotice: {
label: 'Copyright Notice',
description: 'Any legal notice you want to include',
largeInput: true,
fullSize: true,
},
author: {
label: 'Author',
validator: author,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/js/ui/components/modals/create-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CreateSourceProps = {
slug: string;
author: string;
description: string;
copyrightNotice: string;
};

const dataSourceCreateModal = (): m.Component => {
Expand All @@ -25,6 +26,7 @@ const dataSourceCreateModal = (): m.Component => {
slug: '',
author: '',
description: '',
copyrightNotice: '',
};

return {
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/js/ui/views/generator/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default (): m.Component<SingleGeneratorProps> => {
m(Flex, { className: '.bt.b--black-10.pv2.ph3', justify: 'end', items: 'center', gap: 2 }, [
/*
Disabled for now!
m(
Tooltip,
{ content: 'Print Count' },
Expand All @@ -208,7 +208,14 @@ export default (): m.Component<SingleGeneratorProps> => {
m(IconButton, { icon: 'print', intend: 'success', onClick: print }, 'Print'),
]),
]),
Information: () => m('div.ph3.pv2.lh-copy', [m('div.f5.mb2.b', 'Description'), state.generator?.description ?? '']),
Information: () =>
m('div.ph3.pv2.lh-copy', [
m('div.f5.mb2.b', 'Description'),
m('div', { style: { whiteSpace: 'break-spaces' } }, state.generator?.description ?? ''),
...(state.generator?.copyrightNotice
? [m('div.f5.mb2.b.mt3', 'Copyright Notice'), m('div', { style: { whiteSpace: 'break-spaces' } }, state.generator.copyrightNotice)]
: []),
]),
Saved: () => m('div.ph3.pv2', 'coming soon...'),
},
}),
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/js/ui/views/template/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default (): m.Component<SingleTemplateProps> => {
...(settings.value.aiEnabled ? [{ icon: 'planet', label: 'AI Tools' }] : []),
{ icon: 'clipboard', label: 'Information' },
...(state.template?.config && state.template?.config.length > 0 ? [{ icon: 'options', label: 'Config' }] : []),
{ icon: 'search', label: 'Advanced Filter' },
// { icon: 'search', label: 'Advanced Filter' },
],
content: {
Entries: () =>
Expand Down Expand Up @@ -441,7 +441,17 @@ export default (): m.Component<SingleTemplateProps> => {
]),
]),
),
Information: () => m('div.ph3.pv2.lh-copy', [m('div.f5.mb2.b', 'Description'), state.template?.description ?? '']),
Information: () =>
m('div.ph3.pv2.lh-copy', [
m('div.f5.mb2.b', 'Description'),
m('div', { style: { whiteSpace: 'break-spaces' } }, state.template?.description ?? ''),
...(state.template?.copyrightNotice
? [
m('div.f5.mb2.b.mt3', 'Copyright Notice'),
m('div', { style: { whiteSpace: 'break-spaces' } }, state.template.copyrightNotice),
]
: []),
]),
Config: () =>
m(Editor, {
current: state.config,
Expand All @@ -451,7 +461,7 @@ export default (): m.Component<SingleTemplateProps> => {
m.redraw();
},
}),
'Advanced Filter': () => m('div.pa3', 'Coming back soon...'),
//'Advanced Filter': () => m('div.pa3', 'Coming back soon...'),
},
})
: null,
Expand Down
1 change: 1 addition & 0 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Generator struct {
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
CopyrightNotice string `json:"copyrightNotice"`
PrintTemplate string `json:"printTemplate"`
PassEntriesToJS bool `json:"passEntriesToJS"`
Config []GeneratorConfig `json:"config"`
Expand Down
2 changes: 2 additions & 0 deletions imexport/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type generatorMeta struct {
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
CopyrightNotice string `json:"copyrightNotice"`
PassEntriesToJS bool `json:"passEntriesToJS"`
Config []snd.GeneratorConfig `json:"config"`
Images map[string]string `json:"images"`
Expand All @@ -30,6 +31,7 @@ func writeGenMeta(writer io.Writer, gen snd.Generator) error {
Slug: gen.Slug,
Author: gen.Author,
Description: gen.Description,
CopyrightNotice: gen.CopyrightNotice,
PassEntriesToJS: gen.PassEntriesToJS,
Config: gen.Config,
Images: gen.Images,
Expand Down
40 changes: 21 additions & 19 deletions imexport/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ import (
)

type templateMeta struct {
Name string `json:"name"`
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
DataSources []string `json:"dataSources"`
Config []snd.TemplateConfig `json:"config"`
Images map[string]string `json:"images"`
Name string `json:"name"`
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
CopyrightNotice string `json:"copyrightNotice"`
DataSources []string `json:"dataSources"`
Config []snd.TemplateConfig `json:"config"`
Images map[string]string `json:"images"`
}

func writeMeta(writer io.Writer, tmpl snd.Template) error {
enc := json.NewEncoder(writer)
enc.SetIndent("", "\t")
enc.SetEscapeHTML(true)
if err := enc.Encode(&templateMeta{
tmpl.Name, tmpl.Slug, tmpl.Author, tmpl.Description, tmpl.DataSources, tmpl.Config, tmpl.Images,
tmpl.Name, tmpl.Slug, tmpl.Author, tmpl.Description, tmpl.CopyrightNotice, tmpl.DataSources, tmpl.Config, tmpl.Images,
}); err != nil {
return err
}
Expand Down Expand Up @@ -75,17 +76,18 @@ func ImportTemplate(reader ImportReader) (snd.Template, []snd.Entry, error) {
}

tmpl = snd.Template{
Name: meta.Name,
Slug: meta.Slug,
Author: meta.Author,
Description: meta.Description,
PrintTemplate: "",
ListTemplate: "",
SkeletonData: nil,
Images: meta.Images,
Config: meta.Config,
DataSources: meta.DataSources,
Version: "",
Name: meta.Name,
Slug: meta.Slug,
Author: meta.Author,
Description: meta.Description,
CopyrightNotice: meta.CopyrightNotice,
PrintTemplate: "",
ListTemplate: "",
SkeletonData: nil,
Images: meta.Images,
Config: meta.Config,
DataSources: meta.DataSources,
Version: "",
}

if len(tmpl.Slug) == 0 || len(tmpl.Author) == 0 || len(tmpl.Name) == 0 {
Expand Down
23 changes: 12 additions & 11 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ type TemplateConfig struct {

// Template represents one S&D template.
type Template struct {
Name string `json:"name"`
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
PrintTemplate string `json:"printTemplate"`
ListTemplate string `json:"listTemplate"`
SkeletonData map[string]interface{} `json:"skeletonData"`
Images map[string]string `json:"images"`
Config []TemplateConfig `json:"config"`
DataSources []string `json:"dataSources"`
Version string `json:"version"`
Name string `json:"name"`
Slug string `json:"slug"`
Author string `json:"author"`
Description string `json:"description"`
CopyrightNotice string `json:"copyrightNotice"`
PrintTemplate string `json:"printTemplate"`
ListTemplate string `json:"listTemplate"`
SkeletonData map[string]interface{} `json:"skeletonData"`
Images map[string]string `json:"images"`
Config []TemplateConfig `json:"config"`
DataSources []string `json:"dataSources"`
Version string `json:"version"`
}

func (t Template) ID() string {
Expand Down

0 comments on commit be89d17

Please sign in to comment.