Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.09 #132

Merged
merged 5 commits into from
Oct 13, 2022
Merged

14.09 #132

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "2sxc-ui",
"version": "14.08.00",
"version": "14.09.00",
"description": "2sxc UI - the JS UI of 2sxc",
"scripts": {
"release-all": "npm run js2sxc && npm run inpage && npm run snippets && npm run quickdialog && npm run turn-on",
Expand Down
5 changes: 2 additions & 3 deletions projects/$2sxc/src/cms/command-params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CommandNames, ItemIdentifierGroup, ItemIdentifierSimple, CommandParamsMetadata } from '.';
import { TypeValue } from '../../../inpage/src/plumbing';
import { CommandNames, ItemIdentifierInList, ItemIdentifierSimple, CommandParamsMetadata } from '.';

/**
* Command parameters are handed over to a command for execution.
Expand Down Expand Up @@ -40,7 +39,7 @@ export interface CommandParams extends Record<string, unknown>
action?: CommandNames;

/** @internal */
items?: Array<ItemIdentifierSimple | ItemIdentifierGroup>;
items?: Array<ItemIdentifierSimple | ItemIdentifierInList>;

/**
* Special change of dialogs, for example to change the edit-dialog into a new-dialog.
Expand Down
41 changes: 9 additions & 32 deletions projects/$2sxc/src/cms/item-identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,6 @@ export interface ItemIdentifierCopy extends ItemIdentifierShared {
ContentTypeName?: string;
}

/**
* Group identifier
* @internal
* TODO: KEEP INTERNAL, PROBABLY RENAME "Part" to "Field" or something in the whole chain
* TODO: MAY BE replaced completely with ItemIdentifierInField, as it has the same purpose
*/
export interface ItemIdentifierParent {
/** The parent entity GUID - in these cases usually the ContentBlock */
Guid: string;

/** The part of the parent it's in, kind of the "Field" - should be renamed to Field ASAP */
Part?: string;

/** The index position within that field/part */
Index: number;

/** Whether to add the item - alternative is just to leave it, if it already existed */
Add: boolean;
}

/**
* Experimental in 10.27
* @internal
*/
export interface ItemIdentifierInField extends ItemIdentifierSimple {
Parent?: string;
Field?: string;
Add?: boolean;
}

/**
* Template Identifier for telling the code-editor about this template
* @internal
Expand All @@ -83,7 +53,14 @@ export interface TemplateIdentifier {
* Complex identifier using a group
* @internal
*/
export interface ItemIdentifierGroup extends ItemIdentifierShared {
Group: ItemIdentifierParent;
export interface ItemIdentifierInList extends ItemIdentifierShared {
/** Whether to add the item - alternative is just to leave it, if it already existed */
Add: boolean;

/** The index position within that field/part */
Index: number;

Parent: string;
Field: string;
}

16 changes: 7 additions & 9 deletions projects/inpage/src/commands/command-link-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CmdParHlp } from '.';
import { ItemIdentifierCopy, ItemIdentifierGroup, ItemIdentifierInField, ItemIdentifierSimple, TemplateIdentifier } from '../../../$2sxc/src/cms';
import { ItemIdentifierCopy, ItemIdentifierInList, ItemIdentifierSimple, TemplateIdentifier } from '../../../$2sxc/src/cms';
import { C } from '../constants';
import { ContextComplete } from '../context/bundles/context-bundle-button';
import { HasLog, Log } from '../core';
Expand All @@ -16,7 +16,7 @@ const urlMode2 = false;
* @internal
*/
export class CommandLinkGenerator extends HasLog {
public items: Array<ItemIdentifierSimple | ItemIdentifierCopy | ItemIdentifierGroup | TemplateIdentifier>;
public items: (ItemIdentifierSimple | ItemIdentifierCopy | ItemIdentifierInList | TemplateIdentifier)[];
public readonly urlParams: UrlItemParams;
private readonly debugUrlParam: string;

Expand Down Expand Up @@ -156,12 +156,10 @@ export class CommandLinkGenerator extends HasLog {
private addContentGroupItem(guid: string, index: number, part: string, isAdd: boolean) {
const cl = this.log.call('addContentGroupItem', `${guid}, ${index}, ${part}, ${isAdd}`);
this.items.push({
Group: {
Guid: guid,
Index: index,
Part: part.toLocaleLowerCase(),
Add: isAdd,
}
Add: isAdd,
Index: index,
Parent: guid,
Field: part.toLocaleLowerCase(),
});
cl.done();
}
Expand All @@ -187,7 +185,7 @@ export class CommandLinkGenerator extends HasLog {
Parent: groupId,
Add: isAdd,
Index: index,
} as ItemIdentifierInField));
} as ItemIdentifierInList));
}

