add idx to have stable order
This commit is contained in:
parent
1d4967a8d8
commit
3840bb585c
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- mariadb / mysql support (fixes https://github.com/ohmyform/ohmyform/issues/143)
|
||||
- user confirmation tokens
|
||||
- email verification
|
||||
- idx for fields and logic to have stable order
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@ -37,7 +37,8 @@ ENV PORT=3000 \
|
||||
CREATE_ADMIN=FALSE \
|
||||
ADMIN_EMAIL=admin@ohmyform.com \
|
||||
ADMIN_USERNAME=root \
|
||||
ADMIN_PASSWORD=root
|
||||
ADMIN_PASSWORD=root \
|
||||
NODE_ENV=production
|
||||
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
Your Username is {{username}}
|
||||
</mj-text>
|
||||
|
||||
<mj-text font-size="14px" color="#444" font-family="helvetica">
|
||||
<a href="{{confirm}}">Click here to verify your Account</a>
|
||||
</mj-text>
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
</mj-body>
|
||||
|
||||
@ -17,6 +17,9 @@ export class FormFieldInput {
|
||||
@Field({ nullable: true })
|
||||
readonly slug?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
readonly idx?: number
|
||||
|
||||
@Field()
|
||||
readonly description: string
|
||||
|
||||
|
||||
@ -13,6 +13,9 @@ export class FormFieldLogicInput {
|
||||
@Field(() => String, { nullable: true })
|
||||
readonly action: FormFieldLogicAction
|
||||
|
||||
@Field({ nullable: true })
|
||||
readonly idx?: number
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
readonly jumpTo?: string
|
||||
|
||||
|
||||
@ -12,6 +12,9 @@ export class FormFieldLogicModel {
|
||||
@Field()
|
||||
readonly action: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
readonly idx?: number
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
readonly jumpTo?: string
|
||||
|
||||
@ -34,6 +37,7 @@ export class FormFieldLogicModel {
|
||||
this.formula = document.formula
|
||||
this.jumpTo = document.jumpTo?.id.toString()
|
||||
|
||||
this.idx = document.idx
|
||||
this.action = document.action
|
||||
this.visible = document.visible
|
||||
this.disable = document.disable
|
||||
|
||||
@ -15,6 +15,9 @@ export class FormFieldModel {
|
||||
@Field({ nullable: true })
|
||||
readonly slug?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
readonly idx: number
|
||||
|
||||
@Field()
|
||||
readonly type: string
|
||||
|
||||
@ -38,6 +41,7 @@ export class FormFieldModel {
|
||||
|
||||
constructor(document: FormFieldEntity) {
|
||||
this.id = document.id.toString()
|
||||
this.idx = document.idx
|
||||
this.title = document.title
|
||||
this.slug = document.slug
|
||||
this.type = document.type
|
||||
|
||||
@ -21,6 +21,9 @@ export class FormFieldEntity {
|
||||
@Column({ nullable: true })
|
||||
public slug?: string
|
||||
|
||||
@Column({ nullable: true })
|
||||
public idx?: number
|
||||
|
||||
@OneToMany(() => FormFieldLogicEntity, logic => logic.field, { eager: true, orphanedRowAction: 'delete', cascade: true })
|
||||
public logic: FormFieldLogicEntity[]
|
||||
|
||||
|
||||
@ -14,6 +14,9 @@ export class FormFieldLogicEntity {
|
||||
@Column()
|
||||
public formula: string
|
||||
|
||||
@Column({ nullable: true })
|
||||
public idx?: number
|
||||
|
||||
@Column({ type: 'varchar', length: 10 })
|
||||
public action: FormFieldLogicAction
|
||||
|
||||
|
||||
15
src/migrations/mariadb/1641151802308-idx.ts
Normal file
15
src/migrations/mariadb/1641151802308-idx.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class idx1641151802308 implements MigrationInterface {
|
||||
name = 'idx1641151802308'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('ALTER TABLE `form_field_logic` ADD `idx` int NULL');
|
||||
await queryRunner.query('ALTER TABLE `form_field` ADD `idx` int NULL');
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('ALTER TABLE `form_field` DROP COLUMN `idx`');
|
||||
await queryRunner.query('ALTER TABLE `form_field_logic` DROP COLUMN `idx`');
|
||||
}
|
||||
}
|
||||
15
src/migrations/postgres/1641151802308-idx.ts
Normal file
15
src/migrations/postgres/1641151802308-idx.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class idx1641151802308 implements MigrationInterface {
|
||||
name = 'idx1641151802308'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('ALTER TABLE "form_field_logic" ADD "idx" integer');
|
||||
await queryRunner.query('ALTER TABLE "form_field" ADD "idx" integer');
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('ALTER TABLE "form_field" DROP COLUMN "idx"');
|
||||
await queryRunner.query('ALTER TABLE "form_field_logic" DROP COLUMN "idx"');
|
||||
}
|
||||
}
|
||||
27
src/migrations/sqlite/1641151802308-idx.ts
Normal file
27
src/migrations/sqlite/1641151802308-idx.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class idx1641151802308 implements MigrationInterface {
|
||||
name = 'idx1641151802308'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('CREATE TABLE "temporary_form_field_logic" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "formula" varchar NOT NULL, "action" varchar(10) NOT NULL, "visible" boolean, "require" boolean, "disable" boolean, "enabled" boolean NOT NULL, "fieldId" integer, "jumpToId" integer, "idx" integer, CONSTRAINT "FK_4a8019f2b753cfb3216dc3001a6" FOREIGN KEY ("jumpToId") REFERENCES "form_field" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_6098b83f6759445d8cfdd03d545" FOREIGN KEY ("fieldId") REFERENCES "form_field" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)');
|
||||
await queryRunner.query('INSERT INTO "temporary_form_field_logic"("id", "formula", "action", "visible", "require", "disable", "enabled", "fieldId", "jumpToId") SELECT "id", "formula", "action", "visible", "require", "disable", "enabled", "fieldId", "jumpToId" FROM "form_field_logic"');
|
||||
await queryRunner.query('DROP TABLE "form_field_logic"');
|
||||
await queryRunner.query('ALTER TABLE "temporary_form_field_logic" RENAME TO "form_field_logic"');
|
||||
await queryRunner.query('CREATE TABLE "temporary_form_field" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar NOT NULL, "description" text NOT NULL, "slug" varchar, "required" boolean NOT NULL, "disabled" boolean NOT NULL, "type" varchar NOT NULL, "value" varchar NOT NULL, "formId" integer, "ratingSteps" integer, "ratingShape" varchar, "idx" integer, CONSTRAINT "FK_2d83d8a334dd66445db13f92b77" FOREIGN KEY ("formId") REFERENCES "form" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)');
|
||||
await queryRunner.query('INSERT INTO "temporary_form_field"("id", "title", "description", "slug", "required", "disabled", "type", "value", "formId", "ratingSteps", "ratingShape") SELECT "id", "title", "description", "slug", "required", "disabled", "type", "value", "formId", "ratingSteps", "ratingShape" FROM "form_field"');
|
||||
await queryRunner.query('DROP TABLE "form_field"');
|
||||
await queryRunner.query('ALTER TABLE "temporary_form_field" RENAME TO "form_field"');
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('ALTER TABLE "form_field" RENAME TO "temporary_form_field"');
|
||||
await queryRunner.query('CREATE TABLE "form_field" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar NOT NULL, "description" text NOT NULL, "slug" varchar, "required" boolean NOT NULL, "disabled" boolean NOT NULL, "type" varchar NOT NULL, "value" varchar NOT NULL, "formId" integer, "ratingSteps" integer, "ratingShape" varchar, CONSTRAINT "FK_2d83d8a334dd66445db13f92b77" FOREIGN KEY ("formId") REFERENCES "form" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)');
|
||||
await queryRunner.query('INSERT INTO "form_field"("id", "title", "description", "slug", "required", "disabled", "type", "value", "formId", "ratingSteps", "ratingShape") SELECT "id", "title", "description", "slug", "required", "disabled", "type", "value", "formId", "ratingSteps", "ratingShape" FROM "temporary_form_field"');
|
||||
await queryRunner.query('DROP TABLE "temporary_form_field"');
|
||||
await queryRunner.query('ALTER TABLE "form_field_logic" RENAME TO "temporary_form_field_logic"');
|
||||
await queryRunner.query('CREATE TABLE "form_field_logic" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "formula" varchar NOT NULL, "action" varchar(10) NOT NULL, "visible" boolean, "require" boolean, "disable" boolean, "enabled" boolean NOT NULL, "fieldId" integer, "jumpToId" integer, CONSTRAINT "FK_4a8019f2b753cfb3216dc3001a6" FOREIGN KEY ("jumpToId") REFERENCES "form_field" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_6098b83f6759445d8cfdd03d545" FOREIGN KEY ("fieldId") REFERENCES "form_field" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)');
|
||||
await queryRunner.query('INSERT INTO "form_field_logic"("id", "formula", "action", "visible", "require", "disable", "enabled", "fieldId", "jumpToId") SELECT "id", "formula", "action", "visible", "require", "disable", "enabled", "fieldId", "jumpToId" FROM "temporary_form_field_logic"');
|
||||
await queryRunner.query('DROP TABLE "temporary_form_field_logic"');
|
||||
}
|
||||
}
|
||||
@ -61,6 +61,10 @@ export class FormUpdateService {
|
||||
field.description = nextField.description
|
||||
}
|
||||
|
||||
if (nextField.idx !== undefined) {
|
||||
field.idx = nextField.idx
|
||||
}
|
||||
|
||||
if (nextField.disabled !== undefined) {
|
||||
field.disabled = nextField.disabled
|
||||
}
|
||||
@ -90,6 +94,9 @@ export class FormUpdateService {
|
||||
if (nextLogic.formula !== undefined) {
|
||||
logic.formula = nextLogic.formula
|
||||
}
|
||||
if (nextLogic.idx !== undefined) {
|
||||
logic.idx = nextLogic.idx
|
||||
}
|
||||
if (nextLogic.action !== undefined) {
|
||||
logic.action = nextLogic.action
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user