Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
biaogebusy committed Nov 27, 2024
2 parents 1dafde4 + a29546e commit 02aabe4
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"ts-node": "~8.3.0",
"tslib": "^2.3.1",
"tslint": "~6.1.0",
"typescript": "^5.4.5",
"typescript": "5.4.5",
"typescript-eslint": "8.10.0",
"utf-8-validate": "^5.0.7",
"webpack": "^5.91.0",
Expand Down
28 changes: 9 additions & 19 deletions src/app/core/factory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CookieService } from 'ngx-cookie-service';
import { ComponentService } from '@core/service/component.service';
import { inject } from '@angular/core';
import { IBuilderConfig } from '@core/interface/IBuilder';
import { BuilderService } from '@core/service/builder.service';

export const THEMKEY = 'themeMode';
export const DEBUG_ANIMATE_KEY = 'debugAnimate';
Expand Down Expand Up @@ -69,17 +70,16 @@ export function builderCurrentPageFactory(
const versionKey = 'version';
const currentPage$ = new BehaviorSubject<IPage | object | boolean>(false);
const localVersion = storage.retrieve(versionKey);
const builderService = inject(BuilderService);
if (localVersion) {
const currentPage = localVersion.find(
(page: IPage) => page.current === true
);
const currentPage = localVersion.find((page: IPage) => page.current === true);
builderService.checkIsLatestPage(currentPage);
currentPage$.next(currentPage);
}

storage.observe(versionKey).subscribe((version: IPage[]) => {
if (version.length > 0) {
const current =
version.find((page: IPage) => page.current === true) || version[0];
const current = version.find((page: IPage) => page.current === true) || version[0];
currentPage$.next(current);
}
});
Expand All @@ -96,10 +96,7 @@ export function isBuilderModeFactory(router: Router): Observable<boolean> {
}
router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
if (
router.url.includes(BUILDERPATH) &&
router.url !== '/builder/preview'
) {
if (router.url.includes(BUILDERPATH) && router.url !== '/builder/preview') {
isBuilderMode$.next(true);
} else {
isBuilderMode$.next(false);
Expand Down Expand Up @@ -132,9 +129,7 @@ export function debugAnimateFactory(): Observable<boolean> {
return debugAnimate$;
}

export function notifyFactory(
coreConfig: ICoreConfig
): Observable<INotify[] | object | boolean> {
export function notifyFactory(coreConfig: ICoreConfig): Observable<INotify[] | object | boolean> {
const notifyService = inject(NotifyService);
const $notify = new BehaviorSubject<INotify[] | object | boolean>(false);
const apis = coreConfig?.notify?.api;
Expand Down Expand Up @@ -201,17 +196,12 @@ export function langFactory(): ILanguage | undefined {
}
}

export function themeFactory(
coreConfig: ICoreConfig,
storage: LocalStorageService
): string {
export function themeFactory(coreConfig: ICoreConfig, storage: LocalStorageService): string {
const defaultTheme = coreConfig.defaultTheme || 'blue-theme';
const localTheme = storage.retrieve(THEMKEY);
if (localTheme && coreConfig.theme) {
// checkout the theme is removed
const isInThemeList = coreConfig.theme.filter(
item => item.style === localTheme
);
const isInThemeList = coreConfig.theme.filter(item => item.style === localTheme);
if (isInThemeList.length) {
return localTheme;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/interface/IBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface IPageMeta {
title: string;
url: string;
cover?: string;
taxonomy?: string;
}

export interface IBuilderMenu extends ILink {
Expand Down
15 changes: 15 additions & 0 deletions src/app/core/service/builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ export class BuilderService extends ApiService {
});
}

checkIsLatestPage(page: IPage): void {
const { langcode, nid, changed, uuid, title } = page;
if (nid && changed && uuid) {
const lang = this.getApiLang(langcode);
this.nodeService
.fetch(`/api/v3/landingPage/json/${nid}`, 'noCache=1', '', lang)
.subscribe((page: IPage) => {
console.log(page);
if (Number(changed) < Number(page.changed)) {
this.util.openSnackbar(`当前${title}页面不是最新版本!`, 'ok');
}
});
}
}

loadNodeJson(page: { langcode?: string; nid: string; uuid: string }): void {
this.builder.loading$.next(true);
const { langcode, nid, uuid } = page;
Expand Down
24 changes: 9 additions & 15 deletions src/app/core/state/BuilderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ export class BuilderState {
}

setCurrentPage(page: IPage): void {
const currentIndex = this.version.findIndex(
(item: IPage) => item.current === true
);
const currentIndex = this.version.findIndex((item: IPage) => item.current === true);
this.version[currentIndex] = page;
this.storage.store(this.versionKey, Object.assign([], this.version));
}
Expand Down Expand Up @@ -244,15 +242,15 @@ export class BuilderState {
}

loadNewPage(page: IPage): void {
const currentPage = { ...page, current: true, time: new Date() }
const currentPage = { ...page, current: true, time: new Date() };
let somePageIndex = -1;
this.version.forEach(version => (version.current = false));
somePageIndex = this.version.findIndex(item => {
return item.uuid === page.uuid && item.langcode === page.langcode;
})
if(somePageIndex > -1){
this.version[somePageIndex] = currentPage
}else{
});
if (somePageIndex > -1) {
this.version[somePageIndex] = currentPage;
} else {
this.version.unshift(currentPage);
}

Expand All @@ -267,13 +265,13 @@ export class BuilderState {
pageIndex,
content,
path,
fullWidth: true
fullWidth: true,
};
this.rightContent$.next({
mode: 'over',
hasBackdrop: false,
style: {
width: '318px',
'width': '318px',
'max-width': 'calc(100vw - 50px)',
},
elements: [data],
Expand Down Expand Up @@ -306,11 +304,7 @@ export class BuilderState {
return result;
}

getRandomElements(
data: IBuilderComponent[],
id: string,
count: number
): any[] {
getRandomElements(data: IBuilderComponent[], id: string, count: number): any[] {
const elements = data.find(item => item.id === id)?.elements || [];
// 如果元素中包含 content.child,则将其元素也添加到结果中
const result = elements.reduce((acc: any[], element: any) => {
Expand Down
29 changes: 11 additions & 18 deletions src/app/modules/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
AfterViewInit,
} from '@angular/core';
import { BuilderState } from '@core/state/BuilderState';
import {
BUILDER_FULL_SCREEN,
IS_BUILDER_MODE,
} from '@core/token/token-providers';
import { BUILDER_FULL_SCREEN, IS_BUILDER_MODE } from '@core/token/token-providers';
import { MatDrawer } from '@angular/material/sidenav';
import { Observable } from 'rxjs';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
Expand Down Expand Up @@ -40,23 +37,19 @@ export class BuilderComponent implements OnInit, AfterViewInit {
}

ngOnInit(): void {
this.builder.rightContent$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(content => {
if (content) {
setTimeout(() => {
this.builderRightDrawer.open();
}, 100);
}
});
this.builder.rightContent$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(content => {
if (content) {
setTimeout(() => {
this.builderRightDrawer.open();
}, 100);
}
});
}

ngAfterViewInit(): void {
this.builder.closeRightDrawer$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.onClose();
});
this.builder.closeRightDrawer$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.onClose();
});
}

get drawerStyle(): object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
ChangeDetectionStrategy,
Component,
Inject,
Input,
OnInit,
inject,
} from '@angular/core';
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit, inject } from '@angular/core';
import { IBranding } from '@core/interface/branding/IBranding';
import { BuilderState } from '@core/state/BuilderState';
import { BRANDING, BUILDER_CONFIG } from '@core/token/token-providers';
Expand All @@ -14,7 +7,6 @@ import { DialogComponent } from '@uiux/widgets/dialog/dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { ManageService } from '@core/service/manage.service';
import { IBuilderConfig } from '@core/interface/IBuilder';
import { ContentService } from '@core/service/content.service';
import { MatDrawer } from '@angular/material/sidenav';

@Component({
Expand Down Expand Up @@ -44,7 +36,7 @@ export class BuilderSidebarComponent implements OnInit {
inputData: {
content: {
type: 'manage-media',
fullWidth: true
fullWidth: true,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatDialog } from '@angular/material/dialog';
import { IPage } from '@core/interface/IAppConfig';
import { BuilderService } from '@core/service/builder.service';
import { BuilderState } from '@core/state/BuilderState';
import { DialogComponent } from '@uiux/widgets/dialog/dialog.component';
import { LocalStorageService } from 'ngx-webstorage';
Expand All @@ -27,6 +28,7 @@ export class BuilderVersionComponent implements OnInit {
builder = inject(BuilderState);
storage = inject(LocalStorageService);
private destroyRef = inject(DestroyRef);
builderService = inject(BuilderService);
ngOnInit(): void {
this.version = this.storage.retrieve('version');
this.storage
Expand Down Expand Up @@ -68,6 +70,7 @@ export class BuilderVersionComponent implements OnInit {
this.builder.closeRightDrawer$.next(true);
this.builder.fixedShowcase = false;
this.builder.showcase$.next(false);
this.builderService.checkIsLatestPage(page);
}

onClickTitle(event: MouseEvent): any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@
/>
</div>
<div class="meta text-xs font-mono">
{{ page.author | shorten: 6 : '**' }}
<div class="flex justify-between my-2 items-center">
{{ page.author | shorten: 6 : '**' }}
@if (page.taxonomy) {
<span class="bg-gray-300 rounded-2xl py-1 px-2 leading-none">{{
page.taxonomy
}}</span>
}
</div>
<div class="flex justify-between mt-2">
<a
class="truncate"
Expand Down
6 changes: 4 additions & 2 deletions src/app/modules/manage/taxonomy/taxonomy.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<mat-list>
<div mat-subheader>{{ content.title }}</div>
@if (items) {
@for (item of items.data; track item.id) {
@for (item of items.data; track item.id; let last = $last) {
@let attr = item.attributes;
<mat-list-item lines="3">
<mat-icon matListItemIcon>folder</mat-icon>
Expand Down Expand Up @@ -46,7 +46,9 @@
</div>
</div>
</mat-list-item>
<mat-divider></mat-divider>
@if (!last) {
<mat-divider></mat-divider>
}
}
}
</mat-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
[form]="form"
[model]="model"
[fields]="content.form"
(modelChange)="onModelChange($event)" />
(modelChange)="onModelChange($event)"
/>
}
@if (content.params?.api) {
<app-icon (click)="reload()" [content]="{ svg: 'reload' }" />
}
</div>
</div>
}
<app-dynamic-component
[inputs]="{ content: widget$ | async }" />
<app-dynamic-component [inputs]="{ content: widget$ | async }" />
@if (loading) {
<div class="loading-inner">
<mat-spinner diameter="50" />
Expand Down

0 comments on commit 02aabe4

Please sign in to comment.