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

Feature/wysiwyg editor #248

Merged
merged 2 commits into from
Mar 20, 2024
Merged
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
11 changes: 11 additions & 0 deletions src/cms/api/forms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getTestingContext } from '../util/testing';
import { getForm } from './forms';

const ctx = getTestingContext();

it('form tests', () => {
// describe('form should render test boxes', async () => {
// const form = await getForm(ctx, 'posts');
// expect(form).toBeNull();
// });
});
25 changes: 25 additions & 0 deletions src/cms/api/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ export function getForm(ctx: AppContext, table) {
}
]
};
} else if (formField.metaType == 'ckeditor') {
const c = formField;
formField = {
label: c.label || c.key,
editor: 'ckeditor',
customClass: 'pl-4 pr-4',
tableView: true,
key: c.key,
type: 'textarea',
input: true,
isUploadEnabled: false
};
} else if (formField.metaType == 'quill') {
const c = formField;
formField = {
label: c.label || c.key,
editor: 'quill',
customClass: 'pl-4 pr-4',
tableView: true,
key: c.key,
type: 'textarea',
rows: 3,
input: true,
isUploadEnabled: false
};
}
formFields.push(formField);
}
Expand Down
27 changes: 25 additions & 2 deletions src/cms/util/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,30 @@ import { drizzle } from 'drizzle-orm/d1';
import { createUser } from '../auth/lucia';
import { getD1DataByTable } from '../data/d1-data';

export async function createUserAndGetToken(app, ctx, email= '[email protected]', password = 'password123', role = 'admin') {
export async function getTestingContext() {
const { __D1_BETA__D1DATA, KVDATA } = getMiniflareBindings();

const toJson = function (json) {
return json;
};

const ctx = {
env: { KVDATA: KVDATA, D1DATA: __D1_BETA__D1DATA },
json: toJson,
user: { id: 'fromtest' },
_var: { user: { userId: 'abc123' } }
};

return ctx;
}

export async function createUserAndGetToken(
app,
ctx,
email = '[email protected]',
password = 'password123',
role = 'admin'
) {
await createUserTestTables(ctx);

//TODO: create user properly using the lucia api so that the user keys data in populated
Expand Down Expand Up @@ -42,7 +65,7 @@ export async function createUserAndGetToken(app, ctx, email= '[email protected]', password
expect(res.status).toBe(200);
let body = await res.json();
expect(body.bearer.length).toBeGreaterThan(10);
return {id: result.user.userId, token:body.bearer};
return { id: result.user.userId, token: body.bearer };
}

export async function createUserTestTables(ctx) {
Expand Down
9 changes: 9 additions & 0 deletions src/db/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ export interface ApiConfig {
type: 'file' | 'file[]';
bucket: (ctx: AppContext) => R2Bucket;
path?: string | ((ctx: AppContext) => string);
}
| {
type: 'password';
}
| {
type: 'ckeditor';
}
| {
type: 'quill';
};
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/db/schema/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@ export const fields: ApiConfig['fields'] = {
},
tags: {
type: 'string[]'
},
body: {
type: 'ckeditor'
}
};
Loading