Skip to content

Commit

Permalink
Merge pull request #37 from HALFpipe/fix-import
Browse files Browse the repository at this point in the history
Fix import
  • Loading branch information
HippocampusGirl authored May 18, 2022
2 parents 40fa080 + 1c56a27 commit 55add74
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default {
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
},
verbose: true,
};
9 changes: 6 additions & 3 deletions src/model/__tests__/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe("Database", () => {
database.put(imgsArray);

it("gets closest image", () => {
let closestImg = database.closest({"sub": "01", "type": "tsnr_rpt"});
let closestImg = database.closest({sub: "01", type: "tsnr_rpt"});
expect(closestImg.sub).toBe("01");
expect(closestImg.type).toBe("skull_strip_report");

closestImg = database.closest({"sub": "03", "type": "tsnr_rpt"});
closestImg = database.closest({sub: "03", type: "tsnr_rpt"});
expect(closestImg.sub).toBe("01");
expect(closestImg.type).toBe("skull_strip_report");
});
Expand All @@ -29,7 +29,10 @@ describe("Database", () => {
let [ exactImg ] = database.findAll({sub: "01", type: "skull_strip_report"});
expect(exactImg.hash).toBe("1");

let result = database.findAll({sub: "03"});
let result = database.findAll({sub: "03", type: "skull_strip_report"});
expect(result.length).toBe(0);

result = database.findAll({sub: "03"});
expect(result.length).toBe(0);
});

Expand Down
28 changes: 19 additions & 9 deletions src/model/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,33 @@ export class Database {
for (const key of basedOnEntities) {
const value = obj[key];

if (value === null) {
if (value == null) { // == catches both `null` and `undefined`
continue;
}
if (!(value in this.indexSets[key])) {
continue;
if (!(value in this.indexSets[key])) { // unknown value
if (exact) {
return null;
} else {
continue;
}
}

let indexSet = this.indexSets[key][value];
if (matches === null) {
const indexSet = this.indexSets[key][value];

if (matches == null) {
matches = indexSet;
} else {
indexSet = matches.intersection(indexSet);
if (!exact && indexSet.length === 0) {
break;
const intersectionSet = matches.intersection(indexSet);

if (intersectionSet.length === 0) {
if (exact) {
return null;
} else {
break; // return what we have
}
}

matches = indexSet;
matches = intersectionSet;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/styles/explore.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,15 @@ qc-explorer {
font-weight: 600;
font-size: 12.5px;
}

img {
object-fit: contain;
width: 100%;
height: 100%;

background-color: white;

object-fit: contain;
image-rendering: crisp-edges;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/styles/zoom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ qc-zoom {
img {
width: 100%;
height: 100%;

object-fit: cover;
image-rendering: crisp-edges;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/view/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Sidebar extends HTMLElement {
const importButton = h(
"a",
[new Attribute("class", "dropdown-item")],
[t("Import...")]
[t("Import")]
);
const fileInput = h(
"input",
Expand Down Expand Up @@ -134,11 +134,12 @@ export class Sidebar extends HTMLElement {
const { rating } = obj;
delete obj["rating"];

if (rating == "none") {
if (rating === "none") {
continue;
}

for (const img of database.findAll(obj)) {
const imgs = database.findAll(obj);
for (const img of imgs) {
viewModel.ratingsViewModel.set(img.hash, rating);
}
}
Expand Down

0 comments on commit 55add74

Please sign in to comment.