/**
Expand Down
18 changes: 9 additions & 9 deletions projects/inpage/src/commands/command/command-add-existing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CmdParHlp, CommandNames, Commands } from '..';
import { ItemIdentifierGroup } from '../../../../$2sxc/src/cms';
import { ItemIdentifierInList } from '../../../../$2sxc/src/cms';
import { SharedLogic } from './shared-logic';

/**
Expand All @@ -16,16 +16,16 @@ Commands.add(CommandNames.addExisting, 'AddExisting', 'add-existing', false, tru
configureLinkGenerator: (context, linkGenerator) => {
if (SharedLogic.isFieldList(context)) {
const params = context.button.command.params;
linkGenerator.items = [{ Group: {
Guid: params.parent,
Part: params.fields,
Index: CmdParHlp.getIndex(params) + 1,
linkGenerator.items = [{
Add: true,
}}];
Index: CmdParHlp.getIndex(params) + 1,
Parent: params.parent,
Field: params.fields,
}];
} else if (SharedLogic.isPartOfBlockList(context)) {
const topItem = linkGenerator.items[0] as ItemIdentifierGroup;
topItem.Group.Add = true;
topItem.Group.Index++;
const topItem = linkGenerator.items[0] as ItemIdentifierInList;
topItem.Add = true;
topItem.Index++;
linkGenerator.items = [topItem];
}
},
Expand Down
10 changes: 5 additions & 5 deletions projects/inpage/src/commands/command/command-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const cmd = Command.build(CommandNames.list, 'Sort', 'list-numbered', false, tru
if (!SharedLogic.isFieldList(context)) return;

const params = context.button.command.params;
linkGenerator.items = [{ Group: {
Guid: params.parent,
Part: params.fields,
Index: CmdParHlp.getIndex(params),
linkGenerator.items = [{
Add: false,
}}];
Index: CmdParHlp.getIndex(params),
Parent: params.parent,
Field: params.fields,
}];
},
});

Expand Down
10 changes: 5 additions & 5 deletions projects/inpage/src/commands/command/command-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Commands.add(CommandNames.replace, 'Replace', 'replace', false, true, {

// fieldList - redefine the items
const params = context.button.command.params;
linkGenerator.items = [{ Group: {
Guid: params.parent,
Part: params.fields,
Index: CmdParHlp.getIndex(params),
linkGenerator.items = [{
Add: false,
}}];
Index: CmdParHlp.getIndex(params),
Parent: params.parent,
Field: params.fields,
}];
},
});
6 changes: 5 additions & 1 deletion projects/quick-dialog/src/app/core/backend-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class BackendSettings {

appId = new BehaviorSubject<number>(0);

data: Observable<ContextDto>
data: Observable<ContextDto>;

showAdvanced$: Observable<boolean>;

constructor(http: HttpClient) {
this.data = this.appId.pipe(
Expand All @@ -21,6 +23,8 @@ export class BackendSettings {
map(bundle => bundle.Context),
share()
);

this.showAdvanced$ = this.data.pipe(map(settings => settings.Enable?.CodeEditor ?? false));
}

setApp(id: number) {
Expand Down
5 changes: 5 additions & 0 deletions projects/quick-dialog/src/app/core/nameof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Inspired by https://schneidenbach.gitbooks.io/typescript-cookbook/content/nameof-operator.html

export const nameof = <T>(name: keyof T) => name;

export const nameofFactory = <T>() => (name: keyof T) => name;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ <h4>Debug 2sxc 14 Quick Dialog</h4>
<li>Apps: {{ (apps$ | async)?.length }}, current: {{app?.AppId }} </li>
<li>Templates: {{templates?.length}}, current: {{template?.TemplateId}}</li>
<li>Config: isContent='{{isContent}}' Ready: {{ready}} </li>
<li>Tab to show: '{{tabIndex}}' / preventTypeSwitch '{{preventTypeSwitch}}' / preventAppSwitch '{{preventAppSwich}}'</li>
<li>Tab to show: '{{tabIndex}}' / preventTypeSwitch '{{preventTypeSwitch}}' / preventAppSwitch '{{preventAppSwitch}}'</li>
<li>installerNeeded: {{installerNeeded}}, isInnerContent: {{isInnerContent}}, installerShow: {{installerShow}}, showInstallAndAllApps: {{showInstallAndAllApps}}</li>
</ul>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import { BackendSettings } from '../core/backend-settings';
import { CurrentDataService } from './current-data.service';
import { ContentTypesProcessor } from './data/content-types-processor.service';
import { PickerService } from './picker.service';
import { nameofFactory } from '../core/nameof';

const log = parentLog.subLog('picker', DebugConfig.picker.enabled);

const nameofTPC = nameofFactory<TemplatePickerComponent>();

@Component({
selector: 'app-template-picker',
templateUrl: './template-picker.component.html',
Expand All @@ -32,9 +35,6 @@ export class TemplatePickerComponent implements OnInit {
/** is in the main content-app or a generic app */
isContent: boolean;

