Skip to content

Commit

Permalink
feature(progress-bar): #35 global progress bar activates only on gene…
Browse files Browse the repository at this point in the history
…rate actions
  • Loading branch information
curkovicf committed Dec 12, 2021
1 parent fb1afe8 commit d752d83
Show file tree
Hide file tree
Showing 15 changed files with 42,843 additions and 6,482 deletions.
81 changes: 44 additions & 37 deletions libs/app/projects/feature/src/lib/services/projects.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {IProjectsService} from './projects-service.interface';
import { IProjectsService } from './projects-service.interface';
import {
IpcResponses,
IpcResponses
} from '@nx-cli/shared/data-access/models';
import Platform = OsUtils.Platform;
import {StringUtils} from '@nx-cli/shared/util';
import {ProjectsRepositoryImpl} from 'nx-cli-osfn/lib/projects/repositories/projects-repository-impl.class';
import { StringUtils } from '@nx-cli/shared/util';
import { ProjectsRepositoryImpl } from 'nx-cli-osfn/lib/projects/repositories/projects-repository-impl.class';
import { Project } from 'nx-cli-osfn/lib/projects/models/project.model';
import { EditProjectDto } from 'nx-cli-osfn/lib/projects/dtos/edit-project.dto';
import { DeleteProjectDto } from 'nx-cli-osfn/lib/projects/dtos/delete-project.dto';
Expand All @@ -18,15 +18,15 @@ import { ProjectType } from 'nx-cli-osfn/lib/projects/models/project-type.enum';

