A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/signumsoftware/framework/commit/e8d4ab20e612af0b826beca77b7edf648227e806 below:

add UserChart / UserQuery widgets to TemplateControls · signumsoftware/framework@e8d4ab2 · GitHub

1 1

import * as React from 'react'

2 -

import { SubTokensOptions, QueryToken, hasAnyOrAll } from '@framework/FindOptions'

2 +

import { SubTokensOptions, QueryToken, hasAnyOrAll, FindOptions } from '@framework/FindOptions'

3 3

import { TemplateTokenMessage } from './Signum.Entities.Templating'

4 4

import QueryTokenBuilder from '@framework/SearchControl/QueryTokenBuilder'

5 +

import ValueLineModal from '../../Signum.React/Scripts/ValueLineModal'

6 +

import { UserChartEntity } from '../Chart/Signum.Entities.Chart'

7 +

import { useAPI } from '../../Signum.React/Scripts/Hooks'

8 +

import * as Navigator from '../../Signum.React/Scripts/Navigator'

9 +

import * as Finder from '../../Signum.React/Scripts/Finder'

10 +

import { UserQueryEntity } from '../UserQueries/Signum.Entities.UserQueries'

11 +

import { getTypeInfos } from '@framework/Reflection'

12 +

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

5 13 6 14

export interface TemplateControlsProps {

7 15

queryKey: string;

8 -

onInsert: (newCode: string) => void;

9 -

forHtml: boolean

16 +

forHtml: boolean;

17 +

widgetButtons?: boolean;

10 18

}

11 19 12 20

export default function TemplateControls(p: TemplateControlsProps) {

13 21 14 -

const [currentToken, setCurrentToken] = React.useState<QueryToken | undefined>(undefined)

15 - 22 +

const [currentToken, setCurrentToken] = React.useState<QueryToken | undefined>(undefined);

23 +

const qd = useAPI(() => Finder.getQueryDescription(p.queryKey), [p.queryKey]);

24 + 16 25

function renderButton(text: string, canClick: string | undefined, buildPattern: (key: string) => string) {

17 26

return <input type="button" disabled={!!canClick} className="btn btn-light btn-sm sf-button"

18 27

title={canClick} value={text}

19 -

onClick={() => p.onInsert(buildPattern(currentToken ? currentToken.fullKey : ""))} />;

28 +

onClick={() => ValueLineModal.show({

29 +

type: { name: "string" },

30 +

initialValue: buildPattern(currentToken ? currentToken.fullKey : ""),

31 +

title: "Template",

32 +

message: "Copy to clipboard: Ctrl+C, ESC",

33 +

initiallyFocused: true,

34 +

}).done()} />

35 +

}

36 + 37 +

function renderWidgetButton(text: React.ReactElement, getCode: () => Promise<string | undefined>) {

38 +

return <button className="btn btn-light btn-sm sf-button"

39 + 40 +

onClick={() =>

41 +

getCode()

42 +

.then(code =>

43 +

code &&

44 +

ValueLineModal.show({

45 +

type: { name: "string" },

46 +

valueLineType: "TextArea",

47 +

initialValue: code,

48 +

title: "Embedded Widget",

49 +

message: "Make a similar-looking Chart or Table in Excel and copy it to Word or PowerPoint. Then add the following code in the Alternative Text to bind the data:",

50 +

initiallyFocused: true,

51 +

})).done()} >{text}</button>

20 52

}

21 53 22 54 55 + 56 + 23 57

function canElement(): string | undefined {

24 58

let token = currentToken;

25 59

@@ -83,7 +117,7 @@ export default function TemplateControls(p: TemplateControlsProps) {

83 117

return null;

84 118 85 119

return (

86 -

<div>

120 +

<div className="d-flex">

87 121

<span className="rw-widget-sm">

88 122

<QueryTokenBuilder queryToken={ct} queryKey={p.queryKey} onTokenChange={t => setCurrentToken(t ?? undefined)} subTokenOptions={SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement} readOnly={false} />

89 123

</span>

@@ -98,7 +132,40 @@ export default function TemplateControls(p: TemplateControlsProps) {

98 132

{renderButton("any", canElement(), token => p.forHtml ?

99 133

`<!--@any[${token}]--> <!--@notany--> <!--@endany-->` :

100 134

`@any[${token}] @notany @endany`)}

135 + 136 + 137 + 138 + 101 139

</div>

140 +

{p.widgetButtons &&

141 +

<div className="btn-group" style={{ marginLeft: "auto" }}>

142 +

{UserChartEntity.tryTypeInfo() && renderWidgetButton(<><FontAwesomeIcon icon={"chart-bar"} color={"darkviolet"} className="icon" /> {UserChartEntity.niceName()}</>, () => Finder.find<UserChartEntity>({

143 +

queryName: UserChartEntity,

144 +

filterOptions: [{

145 +

token: UserChartEntity.token(a => a.entity!.entityType!.entity!.cleanName),

146 +

operation: "IsIn",

147 +

value: [null, ...getTypeInfos(qd?.columns["Entity"].type!).map(a => a.name)]

148 +

}]

149 +

}).then(uc => uc && Navigator.API.fetch(uc).then(uce => {

150 +

var text = "UserChart:" + uce.guid;

151 + 152 +

if ((uce.chartScript.key.contains("Multi") || uce.chartScript.key.contains("Stacked")) && uce.columns[1].element.token != null /*Split*/)

153 +

text += "\nPivot(0, 1, 2)";

154 + 155 +

return text;

156 +

})))}

157 +

{

158 +

UserQueryEntity.tryTypeInfo() && renderWidgetButton(<><FontAwesomeIcon icon={["far", "list-alt"]} color={"dodgerblue"} className="icon" /> {UserQueryEntity.niceName()}</>, () => Finder.find<UserChartEntity>({

159 +

queryName: UserQueryEntity,

160 +

filterOptions: [{

161 +

token: UserQueryEntity.token(a => a.entity!.entityType!.entity!.cleanName),

162 +

operation: "IsIn",

163 +

value: [null, ...getTypeInfos(qd?.columns["Entity"].type!).map(a => a.name)]

164 +

}]

165 +

}).then(uc => uc && Navigator.API.fetch(uc).then(uce => "UserQuery:" + uce.guid)))

166 +

}

167 +

</div>

168 +

}

102 169

</div>

103 170

);

104 171

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4