Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Jun 12, 2024
1 parent 418acb0 commit 94cb474
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
9 changes: 6 additions & 3 deletions app/client/models/DocPageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface DocPageModel {
isTutorialFork: Observable<boolean>;
isTemplate: Observable<boolean>;

type: Observable<DocumentType|null>;
importSources: ImportSource[];

undoState: Observable<IUndoState|null>; // See UndoStack for details.
Expand Down Expand Up @@ -492,7 +493,8 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
const isFork = Boolean(idParts.forkId || idParts.snapshotId);
const isBareFork = isFork && idParts.trunkId === NEW_DOCUMENT_CODE;
const isSnapshot = Boolean(idParts.snapshotId);
const isTutorial = doc.type === 'tutorial';
const type = doc.type;
const isTutorial = type === 'tutorial';
const isTutorialTrunk = isTutorial && !isFork && mode !== 'default';
const isTutorialFork = isTutorial && isFork;

Expand All @@ -504,7 +506,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
// mode. Since the document's 'openMode' has no effect, don't bother trying
// to set it here, as it'll potentially be confusing for other code reading it.
openMode = 'default';
} else if (!isFork && doc.type === 'template') {
} else if (!isFork && type === 'template') {
// Templates should always open in fork mode by default.
openMode = 'fork';
} else {
Expand All @@ -514,7 +516,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
}

const isPreFork = openMode === 'fork';
const isTemplate = doc.type === 'template' && (isFork || isPreFork);
const isTemplate = type === 'template' && (isFork || isPreFork);
const isEditable = !isSnapshot && (canEdit(doc.access) || isPreFork);
return {
...doc,
Expand All @@ -526,6 +528,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
isSnapshot,
isTutorialTrunk,
isTutorialFork,
type,
isTemplate,
isReadonly: !isEditable,
idParts,
Expand Down
38 changes: 37 additions & 1 deletion app/client/ui/DocumentSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {EngineCode} from 'app/common/DocumentSettings';
import {commonUrls, GristLoadConfig} from 'app/common/gristUrls';
import {not, propertyCompare} from 'app/common/gutil';
import {getCurrency, locales} from 'app/common/Locales';
import {Computed, Disposable, dom, fromKo, IDisposableOwner, makeTestId, Observable, styled} from 'grainjs';
import {Computed, Disposable, dom, fromKo, IDisposableOwner, makeTestId, observable, Observable, styled} from 'grainjs';
import * as moment from 'moment-timezone';

const t = makeT('DocumentSettings');
Expand All @@ -40,6 +40,7 @@ export class DocSettingsPage extends Disposable {
private _timezone = this._docInfo.timezone;
private _locale: KoSaveableObservable<string> = this._docInfo.documentSettingsJson.prop('locale');
private _currency: KoSaveableObservable<string|undefined> = this._docInfo.documentSettingsJson.prop('currency');
// private _type: KoSaveableObservable<string|undefined> = this._docInfo.documentSettingsJson.prop('type');
private _engine: Computed<EngineCode|undefined> = Computed.create(this, (
use => use(this._docInfo.documentSettingsJson.prop('engine'))
))
Expand All @@ -58,6 +59,8 @@ export class DocSettingsPage extends Disposable {
const canChangeEngine = getSupportedEngineChoices().length > 0;
const docPageModel = this._gristDoc.docPageModel;
const isTimingOn = this._gristDoc.isTimingOn;
const typeModel = observable(null);
docPageModel.getDocType().then((type) => typeModel.set(type));

return cssContainer(
dom.create(AdminSection, t('Document Settings'), [
Expand Down Expand Up @@ -189,6 +192,14 @@ export class DocSettingsPage extends Disposable {
value: cssSmallLinkButton(t('Manage webhooks'), urlState().setLinkUrl({docPage: 'webhook'})),
}),
]),
dom.create(AdminSection, t('Document conversion'), [
dom.create(AdminSectionItem, {
id: 'document-type',
name: t('Document type'),
description: t('Convert the document'),
})
// value: dom.create(buildTypeSelect, this._type),
]),
);
}

Expand Down Expand Up @@ -338,6 +349,31 @@ function buildLocaleSelect(
);
}

function buildTypeSelect(
owner: IDisposableOwner,
type: KoSaveableObservable<string>
) {
const typeList: ACSelectItem[] = [{
value: '',
label: t('Regular')
}, {
value: 'template',
label: t('Template')
},
{
value: 'tutorial',
label: t('Tutorial')
}].map((el) => el.label.trim().toLowerCase());
const valueObs = Computed.create(owner, use => use(type));
const acIndex = new ACIndexImpl<LocaleItem>(typeList, {maxResults: 200, keepOrder: true});
return buildACSelect(owner, {
acIndex, valueObs,
save(_value, item: ACSelectItem|undefined) {
type.saveOnly(item?.value ?? '').catch(reportError);
}
});
}

const cssContainer = styled('div', `
overflow-y: auto;
position: relative;
Expand Down

0 comments on commit 94cb474

Please sign in to comment.