Skip to content
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ see the notices in the README.

### Added

- **Check out several parts of an assembly at once** (#415): `POST /api/v1/checkouts`
takes a list of revisions (by id, or item and code) and checks them out in one
transaction with a result per revision – the ones that can be taken are checked
out, the rest are reported with a reason (`not_found`, `released`, `in_review`,
`locked`, `forbidden`), so one released or locked part does not stop the others.
The rows are locked in a fixed order, so overlapping batches cannot deadlock and
every revision has one winner; each changed revision gets its own
`revision.checkout` audit record. A server batch rather than one call per part:
one round trip and one consistent moment for the whole set, with the rules of
the single check-out in one place. TeamCraft Desktop: *Check out parts…* on an
assembly (revision toolbar and *Structure* tab) shows the structure as a tree
with check boxes, state and lock holder (parts that cannot be checked out are
disabled with the reason), checks out the ticked ones in one step, makes their
files in the working folder writable and lists what was refused.
- **BOM components picked by search** (#419, UX B5 of #408): *Add component*
on the web BOM card lists matching items as you type part of their number,
name or file name – with the preview image from the CAD file, latest
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ end-to-end tests against a real PostgreSQL.
**Files and versions**

- **Check-out / check-in** – exclusive locks per revision; a check-in based on
an outdated version is refused instead of overwriting it.
an outdated version is refused instead of overwriting it. Several parts of an
assembly can be checked out in one step to edit them in its context
(`POST /api/v1/checkouts`, a result per part).
- **Versions and rollback** – every upload is a new version; download or
restore any of them, history is never rewritten.
- **Vault explorer** – project groups as folders with lock owners, files and
Expand Down
1 change: 1 addition & 0 deletions desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TeamCraft server – it is a client, not an offline copy.
| SolidCraft design properties | The Files tab shows the `properties_line` the server sends with a design's file record under its name and the server's `property_mismatches` as the notice *Design properties differ from this revision* (`ui/js/revision.js` `propertyMismatchNotice`); *New item* from local files (`ui/js/dialogs.js` `createItemFromFiles`) and *Import a CAD folder* fill an empty description from the uploaded design's `properties.description` while the item is still checked out (`ui/js/folder-import.js` `describeFromDesign`, best effort) – #367 |
| SolidCraft plugin bridge | The TeamCraft plugin inside SolidCraft has no network, so the app shares `<workspace>/.teamcraft/solidcraft` with it (`src/scbridge.rs`, `ui/js/solidcraft-bridge.js`): every 30 s a heartbeat (`desktop.json`: the app runs, the server answers), on every Workspace refresh the state of the revision (`state-<key>.json`: checked out by, local changes, released), every 5 s the plugin's requests (`request-<key>.<action>.json`, one per revision and action) are picked up, checked (a revision of this working folder, a known action, fresh, small, a regular file) and removed: *open* shows the revision, *check out* asks first, *check in* opens the check-in dialog. Only for a working folder that exists; no secrets in the folder |
| Check out and open | *Check out and open* on the revision toolbar (*Open in CAD* for one's own check-out) takes the lock, gets the files and opens the main CAD file; the chip next to it names the program (e.g. *Inventor 2026*). The program: the project group's default CAD program (`default_cad`, `default_cad_version` of `GET /api/v1/projects`) in its version, else its newest installed version; without a default, or for a file of another program, the newest installed version of the program that fits the file (`format_info.family`); else the system's default application. Installed programs are found by their install folders (Windows *Program Files*, SOLIDWORKS via `reg query`; macOS `/Applications`; FreeCAD on the Linux `PATH`), once per start – `src/cadlaunch.rs`, `ui/js/cad-open.js`; *Open* in the Files tab uses the same choice. On Windows an Inventor that already runs – the chosen installation, with the working folder's Inventor project active (the `.ipj` in the nearest folder up to the working folder root) – opens the file as a new window instead of a second instance (#350; asked through COM by a Windows PowerShell script: `GetActiveObject`, `InstallPath`, `ActiveDesignProject`, `Documents.Open`); otherwise a new instance starts and the message says why. After *Cancel* during the download, or with files that could not be copied, nothing is opened (#348, `ui/js/get-rules.js`). *Import CAD folder* detects the folder's program (Inventor with the release year read from the files, `folderimport::inventor_year`) and offers to set it as the group's default |
| Check out parts | *Check out parts…* on an assembly (revision toolbar, group **Lock**, and the *Structure* tab, #415): the structure as a tree with check boxes (`GET …/bom?expand=true&rule=latest` for the tree, `GET …/workset?rule=latest` for state, group and lock holder; parts the CAD files reference follow at the end); parts that are released, in review or held by someone else are disabled with the reason (`checkoutBlocker` in `ui/js/workspace.js`). The command `workspace_checkout_many` sends the ticked revisions in one `POST /api/v1/checkouts` (one transaction, a result per revision), then fetches the files of every revision now checked out – writable, an unchanged copy only loses its read-only flag, local changes are kept (`workspace::checkout_many`, summary `workspace::checkout_many_summary`); the refused ones are listed with the server's reason |
| Preferred CAD program | The account setting of the web UI (`preferred_cad` of `GET /api/v1/me`, read at sign-in): when a revision has files of that program, the Files tab lists the native files of other CAD programs (`format_info.family`) in a collapsed *N files in other CAD formats (…)* group; neutral files (STEP, JT, STL, PDF, …) stay visible. Grouped in `ui/js/revision.js` (`groupByFamily`) with the same rule as the server's `cadformat::group_by_family`; display only |
| Whole project groups locally | the download icon in the navigator (*Tools → Get Project Groups…*): copies the files of every item of the chosen groups – latest revision (also in work, the default since #355) or latest released – into the working folder with their folder structure; unchanged files are skipped, locally modified files kept, name clashes reported. For new team members or a fresh computer |
| Import a CAD folder | the folder icon in the navigator (*Tools → Import CAD Folder…*): scans an existing folder (dry run: items, duplicate file names, skipped lock/backup files), then creates one item per part or assembly with the drawings and exports of the same name, project files in one document item, optional BOM lines from the assembly references, and checks every item in right after its files (assemblies once more after their BOM lines), so an interrupted import never leaves items checked out – a new run of the same folder also releases the check-outs an earlier, interrupted run left behind; a final report lists the new items and files, BOM lines, check-ins and problems (with *Open* for the top assembly); interrupted imports continue where they stopped (remembered per project group, so the same folder can also be imported into another group). Tutorial: *Help → How to Import a CAD Folder* |
Expand Down
16 changes: 16 additions & 0 deletions desktop/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,22 @@ pub async fn workspace_checkout(
.await
}

/// *Check out parts…* (issue #415): checks out the ticked revisions of an
/// assembly in one server call and makes their files in the working folder
/// writable; the result lists what the server refused and why.
#[tauri::command]
pub async fn workspace_checkout_many(
app: AppHandle,
state: State<'_, AppState>,
revisions: Vec<workspace::CheckoutPick>,
) -> CmdResult<workspace::CheckedOutMany> {
usage(&state, |u| u.count("checkout"));
let api = signed_in_api(&state)?;
let (cancel, mut progress) = progress_events(&app, &state);
let root = workspace_root(&app, &state);
workspace::checkout_many(&api, &root, &revisions, &cancel, &mut progress).await
}

/// Copies the current files of a revision into the working folder without
/// taking the lock (read-only on disk).
#[tauri::command]
Expand Down
1 change: 1 addition & 0 deletions desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ fn main() {
commands::assistant_cancel,
commands::file_bytes,
commands::workspace_checkout,
commands::workspace_checkout_many,
commands::workspace_download,
commands::workspace_get,
commands::workspace_cancel,
Expand Down
180 changes: 180 additions & 0 deletions desktop/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,152 @@ pub fn checkout_summary(r: &Downloaded, item: &str, code: &str) -> String {
}
}

/// A revision the user ticked in *Check out parts…* (issue #415).
#[derive(Clone, Debug, Deserialize)]
pub struct CheckoutPick {
pub project: Option<String>,
pub item: String,
pub code: String,
}

/// One server answer of `POST /checkouts` for one revision.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CheckoutResult {
#[serde(default)]
pub revision_id: Option<String>,
#[serde(default)]
pub item: String,
#[serde(default)]
pub code: String,
#[serde(default)]
pub ok: bool,
#[serde(default)]
pub already: bool,
#[serde(default)]
pub reason: Option<String>,
#[serde(default)]
pub message: Option<String>,
#[serde(default)]
pub checked_out_by_name: Option<String>,
}

/// The result of checking out several revisions: the server's answer per
/// revision and the files brought into the working folder.
#[derive(Debug, Default, Serialize)]
pub struct CheckedOutMany {
pub results: Vec<CheckoutResult>,
pub refused: Vec<CheckoutResult>,
pub files: Downloaded,
pub summary: String,
}

/// Checks out several revisions in one server call (`POST /checkouts`,
/// one transaction, a result per revision) and copies the files of every
/// revision now checked out into the working folder – writable, because
/// the user holds their lock now (`layout::read_only_wanted`). A file that
/// was already here unchanged only loses its read-only flag; a changed one
/// is kept. The refused revisions are listed with the server's reason.
pub async fn checkout_many(
api: &Api,
root: &Path,
picks: &[CheckoutPick],
cancel: &AtomicBool,
progress: &mut (dyn FnMut(&Progress) + Send),
) -> Result<CheckedOutMany, ApiError> {
let body = serde_json::json!({
"revisions": picks
.iter()
.map(|p| serde_json::json!({ "item": p.item, "code": p.code }))
.collect::<Vec<_>>(),
});
let answer = api.json(Method::POST, "/checkouts", Some(&body)).await?;
// The server has committed the check-outs by now: an answer we cannot
// read is an error (refresh), never "nothing was checked out".
let results: Vec<CheckoutResult> = serde_json::from_value(answer["revisions"].clone())
.map_err(|e| {
ApiError::local(format!(
"Unexpected answer of POST /checkouts: {e}. Some parts may be checked out – refresh to see them."
))
})?;
let mut files = Vec::new();
let mut dirs = Vec::new();
let mut failed = Vec::new();
for r in results.iter().filter(|r| r.ok) {
let project = picks
.iter()
.find(|p| p.item.eq_ignore_ascii_case(&r.item) && p.code.eq_ignore_ascii_case(&r.code))
.and_then(|p| p.project.clone());
match revision_files(api, project.as_deref(), &r.item, &r.code).await {
Ok(rev) => {
dirs.push(main_dir(
root,
project.as_deref(),
&rev.files,
&rev.item_folder,
));
files.extend(rev.files);
}
Err(e) => failed.push(format!("{}/{}: {e}", r.item, r.code)),
}
}
let mut report = fetch(api, root, &files, cancel, progress).await?;
report.failed.extend(failed);
report.revisions = results.iter().filter(|r| r.ok).count();
report.dir = dirs
.into_iter()
.next()
.unwrap_or_else(|| root.to_path_buf());
let refused: Vec<CheckoutResult> = results.iter().filter(|r| !r.ok).cloned().collect();
let summary = checkout_many_summary(report.revisions, &refused, &report);
Ok(CheckedOutMany {
results,
refused,
files: report,
summary,
})
}

/// The sentence after *Check out parts…*: how many revisions were checked
/// out, how many were refused, and what happened to their files.
pub fn checkout_many_summary(
checked_out: usize,
refused: &[CheckoutResult],
r: &Downloaded,
) -> String {
let mut head = match checked_out {
0 => "Nothing was checked out".to_string(),
1 => "Checked out 1 revision".to_string(),
n => format!("Checked out {n} revisions"),
};
if !refused.is_empty() {
head.push_str(&format!("; {} refused", refused.len()));
}
let mut parts = Vec::new();
if !r.downloaded.is_empty() {
parts.push(format!("{} file(s) downloaded", r.downloaded.len()));
}
if r.up_to_date > 0 {
parts.push(format!("{} up to date and writable now", r.up_to_date));
}
if !r.kept.is_empty() {
parts.push(format!("{} kept (your local changes)", r.kept.len()));
}
if !r.clashes.is_empty() {
parts.push(format!(
"{} name clash(es), not overwritten",
r.clashes.len()
));
}
if !r.failed.is_empty() {
parts.push(format!("{} failed", r.failed.len()));
}
if parts.is_empty() {
format!("{head}.")
} else {
format!("{head}. {}.", parts.join(", "))
}
}

/// The files of a `workset` answer: all, those of the root revision, the
/// root's project group and the number of revisions.
fn workset_files(set: &Value) -> (Vec<ServerFile>, Vec<ServerFile>, Option<String>, usize) {
Expand Down Expand Up @@ -2170,6 +2316,40 @@ mod tests {
);
}

#[test]
fn checkout_many_summaries() {
let refused = CheckoutResult {
item: "PRT-000003".into(),
code: "A".into(),
reason: Some("released".into()),
message: Some("PRT-000003/A is Released: revise it first.".into()),
..CheckoutResult::default()
};
assert_eq!(
checkout_many_summary(0, &[], &Downloaded::default()),
"Nothing was checked out."
);
let files = Downloaded {
downloaded: vec!["ROVER/hub.prt".into()],
up_to_date: 2,
kept: vec!["ROVER/axle.prt".into()],
..Downloaded::default()
};
assert_eq!(
checkout_many_summary(3, std::slice::from_ref(&refused), &files),
"Checked out 3 revisions; 1 refused. 1 file(s) downloaded, \
2 up to date and writable now, 1 kept (your local changes)."
);
assert_eq!(
checkout_many_summary(0, &[refused], &Downloaded::default()),
"Nothing was checked out; 1 refused."
);
// the server answer is read leniently (missing fields = defaults)
let r: CheckoutResult =
serde_json::from_value(json!({ "item": "PRT-1", "code": "A", "ok": true })).unwrap();
assert!(r.ok && !r.already && r.reason.is_none());
}

#[test]
fn decomposed_files_get_the_composed_name() {
let dir = tempfile::tempdir().unwrap();
Expand Down
12 changes: 11 additions & 1 deletion desktop/ui/js/revision.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { openTab, reloadActive, renderActive, renderTabs, table } from "./tabs.j
import { agentButton } from "./agent.js";
import { groupImpacts, impactGroup, revChanges, revHistory, revReferences } from "./references.js";
import { graphBackControl, revGraph } from "./graph.js";
import { addFilesDialog, checkinDialog, doCancelCheckout, doCheckout, doObsolete, doRevise, editDialog, filesHint, getStructureDialog, openFile, openWorkspaceFolder, releaseDialog, revViewer, revWorkspace } from "./workspace.js";
import { addFilesDialog, checkinDialog, checkoutPartsDialog, doCancelCheckout, doCheckout, doObsolete, doRevise, editDialog, filesHint, getStructureDialog, openFile, openWorkspaceFolder, releaseDialog, revViewer, revWorkspace } from "./workspace.js";
import { openChange } from "./change.js";
import { openRequest, requestChangeDialog } from "./requests.js";
import { bomFromCadDialog, importBomDialog } from "./bom-import.js";
Expand Down Expand Up @@ -190,6 +190,12 @@ export function renderRevision(tab, body, toolbar) {
] : [
act("checkout", "Check out", "checkout", function () { doCheckout(tab); }, "Take the lock and copy the files into your workspace")
];
// an assembly: check out several of its parts in one step (#415)
var isAssembly = rev.item_type === "assembly" || d.bom.length > 0;
if (isAssembly && canEdit()) {
lock.push(tool("Check out parts…", "checkout", function () { checkoutPartsDialog(tab); },
{ title: "Pick parts of this assembly and check them out together – their files become writable, so you can change them in the context of the assembly" }));
}
var releaseButton = act("release", "Release…", "release", function () { releaseDialog(tab); }, "Create a change order with reviewers and submit it");
// The working copy changes while the tab stays open (the CAD program saves
// into it): look again when the tab is shown from its cache or the window
Expand Down Expand Up @@ -630,6 +636,10 @@ export function revStructure(tab, el) {
type: "button", title: "Save the structure with this revision rule and all its files as ZIP",
on: { click: function () { savePackage(rev, rule); } }
}, "Pack and Go…"),
canEdit() && d.bom.length ? h("button.small", {
type: "button", title: "Pick parts of this structure and check them out together – their files become writable",
on: { click: function () { checkoutPartsDialog(tab); } }
}, "Check out parts…") : null,
canEdit() ? h("button.small", {
type: "button", disabled: !mine,
title: mine ? "Add a component – search by number, name or file name"
Expand Down
Loading
Loading