Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No files loaded when closing the dialog window #875

Closed
NearW opened this issue Mar 11, 2020 · 3 comments · Fixed by #1082
Closed

No files loaded when closing the dialog window #875

NearW opened this issue Mar 11, 2020 · 3 comments · Fixed by #1082
Assignees
Labels
bug Only issues that describe bugs. pr-visualization Issues that touch the visualization pr(oject) which means web and desktop features.

Comments

@NearW
Copy link
Contributor

NearW commented Mar 11, 2020

Bug

Expected Behavior

When I have a map loaded and open the dialog to load a new file and close it again, I expect that nothing changes at all. The application should return to it's state before I opened the dialog.

Actual Behavior

When I have a map loaded and open the dialog to load a new file and close it again, the file selection vanishes and I can't select another loaded file until I load a complete new file.

Screenshots

no_file_selected

Additional Info

This somehow only happens with maps that were loaded through the dialog. It doesn't happen with the default loaded maps.

Steps to Reproduce the Problem

  1. Open any map
  2. Open the "load file dialog"
  3. Close it again

Specifications

  • CodeCharta Version: master
  • OS: macOS
  • Browser: Chrome
@NearW NearW added bug Only issues that describe bugs. pr-visualization Issues that touch the visualization pr(oject) which means web and desktop features. pr-visualization-desktop Issues that touch the visualization pr(oject) but only apply to the desktop version. labels Mar 11, 2020
@alschmut
Copy link
Contributor

I saw that the other day as well and committed a fix on the other file validation branch ✌️

@NearW NearW removed the pr-visualization-desktop Issues that touch the visualization pr(oject) but only apply to the desktop version. label Mar 20, 2020
@alschmut
Copy link
Contributor

The above mentioned fix, doesn't fix the issue correctly. I undid the change again on the other branch some time ago.

How to solve this bug:

  • call codeChartaService.loadFiles(nameDataPairs: NameDataPair[]) with all files inside that array
  • loop over every file (NameDataPair) and validate it
  • WHEN at least one file was valid THEN reset the state.files

The problem is:

  • The fileChooser.component.ts calls the function codeChartaService.loadFiles(nameDataPairs: NameDataPair[]) for every imported file, instead of once with all files. As the fileChooser is a legacy angularJS directive, I was not able to change the code in there to make it work.

@alschmut alschmut removed their assignment Jun 20, 2020
@JaiJoPa JaiJoPa self-assigned this Jun 23, 2020
JaiJoPa added a commit that referenced this issue Jun 25, 2020
@NearW
Copy link
Contributor Author

NearW commented Jul 3, 2020

@JaiJoPa collecting multiples before setting them all

export class FileChooserController {
	private files : NameDataPair[] = []

	/* @ngInject */
	constructor(
		private $scope,
		private dialogService: DialogService,
		private codeChartaService: CodeChartaService,
		private storeService: StoreService
	) {}

	public onImportNewFiles(element) {
		this.$scope.$apply(() => {
			this.storeService.dispatch(resetFiles())
			let content
			let readFiles = 0

			for (const file of element.files) {
				const isCompressed = file.name.endsWith(".gz")
				const reader = new FileReader()
				reader.onloadstart = () => {
					this.storeService.dispatch(setIsLoadingFile(true))
				}
				reader.onload = event => {
					if (isCompressed) {
						const zlib = require("zlib")

						content = zlib.unzipSync(Buffer.from((<any>event.target).result))
					} else {
						content = (<any>event.target).result
					}

				}
				reader.onloadend = () => {
					readFiles++
					this.addNameDataPair(file.name, content)
					console.log("adding ", file.name)

					if(readFiles === element.files.length) {
						this.setNewData()
						console.log("setting files")
					}
				}
				isCompressed ? reader.readAsArrayBuffer(file) : reader.readAsText(file, "UTF-8")
			}
		})
	}

	public setNewData() {
		this.codeChartaService.loadFiles(this.files).catch((validationResult: CCValidationResult) => {
			this.storeService.dispatch(setIsLoadingFile(false))
			this.printErrors(validationResult)
		})
		this.files = []
	}

	private addNameDataPair(fileName: string, content: string) {
		this.files.push({
			fileName,
			content: FileChooserController.getParsedContent(content)
		})
	}
}

JaiJoPa added a commit that referenced this issue Jul 6, 2020
JaiJoPa added a commit that referenced this issue Jul 6, 2020
JaiJoPa added a commit that referenced this issue Jul 6, 2020
JaiJoPa added a commit that referenced this issue Jul 7, 2020
NearW added a commit that referenced this issue Jul 23, 2020
* Fix files are only valuated if a file was chosen #875

* Test onimportnewfiles #875

* Remove unused implementation in codeCharta test

* Filereset only after first valid file #875

* Remove invalid validation behaviour #875

* Collect files in array instead calling multiple times loadingFile #875

* Adjust tests #875

* Update changelog #875

* Remove tests #875

* Add delay to prevent e2e tests failing #875

Co-authored-by: Ben Willenbring <ben-willenbring@t-online.de>
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Only issues that describe bugs. pr-visualization Issues that touch the visualization pr(oject) which means web and desktop features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants