Skip to content

Commit

Permalink
Add serie data entry feature
Browse files Browse the repository at this point in the history
Fixes #545
  • Loading branch information
CarolineDenis committed Apr 17, 2024
1 parent f1c1404 commit 0680b87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Expand Up @@ -177,10 +177,7 @@ export type SpecifyResource<SCHEMA extends AnySchema> = {
viewUrl(): string;
isNew(): boolean;
isBeingInitialized(): boolean;
clone(
cloneAll: boolean,
bulkAmount: number
): Promise<SpecifyResource<SCHEMA>>;
clone(cloneAll: boolean): Promise<SpecifyResource<SCHEMA>>;
// eslint-disable-next-line @typescript-eslint/naming-convention
toJSON(): SerializedRecord<AnySchema>;
getRelatedObjectCount(
Expand Down
Expand Up @@ -134,9 +134,8 @@ export const ResourceBase = Backbone.Model.extend({
handleChanged() {
this.needsSaved = true;
},
async clone(cloneAll = false, bulkAmount = 1) {
async clone(cloneAll = false) {
const self = this;
console.log(bulkAmount);

const exemptFields = getFieldsToNotClone(this.specifyTable, cloneAll).map(
(fieldName) => fieldName.toLowerCase()
Expand Down
40 changes: 37 additions & 3 deletions specifyweb/frontend/js_src/lib/components/Forms/Save.tsx
Expand Up @@ -196,7 +196,9 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({
const copyButton = (
label: LocalizedString,
description: LocalizedString,
handleClick: () => Promise<SpecifyResource<SCHEMA>>
handleClick: () =>
| Promise<SpecifyResource<SCHEMA>[]>
| Promise<SpecifyResource<SCHEMA>>
): JSX.Element => (
<ButtonComponent
className={saveBlocked ? '!cursor-not-allowed' : undefined}
Expand All @@ -205,7 +207,18 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({
onClick={(): void => {
// Scroll to the top of the form on clone
smoothScroll(form, 0);
loading(handleClick().then(handleAdd));
// loading(handleClick().then(handleAdd));
loading(
handleClick().then((result) => {
if (Array.isArray(result)) {
result.forEach((newResource) => {
if (handleAdd) handleAdd(newResource);
});
} else {
if (handleAdd) handleAdd(result);
}
})
);
}}
>
{label}
Expand Down Expand Up @@ -240,7 +253,28 @@ export function SaveButton<SCHEMA extends AnySchema = AnySchema>({
copyButton(
formsText.carryForward(),
formsText.carryForwardDescription(),
async () => resource.clone(false, carryForwardAmount)
// async () => {
// return resource.clone(false);
// }
async () => {
const clones = [];
for (let i = 0; i < carryForwardAmount; i++) {
clones.push(
await resource
.clone(false)
.then(async (resource) => {
const formatter = resource.specifyTable
.strictGetLiteralField('catalogNumber')
.getUiFormatter()!;
const wildCard = formatter.valueOrWild();
await resource.set('catalogNumber', wildCard as never);
return resource;
})
.then((resource) => resource.save())
);
}
return clones;
}
)}
{showAdd &&
copyButton(
Expand Down

0 comments on commit 0680b87

Please sign in to comment.