Skip to content

Commit

Permalink
adapt Signum.React and Signum.React.Extensions to Lite Model (a.toStr…
Browse files Browse the repository at this point in the history
… -> getToString(a), and more changes)
  • Loading branch information
olmobrutall committed Jun 24, 2022
1 parent 7a38ab1 commit 498aea3
Show file tree
Hide file tree
Showing 91 changed files with 481 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ public EntityInfoProxy(string dataEntity)

public Lite<Entity> ToLite(object? liteModel = null)
{
return Lite.Create(this.EntityType, this.IdOrNull!.Value, liteModel);
if (liteModel == null)
return Lite.Create(this.EntityType, this.IdOrNull!.Value);
else
return Lite.Create(this.EntityType, this.IdOrNull!.Value, liteModel);
}

public static EntityInfoProxy? Parse(string dataEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Lite<IEntity>? LiteValue
public List<Lite<Entity>?> Options()
{
return this.ComboElement.Options
.Select(o => Lite.Parse(o.GetAttribute("value"))?.Do(l => l.SetToString(o.Text)))
.Select(o => Lite.Parse(o.GetAttribute("value"))?.Do(l => l.SetModel(o.Text)))
.ToList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using OpenQA.Selenium;
using Signum.Entities;
Expand All @@ -23,7 +23,7 @@ public List<Lite<Entity>> GetDataElements()
return this.Element.WithLocator(By.CssSelector("label.sf-checkbox-element")).FindElements().Select(e =>
{
var lite = Lite.Parse(e.FindElement(By.CssSelector("input[type=checkbox]")).GetAttribute("name"));
lite.SetToString(e.FindElement(By.CssSelector("span.sf-entitStrip-link")).Text);
lite.SetModel(e.FindElement(By.CssSelector("span.sf-entitStrip-link")).Text);
return lite;
}).ToList();
}
Expand Down
4 changes: 2 additions & 2 deletions Signum.React.Extensions/Alerts/AlertDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import * as Operations from '@framework/Operations'
import * as Finder from '@framework/Finder'
import { is, JavascriptMessage, toLite } from '@framework/Signum.Entities'
import { getToString, is, JavascriptMessage, toLite } from '@framework/Signum.Entities'
import { Toast, Button, ButtonGroup } from 'react-bootstrap'
import { DateTime } from 'luxon'
import { useAPIWithReload, useForceUpdate, useUpdatedRef } from '@framework/Hooks';
Expand Down Expand Up @@ -224,7 +224,7 @@ export function AlertToast(p: { alert: AlertEntity, onClose: (e: AlertEntity[])
</Toast.Header>
<Toast.Body style={{ whiteSpace: "pre-wrap" }}>
{AlertsClient.formatText(p.alert.textField || p.alert.textFromAlertType || "", p.alert, p.refresh)}
{p.alert.createdBy && <small className="sf-alert-signature">{p.alert.createdBy?.toStr}</small>}
{p.alert.createdBy && <small className="sf-alert-signature">{getToString(p.alert.createdBy)}</small>}
</Toast.Body>
</Toast>
);
Expand Down
4 changes: 2 additions & 2 deletions Signum.React.Extensions/Alerts/AlertsClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { andClose } from '@framework/Operations/EntityOperations';
import * as AuthClient from '../Authorization/AuthClient'
import { ajaxGet } from '@framework/Services'
import * as Finder from '@framework/Finder'
import { Entity, isEntity, isLite, Lite, toLite } from '@framework/Signum.Entities'
import { Entity, getToString, isEntity, isLite, Lite, toLite } from '@framework/Signum.Entities'
import { EntityLink } from '@framework/Search'
import Alert from './Templates/Alert'
import { ISymbol, PropertyRoute, symbolNiceName } from '@framework/Reflection'
Expand Down Expand Up @@ -145,7 +145,7 @@ export function formatText(text: string, alert: Partial<AlertEntity>, onNavigate
isLite(prop) ? prop : null;

if (groups.url)
nodes.push(<Link to={replacePlaceHolders(groups.url, alert)!}>{replacePlaceHolders(groups.text, alert) ?? lite?.toStr}</Link>);
nodes.push(<Link to={replacePlaceHolders(groups.url, alert)!}>{replacePlaceHolders(groups.text, alert) ?? getToString(lite)}</Link>);
else if (lite != null) {
if (groups.text)
nodes.push(<EntityLink lite={lite} onNavigated={onNavigated}>{replacePlaceHolders(groups.text, alert)}</EntityLink>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from 'react-bootstrap'
import { notifySuccess } from '@framework/Operations'
import { TypeContext, ButtonsContext, IRenderButtons, ButtonBarElement } from '@framework/TypeContext'
import { EntityLine, ValueLine } from '@framework/Lines'
import { OperationSymbol } from '@framework/Signum.Entities'
import { getToString, OperationSymbol } from '@framework/Signum.Entities'
import { API } from '../AuthAdminClient'
import { OperationRulePack, OperationAllowed, OperationAllowedRule, AuthAdminMessage, PermissionSymbol, AuthEmailMessage } from '../Signum.Entities.Authorization'
import { ColorRadio, GrayCheckbox } from './ColoredRadios'
Expand Down Expand Up @@ -77,7 +77,7 @@ export default React.forwardRef(function OperationRulePackControl({ ctx }: { ctx
{ctx.mlistItemCtxs(a => a.rules).map((c, i) =>
<tr key={i}>
<td>
{c.value.resource!.operation!.toStr}
{getToString(c.value.resource!.operation)}
</td>
<td style={{ textAlign: "center" }}>
{renderRadio(c.value, "Allow", "green")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ColorRadio, GrayCheckbox } from './ColoredRadios'
import { Button } from 'react-bootstrap'
import "./AuthAdmin.css"
import { useForceUpdate } from '@framework/Hooks';
import { getToString } from '@framework/Signum.Entities';

export default React.forwardRef(function QueryRulesPackControl({ ctx }: { ctx: TypeContext<QueryRulePack> }, ref: React.Ref<IRenderButtons>) {

Expand Down Expand Up @@ -77,7 +78,7 @@ export default React.forwardRef(function QueryRulesPackControl({ ctx }: { ctx: T
{ctx.mlistItemCtxs(a => a.rules).orderBy(a => a.value.resource.key).map((c, i) =>
<tr key={i}>
<td>
{c.value.resource.toStr}
{getToString(c.value.resource)}
</td>
<td style={{ textAlign: "center" }}>
{renderRadio(c.value, "Allow", "green")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SelectorModal from '@framework/SelectorModal'
import MessageModal from '@framework/Modals/MessageModal'

import { getTypeInfo, Binding, GraphExplorer } from '@framework/Reflection'
import { OperationSymbol, ModelEntity, newMListElement, NormalControlMessage } from '@framework/Signum.Entities'
import { OperationSymbol, ModelEntity, newMListElement, NormalControlMessage, getToString } from '@framework/Signum.Entities'
import { API, properties, queries, operations } from '../AuthAdminClient'
import {
TypeRulePack, AuthAdminMessage, PermissionSymbol, TypeAllowed, TypeAllowedRule,
Expand Down Expand Up @@ -188,7 +188,7 @@ export default React.forwardRef(function TypesRulesPackControl({ ctx }: { ctx: T


function handleAddConditionClick(remainig: TypeConditionSymbol[], taac: TypeAllowedAndConditions) {
SelectorModal.chooseElement(remainig, { buttonDisplay: a => a.toStr.tryAfter(".") ?? a.toStr })
SelectorModal.chooseElement(remainig, { buttonDisplay: a => getToString(a) })
.then(tc => {
if (!tc)
return;
Expand Down Expand Up @@ -278,7 +278,7 @@ export default React.forwardRef(function TypesRulesPackControl({ ctx }: { ctx: T
{"\u00A0 \u00A0".repeat(i + 1)}
<span className="sf-condition-icon" onClick={() => handleRemoveConditionClick(tctx.value.allowed, c)}><FontAwesomeIcon icon="minus-circle" /></span>
&nbsp;
<small>{c.typeCondition.toStr.tryAfter(".") ?? c.typeCondition.toStr}</small>
<small>{getToString(c.typeCondition)}</small>
</td>
<td style={{ textAlign: "center" }} className={masterClass}>
{colorRadio(b, "Write", "green")}
Expand Down
6 changes: 3 additions & 3 deletions Signum.React.Extensions/Chart/ChartClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ajaxGet } from '@framework/Services';
import * as Navigator from '@framework/Navigator'
import * as AppContext from '@framework/AppContext'
import * as Finder from '@framework/Finder'
import { Entity, Lite, liteKey, MList } from '@framework/Signum.Entities'
import { Entity, getToString, Lite, liteKey, MList } from '@framework/Signum.Entities'
import { getQueryKey, getEnumInfo, QueryTokenString, getTypeInfos, tryGetTypeInfos, timeToString, toFormatWithFixes } from '@framework/Reflection'
import {
FilterOption, OrderOption, OrderOptionParsed, QueryRequest, QueryToken, SubTokensOptions, ResultTable, OrderRequest, OrderType, FilterOptionParsed, hasAggregate, ColumnOption, withoutAggregate
Expand Down Expand Up @@ -648,7 +648,7 @@ export module API {
if (token.type.isLite)
return v => {
var lite = v as Lite<Entity> | null;
return String(lite?.toStr ?? "");
return String(getToString(lite) ?? "");
};

if (token.filterType == "Enum")
Expand Down Expand Up @@ -746,7 +746,7 @@ export module API {
if (!hasAggregates(request)) {
const value = (r: ChartRow) => r.entity;
const color = (v: Lite<Entity> | undefined) => !v ? "#555" : null;
const niceName = (v: Lite<Entity> | undefined) => v?.toStr;
const niceName = (v: Lite<Entity> | undefined) => getToString(v);
const key = (v: Lite<Entity> | undefined) => v ? liteKey(v) : String(v);
cols.insertAt(0, ({
name: "entity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ajaxPost, ajaxGet } from '@framework/Services';
import { EntitySettings } from '@framework/Navigator'
import * as Navigator from '@framework/Navigator'
import * as Finder from '@framework/Finder'
import { Entity, Lite, liteKey } from '@framework/Signum.Entities'
import { Entity, getToString, Lite, liteKey } from '@framework/Signum.Entities'
import * as QuickLinks from '@framework/QuickLinks'
import { OrderOptionParsed } from '@framework/FindOptions'
import * as AuthClient from '../../Authorization/AuthClient'
Expand Down Expand Up @@ -71,7 +71,7 @@ export function toColorPalete(model: ChartPaletteModel): ColorPalette {

if (ti == null || ti.kind == "Enum") {
var byName = model.colors.filter(a => a.element.color != null)
.toObject(a => a.element.related.toStr!, a => a.element.color);
.toObject(a => getToString(a.element.related)!, a => a.element.color);
return { ...byId, ...byName };
}

Expand Down
4 changes: 2 additions & 2 deletions Signum.React.Extensions/Chart/UserChart/UserChartClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EntitySettings } from '@framework/Navigator'
import * as AppContext from '@framework/AppContext'
import * as Navigator from '@framework/Navigator'
import * as Finder from '@framework/Finder'
import { Entity, Lite, liteKey } from '@framework/Signum.Entities'
import { Entity, getToString, Lite, liteKey } from '@framework/Signum.Entities'
import * as QuickLinks from '@framework/QuickLinks'
import * as AuthClient from '../../Authorization/AuthClient'
import { UserChartEntity, ChartPermission, ChartMessage, ChartRequestModel, ChartParameterEmbedded, ChartColumnEmbedded } from '../Signum.Entities.Chart'
Expand Down Expand Up @@ -39,7 +39,7 @@ export function start(options: { routes: JSX.Element[] }) {
API.forEntityType(ctx.lite.EntityType);

return promise.then(uqs =>
uqs.map(uc => new QuickLinks.QuickLinkAction(liteKey(uc), () => uc.toStr ?? "", e => {
uqs.map(uc => new QuickLinks.QuickLinkAction(liteKey(uc), () => getToString(uc) ?? "", e => {
window.open(AppContext.toAbsoluteUrl(`~/userChart/${uc.id}/${liteKey(ctx.lite)}`));
}, { icon: "chart-bar", iconColor: "darkviolet" })));
});
Expand Down
14 changes: 7 additions & 7 deletions Signum.React.Extensions/Chart/UserChart/UserChartMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import { Dropdown } from 'react-bootstrap'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { classes } from '@framework/Globals'
import { Lite, toLite, newMListElement, SearchMessage, MList } from '@framework/Signum.Entities'
import { Lite, toLite, newMListElement, SearchMessage, MList, getToString } from '@framework/Signum.Entities'
import { is } from '@framework/Signum.Entities'
import * as Finder from '@framework/Finder'
import * as Navigator from '@framework/Navigator'
Expand Down Expand Up @@ -41,13 +41,13 @@ export default function UserChartMenu(p: UserChartMenuProps) {
setUserCharts(list);
const userChart = p.chartRequestView.userChart;

if (userChart && userChart.toStr == null) {
if (userChart && userChart.model == null) {
const similar = list.singleOrNull(a => is(a, userChart));
if (similar) {
userChart.toStr = similar.toStr;
userChart.model = similar.model;
forceUpdate();
} else {
Navigator.API.fillToStrings(userChart)
Navigator.API.fillLiteModels(userChart)
.then(() => forceUpdate())
.done();
}
Expand Down Expand Up @@ -162,7 +162,7 @@ export default function UserChartMenu(p: UserChartMenuProps) {
}

const crView = p.chartRequestView;
const labelText = !crView.userChart ? UserChartEntity.nicePluralName() : crView.userChart.toStr
const labelText = !crView.userChart ? UserChartEntity.nicePluralName() : getToString(crView.userChart)

var canSave = tryGetOperationInfo(UserChartOperation.Save, UserChartEntity) != null;

Expand All @@ -187,12 +187,12 @@ export default function UserChartMenu(p: UserChartMenuProps) {
</div>}
<div id="userchart-items-container" style={{ maxHeight: "300px", overflowX: "auto" }}>
{userCharts?.map((uc, i) => {
if (filter == undefined || uc.toStr?.search(new RegExp(RegExp.escape(filter), "i")) != -1)
if (filter == undefined || getToString(uc)?.search(new RegExp(RegExp.escape(filter), "i")) != -1)
return (
<Dropdown.Item key={i}
className={classes("sf-userquery", is(uc, crView.userChart) && "active")}
onClick={() => handleSelect(uc)}>
{uc.toStr}
{getToString(uc)}
</Dropdown.Item>)
})}
</div>
Expand Down
2 changes: 1 addition & 1 deletion Signum.React.Extensions/Chart/UserChart/UserChartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function UserChartPage(p : UserChartPageProps){

const lite = entity == undefined ? undefined : parseLite(entity);

Navigator.API.fillToStrings(lite)
Navigator.API.fillLiteModels(lite)
.then(() => Navigator.API.fetchEntity(UserChartEntity, userChartId))
.then(uc => UserChartClient.Converter.toChartRequest(uc, lite)
.then(cr => ChartClient.Encoder.chartPathPromise(cr, toLite(uc))))
Expand Down
22 changes: 11 additions & 11 deletions Signum.React.Extensions/ConcurrentUser/ConcurrentUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as AppContext from '@framework/AppContext'
import { useSignalRCallback, useSignalRConnection, useSignalRGroup } from '../Alerts/useSignalR'
import { ConcurrentUserEntity, ConcurrentUserMessage } from './Signum.Entities.ConcurrentUser'
import { OverlayTrigger, Popover } from 'react-bootstrap';
import { Entity, Lite, liteKey, toLite } from '@framework/Signum.Entities'
import { Entity, getToString, Lite, liteKey, toLite } from '@framework/Signum.Entities'
import { UserEntity } from '../Authorization/Signum.Entities.Authorization'
import { useAPI, useForceUpdate, useUpdatedRef } from '../../Signum.React/Scripts/Hooks'
import { GraphExplorer } from '@framework/Reflection'
Expand Down Expand Up @@ -83,15 +83,15 @@ export default function ConcurrentUser(p: { entity: Entity, onReload: ()=> void
style: "warning",
message:
<div>
<p>{ConcurrentUserMessage.LooksLikeSomeoneJustSaved0ToTheDatabase.niceToString().formatHtml(<strong>{p.entity.toStr}</strong>)}</p>
<p>{ConcurrentUserMessage.LooksLikeSomeoneJustSaved0ToTheDatabase.niceToString().formatHtml(<strong>{getToString(p.entity)}</strong>)}</p>
<p>{ConcurrentUserMessage.DoYouWantToReloadIt.niceToString()}</p>
{isModified.current &&
<>
<p className="text-danger">
{ConcurrentUserMessage.WarningYouWillLostYourCurrentChanges.niceToString()}
</p>
<p>
{ConcurrentUserMessage.ConsiderOpening0InANewTabAndApplyYourChangesManually.niceToString().formatHtml(<a href={Navigator.navigateRoute(p.entity)} target="_blank">{p.entity.toStr}</a>)}
{ConcurrentUserMessage.ConsiderOpening0InANewTabAndApplyYourChangesManually.niceToString().formatHtml(<a href={Navigator.navigateRoute(p.entity)} target="_blank">{getToString(p.entity)}</a>)}
</p>
</>
}
Expand Down Expand Up @@ -121,30 +121,30 @@ export default function ConcurrentUser(p: { entity: Entity, onReload: ()=> void

{otherUsers?.map((a, i) =>
<div key={i} style={{ whiteSpace: "nowrap" }} >
<UserCircle user={a.user} /> {a.user.toStr} ({DateTime.fromISO(a.startTime).toRelative()})
<UserCircle user={a.user} /> {getToString(a.user)} ({DateTime.fromISO(a.startTime).toRelative()})
{a.isModified && <FontAwesomeIcon icon="edit" color={"#FFAA44"} title={ConcurrentUserMessage.CurrentlyEditing.niceToString()} style={{ marginLeft: "10px" }} />}
</div>)}

{isModified.current ?
(ticks !== p.entity.ticks ?
<div className="mt-3">
<small>
{ConcurrentUserMessage.YouHaveLocalChangesBut0HasAlreadyBeenSavedInTheDatabaseYouWillNotBeAbleToSaveChanges.niceToString().formatHtml(<strong>{p.entity.toStr}</strong>)}
{ConcurrentUserMessage.ConsiderOpening0InANewTabAndApplyYourChangesManually.niceToString().formatHtml(<a href={Navigator.navigateRoute(p.entity)} target="_blank">{p.entity.toStr}</a>)}
{ConcurrentUserMessage.YouHaveLocalChangesBut0HasAlreadyBeenSavedInTheDatabaseYouWillNotBeAbleToSaveChanges.niceToString().formatHtml(<strong>{getToString(p.entity)}</strong>)}
{ConcurrentUserMessage.ConsiderOpening0InANewTabAndApplyYourChangesManually.niceToString().formatHtml(<a href={Navigator.navigateRoute(p.entity)} target="_blank">{getToString(p.entity)}</a>)}
</small>
</div> :
otherUsers.some(u => u.isModified) && isModified.current ?
<div className="mt-3">
<small>{ConcurrentUserMessage.LooksLikeYouAreNotTheOnlyOneCurrentlyModifiying0OnlyTheFirstOneWillBeAbleToSaveChanges.niceToString().formatHtml(<strong>{p.entity.toStr}</strong>)}</small>
<small>{ConcurrentUserMessage.LooksLikeYouAreNotTheOnlyOneCurrentlyModifiying0OnlyTheFirstOneWillBeAbleToSaveChanges.niceToString().formatHtml(<strong>{getToString(p.entity)}</strong>)}</small>
</div>
:
<div className="mt-3">
<small>{ConcurrentUserMessage.YouHaveLocalChangesIn0ThatIsCurrentlyOpenByOtherUsersSoFarNoOneElseHasMadeModifications.niceToString().formatHtml(<strong>{p.entity.toStr}</strong>)}</small>
<small>{ConcurrentUserMessage.YouHaveLocalChangesIn0ThatIsCurrentlyOpenByOtherUsersSoFarNoOneElseHasMadeModifications.niceToString().formatHtml(<strong>{getToString(p.entity)}</strong>)}</small>
</div>
) : ticks !== p.entity.ticks ?
<div className="mt-3">
<small>
{ConcurrentUserMessage.ThisIsNotTheLatestVersionOf0.niceToString().formatHtml(<strong>{p.entity.toStr}</strong>)}
{ConcurrentUserMessage.ThisIsNotTheLatestVersionOf0.niceToString().formatHtml(<strong>{getToString(p.entity)}</strong>)}
<button className="btn btn-primary btn-sm" onClick={p.onReload}>{ConcurrentUserMessage.ReloadIt.niceToString()}</button>
</small>
</div> : null
Expand Down Expand Up @@ -174,13 +174,13 @@ export namespace Options {
}

export function getUserInitials(u: Lite<UserEntity>): string {
return u.toStr?.split(" ").map(m => m[0]).filter((a, i) => i < 2).join("").toUpperCase() ?? "";
return getToString(u)?.split(" ").map(m => m[0]).filter((a, i) => i < 2).join("").toUpperCase() ?? "";
}

export function UserCircle(p: { user: Lite<UserEntity>, className?: string }) {
var color = Options.getUserColor(p.user);
return (
<span className={classes("concurrent-user-circle", p.className)} style={{ color: "white", backgroundColor: color }} title={p.user.toStr}>
<span className={classes("concurrent-user-circle", p.className)} style={{ color: "white", backgroundColor: color }} title={getToString(p.user)}>
{getUserInitials(p.user)}
</span>
);
Expand Down
Loading

0 comments on commit 498aea3

Please sign in to comment.