/** show advanced features (admin/host only) */
private showAdvanced = false;

/** Needs the installer */
installerNeeded = false;

Expand Down Expand Up @@ -75,7 +75,7 @@ export class TemplatePickerComponent implements OnInit {
/** Ajax-support changes how saving/changing is handled */
private supportsAjax: boolean;

preventAppSwich = false;
preventAppSwitch = false;

public showDebug = DebugConfig.picker.showDebugPanel;

Expand Down Expand Up @@ -119,10 +119,6 @@ export class TemplatePickerComponent implements OnInit {

// Make sure we have the latest backend settings
this.backendSettings.setApp(dashInfo.appId);
this.backendSettings.data.subscribe(settings => {
this.showAdvanced = settings.Enable?.CodeEditor ?? false;
});

// start data-loading
this.api.initLoading(!dashInfo.isContent);

Expand Down Expand Up @@ -159,21 +155,33 @@ export class TemplatePickerComponent implements OnInit {
.subscribe(_ => this.switchTab());

// once the data is known, check if installer is needed
combineLatest([this.api.templates$,
combineLatest([
this.api.templates$,
this.api.contentTypes$,
this.api.apps$,
this.api.ready$.pipe(filter(r => !!r))])
this.api.ready$.pipe(filter(r => !!r)),
this.backendSettings.showAdvanced$
])
.pipe(
map(([templates, _, apps, _2]) => {
map(([templates, _, apps, _2, showAdv]) => {
log.add('apps/templates loaded, will check if we should show installer');
// Installer is needed on content without templates, or apps without any apps
this.installerNeeded = this.isContent
? templates.length === 0
: apps.length === 0;
this.installerShow = this.showAdvanced && this.installerNeeded && !this.isInnerContent;
this.installerShow = showAdv && this.installerNeeded && !this.isInnerContent;
this.showSearchBar = !this.installerNeeded;
this.showInstallAndAllApps = this.showAdvanced && (this.installerShow || !this.isContent);
this.showAdminApp = this.showAdvanced && !this.installerNeeded;
this.showInstallAndAllApps = showAdv && (this.installerShow || !this.isContent);
this.showAdminApp = showAdv && !this.installerNeeded;

log.add('Debug Relevant Properties', {
installerNeeded: this.installerNeeded,
showAdv: showAdv,
isInnerContent: this.isInnerContent,
installerShow: this.installerShow,
});

// if (this.showDebug) console.log('initObservables...combineLatest(...)', this);
}))
.subscribe();

Expand Down Expand Up @@ -216,11 +224,12 @@ export class TemplatePickerComponent implements OnInit {


private initValuesFromBridge(config: IQuickDialogConfig): void {
if (this.showDebug) console.log(`initValuesFromBridge(config)`, config);
this.preventTypeSwitch = config.hasContent;
this.isInnerContent = config.isInnerContent;
this.isContent = config.isContent;
this.supportsAjax = this.isContent || config.supportsAjax;
this.preventAppSwich = config.hasContent;
this.preventAppSwitch = config.hasContent;
this.showCancel = config.templateId != null;
}

Expand Down Expand Up @@ -280,8 +289,8 @@ export class TemplatePickerComponent implements OnInit {
// ajax-support can change as apps are changed; for ajax, maybe both the previous and new must support it
// or just new? still WIP
const ajax = newApp.SupportsAjaxReload;
log.add(`changing app to ${newApp.AppId}; prevent-switch: ${this.preventAppSwich} use-ajax:${ajax}`);
if (this.preventAppSwich) return;
log.add(`changing app to ${newApp.AppId}; prevent-switch: ${this.preventAppSwitch} use-ajax:${ajax}`);
if (this.preventAppSwitch) return;


this.loading$.next(true);
Expand Down