export class ProjectsService implements IProjectsService {
constructor(
private projectsRepository: ProjectsRepositoryImpl = new ProjectsRepositoryImpl(),
private projectsRepository: ProjectsRepositoryImpl = new ProjectsRepositoryImpl()
) {}

/**
* Gets all libs and apps for a specific nx workspace
* @param workspacePath root workspace path
*/
async getAllProjects(
workspacePath: string,
workspacePath: string
): Promise<IpcResponses.ResponseWithData<Project[]>> {
await this.projectsRepository.openConfigFiles(workspacePath);
const projects = await this.projectsRepository.getAllProjectsV2(workspacePath);
Expand All @@ -35,7 +35,7 @@ export class ProjectsService implements IProjectsService {
return {
data: projects,
success: projects.length > 0 ? 'Projects successfully fetched.' : '',
error: projects.length === 0 ? 'There are no projects installed.' : '',
error: projects.length === 0 ? 'There are no projects installed.' : ''
};
}

Expand All @@ -44,33 +44,33 @@ export class ProjectsService implements IProjectsService {
* @param dto
*/
async editProject(
dto: EditProjectDto,
dto: EditProjectDto
): Promise<IpcResponses.ResponseWithLogs> {
const {oldName, newName, newDirectory, oldDirectory, workspacePath, project} = dto;
const { oldName, newName, newDirectory, oldDirectory, workspacePath, project } = dto;
const dir = StringUtils.removeSpecialCharFrontBack(
OsUtils.parsePath(
newDirectory
.replace('/libs/', '')
.replace('\\libs\\', '')
.replace('/apps/', '')
.replace('\\apps\\', ''),
),
.replace('\\apps\\', '')
)
);
const cmd = OsUtils.parsePath(
`nx g @nrwl/workspace:move --project ${project} ${
dir ? dir + '/' : ''
}${StringUtils.removeSpecialCharacters(newName)}`,
}${StringUtils.removeSpecialCharacters(newName)}`
);
const cmdTest = OsUtils.parsePath(
`nx g mv --project ${project}-e2e ${dir}${newName}-e2e`,
`nx g mv --project ${project}-e2e ${dir}${newName}-e2e`
);
const logs: string[] = [];

const e2eResult = await NodeUtils.executeCommand(
cmdTest,
[],
workspacePath,
'CREATE',
'CREATE'
);
const result = await NodeUtils.executeCommand(cmd, [], workspacePath, 'CREATE');

Expand All @@ -79,10 +79,10 @@ export class ProjectsService implements IProjectsService {

if (OsUtils.getOs() === OsUtils.Platform.windows) {
await this.projectsRepository.cleanEmptyDirWinFunction(
`${workspacePath}${OsUtils.getPlatformPathSeparator()}libs`,
`${workspacePath}${OsUtils.getPlatformPathSeparator()}libs`
);
await this.projectsRepository.cleanEmptyDirWinFunction(
`${workspacePath}${OsUtils.getPlatformPathSeparator()}apps`,
`${workspacePath}${OsUtils.getPlatformPathSeparator()}apps`
);
}

Expand All @@ -95,12 +95,12 @@ export class ProjectsService implements IProjectsService {
: '',
error: !result?.isSuccess
? `${oldName} has not been successfully moved/renamed.`
: '',
: ''
},
logResponse: {
workspacePath,
logs,
},
logs
}
};
}

Expand All @@ -109,12 +109,12 @@ export class ProjectsService implements IProjectsService {
* @param dto
*/
async deleteProject(
dto: DeleteProjectDto,
dto: DeleteProjectDto
): Promise<IpcResponses.ResponseWithLogs> {
const {projectNameInNxJson, workspacePath, type} = dto;
const { projectNameInNxJson, workspacePath, type } = dto;
const logs: string[] = [];
const cmd = OsUtils.parsePath(
`nx g @nrwl/workspace:remove --project ${projectNameInNxJson}`,
`nx g @nrwl/workspace:remove --project ${projectNameInNxJson}`
);

if (type === ProjectType.app) {
Expand All @@ -123,7 +123,7 @@ export class ProjectsService implements IProjectsService {
cmdTest,
[],
workspacePath,
'DELETE',
'DELETE'
);

logs.push(e2eResult?.log ?? '');
Expand All @@ -140,12 +140,12 @@ export class ProjectsService implements IProjectsService {
success: result?.isSuccess ? `${projectNameInNxJson} successfully deleted.` : '',
error: !result?.isSuccess
? `${projectNameInNxJson} has not been successfully deleted. If you are trying to delete app, make sure nothing depends on it.`
: '',
: ''
},
logResponse: {
workspacePath,
logs,
},
logs
}
};
}

Expand All @@ -161,45 +161,52 @@ export class ProjectsService implements IProjectsService {
OsUtils.getOs() === Platform.unix ? unixCmd : winCmd,
[],
workspacePath,
'Dep graph started',
'Dep graph started'
);

return {
workspacePath,
success: result ? `Dep graph successfully started.` : '',
error: !result ? `Dep graph has not successfully started.` : '',
error: !result ? `Dep graph has not successfully started.` : ''
};
}

async removeTag(
dto: RemoveTagDto,
dto: RemoveTagDto
): Promise<IpcResponses.ResponseWithData<RemoveTagDto>> {
await this.projectsRepository.openConfigFiles(dto.workspacePath);
const result = await this.projectsRepository.removeTag(dto);
await this.projectsRepository.clean();

return {
success: result ? 'Tag successfully removed' : '',
data: dto,
data: dto
};
}

async addTag(
dto: TagDto,
dto: TagDto
): Promise<IpcResponses.ResponseWithData<AddTagResult>> {
await this.projectsRepository.openConfigFiles(dto.workspacePath);
await this.projectsRepository.addTagV2(dto);
await this.projectsRepository.clean();
// FIXME: Add checks
return {
success: 'Tag successfully created',
data: {
tags: dto.tags,
workspacePath: dto.workspacePath,
selectedProjectName: dto.selectedProjectName,
},
selectedProjectName: dto.selectedProjectName
}
};
}

async generateArtifact(
dto: GenerateArtifactDto,
dto: GenerateArtifactDto
): Promise<IpcResponses.ResponseWithLogs> {
await this.projectsRepository.openConfigFiles(dto.workspacePath);
const result = await this.projectsRepository.generateNxArtifact(dto);
await this.projectsRepository.clean();

return {
result: {
Expand All @@ -208,12 +215,12 @@ export class ProjectsService implements IProjectsService {
success: result ? `${dto.nxGenerator.name} successfully executed.` : '',
error: !result
? `${dto.nxGenerator.name} has not been successfully executed.`
: '',
: ''
},
logResponse: {
workspacePath: dto.workspacePath,
logs: [result?.log],
},
logs: [result?.log]
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createAction, props} from '@ngrx/store';
import { createAction, props } from '@ngrx/store';
import { Project } from 'nx-cli-osfn/lib/projects/models/project.model';
import { AddTagResult } from 'nx-cli-osfn/lib/projects/dtos/add-tag-result.dto';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export class ProjectsEffects {
() =>
this.actions$.pipe(
ofType(switchCurrentWorkspace),
tap(({selectedWorkspace}) =>
this.projectsIpcApiService.getAllProjects(selectedWorkspace.path),
),
tap(({ selectedWorkspace }) => {
this.projectsFacade.resetProjects();
this.projectsIpcApiService.getAllProjects(selectedWorkspace.path);
}
)
),
{dispatch: false},
{ dispatch: false }
);

deleteWorkspace$ = createEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ProjectsIpcApiService {
}

public getAllProjects(projectPath: string): void {
this.progressBarFacade.markOperationAsActive();
// this.progressBarFacade.markOperationAsActive();
this.electronService.ipcRenderer.send(
ProjectsIpcEvents.getAllProjects.fromAngular,
projectPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {Injectable, NgZone} from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import {
ProjectsIpcEvents,
IpcResponses,
IpcResponses
} from '@nx-cli/shared/data-access/models';
import {first, tap} from 'rxjs/operators';
import {ElectronService} from 'ngx-electron';
import {ProjectsIpcApiService} from './projects-ipc-api.service';
import {MatSnackBar} from '@angular/material/snack-bar';
import {WorkspacesFacade} from '@nx-cli/client/workspaces/data-access';
import {ProjectsFacade} from '../+store/projects.facade';
import {ProgressBarFacade} from '@nx-cli/client/shared/data-access';
import { first, tap } from 'rxjs/operators';
import { ElectronService } from 'ngx-electron';
import { ProjectsIpcApiService } from './projects-ipc-api.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { WorkspacesFacade } from '@nx-cli/client/workspaces/data-access';
import { ProjectsFacade } from '../+store/projects.facade';
import { ProgressBarFacade } from '@nx-cli/client/shared/data-access';
import { Project } from 'nx-cli-osfn/lib/projects/models/project.model';
import { RemoveTagDto } from 'nx-cli-osfn/lib/projects/dtos/remove-tag.dto';
import { AddTagResult } from 'nx-cli-osfn/lib/projects/dtos/add-tag-result.dto';
Expand Down Expand Up @@ -44,7 +44,7 @@ export class ProjectsIpcEventsService {
(event, response: IpcResponses.ResponseWithData<Project[]>) => {
// FIXME:
this.ngZone.run(() => {
this.progressBarFacade.markOperationAsComplete();
// this.progressBarFacade.markOperationAsComplete();

this.workspacesFacade.selectedProject$
.pipe(
Expand Down Expand Up @@ -99,10 +99,7 @@ export class ProjectsIpcEventsService {
return;
}

this.ngZone.run(() => {
this.snackBar.open(success || error, null);
// this.progressBarFacade.markOperationAsComplete();
});
this.ngZone.run(() => this.snackBar.open(success || error, null));
},
);
}
Expand All @@ -118,7 +115,6 @@ export class ProjectsIpcEventsService {
const {error, success, data} = response;

if (success) {
console.log(response);
this.ngZone.run(() => this.projectsFacade.addTags(data));

return;
Expand Down
26 changes: 13 additions & 13 deletions libs/client/projects/data-access/src/lib/viewmodels/detail.store.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {Injectable} from '@angular/core';
import {ComponentStore} from '@ngrx/component-store';
import {ProjectsFacade} from '../+store/projects.facade';
import {ProjectsIpcApiService} from '../api/projects-ipc-api.service';
import {EditProjectDialogComponent} from '@nx-cli/client/projects/ui/edit-project-dialog';
import { Injectable } from '@angular/core';
import { ComponentStore } from '@ngrx/component-store';
import { ProjectsFacade } from '../+store/projects.facade';
import { ProjectsIpcApiService } from '../api/projects-ipc-api.service';
import { EditProjectDialogComponent } from '@nx-cli/client/projects/ui/edit-project-dialog';
import {
ConfirmDialogComponent,
ConfirmDialogContent,
ConfirmDialogContent
} from '@nx-cli/client/shared/ui/confirm-dialog';
import {ComponentType} from '@angular/cdk/portal/portal';
import {MatDialogConfig} from '@angular/material/dialog/dialog-config';
import {combineLatest, Observable} from 'rxjs';
import {filter, first, map, tap} from 'rxjs/operators';
import {MatDialog} from '@angular/material/dialog';
import {WorkspacesFacade} from '@nx-cli/client/workspaces/data-access';
import {NewTagDialogComponent} from '@nx-cli/client/projects/ui/new-tag-dialog';
import { ComponentType } from '@angular/cdk/portal/portal';
import { MatDialogConfig } from '@angular/material/dialog/dialog-config';
import { combineLatest, Observable } from 'rxjs';
import { filter, first, map, tap } from 'rxjs/operators';
import { MatDialog } from '@angular/material/dialog';
import { WorkspacesFacade } from '@nx-cli/client/workspaces/data-access';
import { NewTagDialogComponent } from '@nx-cli/client/projects/ui/new-tag-dialog';
import { Project } from 'nx-cli-osfn/lib/projects/models/project.model';

export interface DetailState {
Expand Down
26 changes: 13 additions & 13 deletions libs/client/projects/data-access/src/lib/viewmodels/list.store.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {ComponentStore} from '@ngrx/component-store';
import {Injectable} from '@angular/core';
import {filter, first, map, switchMap, tap} from 'rxjs/operators';
import {WorkspacesFacade} from '@nx-cli/client/workspaces/data-access';
import {combineLatest, Observable} from 'rxjs';
import {ProjectsIpcApiService} from '../api/projects-ipc-api.service';
import {MatDialog} from '@angular/material/dialog';
import {ComponentType} from '@angular/cdk/portal/portal';
import {GeneratorDialogComponent} from '@nx-cli/client/projects/ui/generator-dialog';
import {MatDialogConfig} from '@angular/material/dialog/dialog-config';
import {ProjectsFacade} from '../+store/projects.facade';
import {AutocompleteSearchComponent} from '@nx-cli/client/shared/ui/autocomplete-search';
import {ObjectUtils} from '@nx-cli/shared/util';
import { ComponentStore } from '@ngrx/component-store';
import { Injectable } from '@angular/core';
import { filter, first, map, switchMap, tap } from 'rxjs/operators';
import { WorkspacesFacade } from '@nx-cli/client/workspaces/data-access';
import { combineLatest, Observable } from 'rxjs';
import { ProjectsIpcApiService } from '../api/projects-ipc-api.service';
import { MatDialog } from '@angular/material/dialog';
import { ComponentType } from '@angular/cdk/portal/portal';
import { GeneratorDialogComponent } from '@nx-cli/client/projects/ui/generator-dialog';
import { MatDialogConfig } from '@angular/material/dialog/dialog-config';
import { ProjectsFacade } from '../+store/projects.facade';
import { AutocompleteSearchComponent } from '@nx-cli/client/shared/ui/autocomplete-search';
import { ObjectUtils } from '@nx-cli/shared/util';
import { Project } from 'nx-cli-osfn/lib/projects/models/project.model';
import { NxGenerator } from 'nx-cli-osfn/lib/projects/models/nx-generator.model';

Expand Down
Loading

0 comments on commit d752d83

Please sign in to comment.