Skip to content

Commit

Permalink
Add Opex export bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Feb 18, 2023
1 parent 8affacf commit 714460c
Show file tree
Hide file tree
Showing 17 changed files with 347 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
- beta
- release
workflow_dispatch:

jobs:
Expand Down
11 changes: 9 additions & 2 deletions app/components/ImdiView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Folder } from "../model/Folder/Folder";
import ImdiGenerator from "../export/ImdiGenerator";
import ImdiGenerator, { IMDIMode } from "../export/ImdiGenerator";
import { Session } from "../model/Project/Session/Session";
import { Project } from "../model/Project/Project";
import { Person } from "../model/Project/Person/Person";
Expand Down Expand Up @@ -43,19 +43,25 @@ export default class ImdiView extends React.Component<IProps, IState> {

if (this.props.target instanceof Session) {
xml = ImdiGenerator.generateSession(
IMDIMode.OPEX,
this.props.target as Session,
this.props.project
);
} else if (this.props.target instanceof Project) {
xml =
ImdiGenerator.generateCorpus(
IMDIMode.RAW_IMDI,
this.props.target as Project,
new Array<string>() /* we don't bother to compute the children IMDI's for this view */
) + // I want to see how some of this project info is going to show up inside of sessions
"\r\n\r\n-- This project-related info will show up in the IMDI of sessions -- \r\n" +
ImdiGenerator.generateProject(this.props.target as Project);
ImdiGenerator.generateProject(
IMDIMode.RAW_IMDI,
this.props.target as Project
);
} else if (this.props.target instanceof Person) {
const generator = new ImdiGenerator(
IMDIMode.RAW_IMDI,
this.props.target,
this.props.project
);
Expand All @@ -66,6 +72,7 @@ export default class ImdiView extends React.Component<IProps, IState> {
) as string;
} else if (this.props.target instanceof File) {
const generator = new ImdiGenerator(
IMDIMode.RAW_IMDI,
this.props.folder,
this.props.project
);
Expand Down
10 changes: 5 additions & 5 deletions app/components/export/ExportChoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ export const ExportChoices: React.FunctionComponent<{
<input
type="radio"
name="format"
value="imdi-plus-files"
checked={props.exportFormat === "imdi-plus-files"}
value="opex-plus-files"
checked={props.exportFormat === "opex-plus-files"}
onChange={(e) => props.setExportFormat(e.target.value)}
/>
<Trans>IMDI + Files</Trans>
<Trans>OPEX + Files</Trans>
</label>
<p>
<Trans>
A folder containing both the IMDI files and all the project's
archivable files.
A folder containing all the project's archivable files, with IMDI
wrapped for OPEX.
</Trans>
</p>
</fieldset>
Expand Down
10 changes: 6 additions & 4 deletions app/components/export/ExportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CopyManager, ICopyJob } from "../../other/CopyManager";
import { useInterval } from "../UseInterval";
import userSettingsSingleton from "../../other/UserSettings";
import { DialogButton } from "../LametaDialog";
import { IMDIMode } from "../../export/ImdiGenerator";

const saymore_orange = "#e69664";
const { app } = require("@electron/remote");
Expand Down Expand Up @@ -71,8 +72,7 @@ export const ExportDialog: React.FunctionComponent<{
const [countOfMarkedSessions, setCountOfMarkedSessions] = useState(0);
React.useEffect(() => {
if (props.projectHolder && props.projectHolder.project) {
const count =
props.projectHolder!.project!.sessions.countOfMarkedFolders();
const count = props.projectHolder!.project!.sessions.countOfMarkedFolders();
setCountOfMarkedSessions(count);
// guess what they will want based on if they have checked anything
setWhichSessionsOption(count === 0 ? "all" : "marked");
Expand Down Expand Up @@ -237,13 +237,14 @@ export const ExportDialog: React.FunctionComponent<{
ImdiBundler.saveImdiBundleToFolder(
props.projectHolder.project!,
path,
IMDIMode.OPEX,
false,
folderFilter
);
setMode(Mode.finished); // don't have to wait for any copying of big files
break;
case "imdi-plus-files":
analyticsEvent("Export", "Export IMDI Plus Files");
case "opex-plus-files":
analyticsEvent("Export", "Export OPEX Plus Files");
if (CopyManager.filesAreStillCopying()) {
NotifyWarning(
t`lameta cannot export files while files are still being copied in.`
Expand All @@ -253,6 +254,7 @@ export const ExportDialog: React.FunctionComponent<{
ImdiBundler.saveImdiBundleToFolder(
props.projectHolder.project!,
path,
IMDIMode.OPEX,
true,
folderFilter
).then(() => {
Expand Down
77 changes: 77 additions & 0 deletions app/export/ImdiBundler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as temp from "temp";
import { Project } from "../model/Project/Project";
import { Session } from "../model/Project/Session/Session";
import ImdiBundler from "./ImdiBundler";
import { IMDIMode } from "./ImdiGenerator";
import fs from "fs";
import * as Path from "path";
jest.mock("@electron/remote", () => ({ exec: jest.fn() })); //See commit msg for info

let project: Project;
let session: Session;
const projectDir = temp.mkdirSync("lameta imdi bundler test");
const projectName = Path.basename(projectDir);
const targetDir = temp.mkdirSync("lameta imdi bundler test output");
beforeAll(() => {
temp.track();
project = Project.fromDirectory(projectDir);
project.descriptionFolder.addFileForTest("test.txt");
project.otherDocsFolder.addFileForTest("test.txt");
session = project.addSession();
ImdiBundler.saveImdiBundleToFolder(
project,
targetDir,
IMDIMode.OPEX,
false,
(f) => true
);
});
afterAll(() => {
temp.cleanupSync();
});

describe("opex file placement", () => {
it("should have a project opex inside of the project folder", () => {
const p = Path.join(targetDir, projectName, projectName + ".opex"); //?
expect(fs.existsSync(p)).toBe(true);
});
/* this would just be too expensive to set up at this point
it("should have a consent opex inside of the Consent folder", () => {
const p = Path.join(
targetDir,
projectName,
"ConsentDocuments",
"ConsentDocuments.opex"
); //?
expect(fs.existsSync(p)).toBe(true);
});
*/
it("should have a DescriptionDocuments opex inside of the Description folder", () => {
const p = Path.join(
targetDir,
projectName,
"DescriptionDocuments",
"DescriptionDocuments.opex"
);
expect(fs.existsSync(p)).toBe(true);
});
it("should have a OtherDocuments opex inside of the OtherDocuments folder", () => {
const p = Path.join(
targetDir,
projectName,
"OtherDocuments",
"OtherDocuments.opex"
);
expect(fs.existsSync(p)).toBe(true);
});
it("should have a session opex inside of the session folder", () => {
const p = Path.join(
targetDir,
projectName,
"New Session",
"New_Session.opex"
);
expect(fs.existsSync(p)).toBe(true);
});
});

0 comments on commit 714460c

Please sign in to comment.