Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

release: Master into dev #856

Merged
merged 31 commits into from
Aug 20, 2019
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
39521f2
Fix ymax and rename Tensorflow nama everywhere (#763)
JacopoMangiavacchi Apr 15, 2019
0fe6386
feat: Save partial project progress during project creation (#769)
wbreza Apr 17, 2019
c10c971
feat: CNTK Export Provider (#771)
wbreza Apr 17, 2019
d6a0594
Fix: Enables selection of azure region for custom vision export (#765)
wbreza Apr 18, 2019
37234ec
refactor: Remove editor footer
tbarlow12 Apr 18, 2019
6974aef
Project service functions
tbarlow12 Apr 15, 2019
1001528
Added tests for project service
tbarlow12 Apr 15, 2019
2ef4e13
Added confirm and strings for tag and rename operations
tbarlow12 Apr 15, 2019
4f325df
Split out project functions and asset functions into respective services
tbarlow12 Apr 15, 2019
f394ea3
Editor Page and canvas upates
tbarlow12 Apr 15, 2019
4193bc0
Register mixins and run async loop
tbarlow12 Apr 15, 2019
8439574
Saving assets in async foreach loop
tbarlow12 Apr 15, 2019
996a555
Delete tag working
tbarlow12 Apr 15, 2019
5b4610b
Rename tag function in editor page
tbarlow12 Apr 15, 2019
bbd83a4
Fix tag removal test for editor page
tbarlow12 Apr 16, 2019
8b34db5
Clean up and docs
tbarlow12 Apr 16, 2019
354623e
Lint fixes
tbarlow12 Apr 16, 2019
4a0dcb2
Dummy commit to kick off build again
tbarlow12 Apr 16, 2019
3998b6e
fix: Refactored project tag/delete updates
wbreza Apr 19, 2019
0b06d6a
test: Refactored editor page tests
wbreza Apr 19, 2019
48805dc
test: Verify tag update/delete project actions
wbreza Apr 19, 2019
0429590
doc: Add bug & feature templates (#780)
wbreza Apr 23, 2019
25b4aa2
Create CODE_OF_CONDUCT.md (#779)
wbreza Apr 23, 2019
a2ef52c
docs: updates to readme and changelog (#781)
pjlittle Apr 23, 2019
921dbac
feat: Active Learning Updates (#778)
wbreza Apr 24, 2019
acbbc86
fix: Fix display of tag color picker (#782)
tbarlow12 Apr 26, 2019
f29963c
feat: Add CSV Exporter (#757)
JacopoMangiavacchi Apr 26, 2019
90754dc
fix: change method for alloc string to buffer (#777)
golee Apr 29, 2019
4d02db4
fix: Updates export options for pascalVOC rename (#788)
wbreza Apr 29, 2019
2234c8a
fix: Updates backwards compat & fixes cntk export image bug (#789)
wbreza Apr 29, 2019
745e854
Release 2.1.0 (#790)
wbreza Apr 29, 2019
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
Prev Previous commit
Next Next commit
Project service functions
  • Loading branch information
tbarlow12 authored and wbreza committed Apr 29, 2019
commit 6974aef9d1526750e1729e824ba4d1e124ae565f
78 changes: 77 additions & 1 deletion src/services/projectService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import _ from "lodash";
import shortid from "shortid";
import { StorageProviderFactory } from "../providers/storage/storageProviderFactory";
import { IProject, ISecurityToken, AppError, ErrorCode, AssetState } from "../models/applicationState";
import { IProject, ISecurityToken, AppError, ErrorCode, AssetState, IAssetMetadata } from "../models/applicationState";
import Guard from "../common/guard";
import { constants } from "../common/constants";
import { ExportProviderFactory } from "../providers/export/exportProviderFactory";
import { decryptProject, encryptProject } from "../common/utils";
import packageJson from "../../package.json";
import { AssetService } from "./assetService";
import { forEachAsync } from "../common/extensions/array";

/**
* Functions required for a project service
Expand All @@ -18,6 +20,8 @@ export interface IProjectService {
save(project: IProject, securityToken: ISecurityToken): Promise<IProject>;
delete(project: IProject): Promise<void>;
isDuplicate(project: IProject, projectList: IProject[]): boolean;
deleteTag(project: IProject, tagName: string, currentAsset: IAssetMetadata): Promise<IAssetMetadata>;
renameTag(project: IProject, tagName: string, newTagName: string, currentAsset: IAssetMetadata): Promise<IAssetMetadata>;
}

/**
Expand Down Expand Up @@ -100,6 +104,78 @@ export default class ProjectService implements IProjectService {
return (duplicateProjects !== undefined);
}

/**
* Delete a tag from a project, including from all asset metadata files
* @param project The project containing tag to delete
* @param tagName Name of tag to delete
* @param currentAsset Current asset being viewed. Makes changes and returns updated asset to avoid
* needing to reload the asset in the editor page
*/
public async deleteTag(project: IProject, tagName: string, currentAsset: IAssetMetadata): Promise<IAssetMetadata> {
const transformer = (tags) => tags.filter((t) => t!== tagName);
return await this.updateProjectTags(project, tagName, currentAsset, transformer);
}

/**
* Rename a tag within a project, including within all asset metadata files
* @param project The project containing tag to rename
* @param tagName Name of tag to rename
* @param currentAsset Current asset being viewed. Makes changes and returns updated asset to avoid
* needing to reload the asset in the editor page
*/
public async renameTag(project: IProject, tagName: string, newTagName: string, currentAsset: IAssetMetadata): Promise<IAssetMetadata> {
const transformer = (tags) => tags.map((t) => (t === tagName) ? newTagName : t);
return await this.updateProjectTags(project, tagName, currentAsset, transformer);
}

/**
* Update tags within project, including within all asset metadata files
* @param project The project containing tags to update
* @param tagName Name of tag to update within project
* @param currentAsset Current asset being viewed. Makes changes and returns updated asset to avoid
* needing to reload the asset in the editor page
* @param transformer Function that accepts array of tags from a region and returns a modified array of tags
*/
private async updateProjectTags(project: IProject, tagName: string, currentAsset: IAssetMetadata, transformer: (tags: string[]) => string[]) {
const assetService = new AssetService(project);
const assetKeys = Object.keys(project.assets);
await assetKeys.forEachAsync(async (assetKey) => {
const asset = project.assets[assetKey];
if (asset.state !== AssetState.Tagged) {
return;
}
const assetMetadata = await assetService.getAssetMetadata(asset);
const updatedAssetMetadata = this.updateTagInAssetMetadata(assetMetadata, tagName, transformer);
if (updatedAssetMetadata) {
await assetService.save(updatedAssetMetadata);
}
});
return this.updateTagInAssetMetadata(currentAsset, tagName, transformer);
}

/**
* Update tag within asset metadata object
* @param assetMetadata Asset metadata to update
* @param tagName Name of tag being updated
* @param transformer Function that accepts array of tags from a region and returns a modified array of tags
* @returns Modified asset metadata object or null if object does not need to be modified
*/
private updateTagInAssetMetadata(assetMetadata: IAssetMetadata, tagName: string, transformer: (tags: string[]) => string[]) {
let foundTag = false;
for (const region of assetMetadata.regions) {
if (region.tags.find((t) => t === tagName)) {
foundTag = true;
region.tags = transformer(region.tags);
}
}
if (foundTag) {
assetMetadata.regions = assetMetadata.regions.filter((region) => region.tags.length > 0);
assetMetadata.asset.state = (assetMetadata.regions.length) ? AssetState.Tagged : AssetState.Visited;
return assetMetadata;
}
return null;
}

private async saveExportSettings(project: IProject): Promise<void> {
if (!project.exportFormat || !project.exportFormat.providerType) {
return Promise.resolve();
Expand Down