Programming

Upload multiple files from Angular 5 to Sharepoint, wait for all files to be uploaded before closing the modal, what am I doing wrong?

Learn Programming - 28 min 21 sec ago

I have an Angular 5 app, a C# .NET Web Api and as "database" you could imagine Sharepoint.

The flow of actions are, firstly the user logs into my angular app, selects an item from the list (data gotten from Sharepoint via my web api) and receive a modal/pop-up to add some comments, check some checkboxes and upload multiple files. When they click save, my app should send the line of comments typed in to a Sharepoint list and should upload any files selected by the user, this could be 1 or 10, to another Sharepoint list.

I disable the save/cancel buttons and display a spinner when the user has clicked on "Save". When all files are uploaded correctly, the modal should close. If any of them result in an error, it should throw an error to the modal to signal the user of the failure to upload.

Here's my code:

save() { if (this.EADModal.comments === '') { this.EADModal.comments = null; } // ...files = "FileList" item, NOT an Array! this.filesToUploadLength = this.filesToUpload.nativeElement.files.length; if (this.filesToUploadLength > 0 || this.EADModal.comments != null) { if (this.errorMessage != null) { this.errorMessage.nativeElement.value = ''; } this.showSpinner = true; this.showErrorMessage = false; this.saveButton.nativeElement.disabled = true; this.closeButton.nativeElement.disabled = true; if (this.EADModal.comments != null) { this.uploadComments(this.EADModal.comments); } if (this.filesToUploadLength > 0) { this.uploadAllFiles(this.filesToUpload.nativeElement.files); } } }

Here's my "uploadAllFiles":

public uploadAllFiles(files) { const observableArray: Array<Observable<any>> = new Array; for (const file of files) { observableArray.push(this.getBase64(file)); } Observable.forkJoin(observableArray).subscribe( data => { this.modalRef.close(this.EADModal.EOTAFileNr); }, error => { this.showSpinner = false; this.showErrorMessage = true; this.saveButton.nativeElement.disabled = false; this.closeButton.nativeElement.disabled = false; // this.errorMessage.nativeElement.value += 'File failed to upload! '; } ); }

Here's my "getBase64" function:

public getBase64(file): Observable<any> { const $this = this; const reader = new FileReader(); const fileReaderObs = Observable.create((observer: any) => { reader.onload = function() { $this.fillJsonVariable(reader.result); }; // observer.next(); observer.complete(); }); reader.readAsDataURL(file); return fileReaderObs; }

And here's my "fillJsonVariable":

public fillJsonVariable(readerResult): Observable<any> { const folderYear = '20' + this.EADModal.EOTAFileNr.substring(0, 2); this.json = { ... : ... }; return this.tableService.postModalDataFile(this.json); }

I've got limited experience in Angular and working with Observables as you might be able to see. What am I doing wrong here? The files simply aren't posted to Sharepoint. I know for sure this isn't an API/Sharepoint problem, because calling the observable/function once (not in a for loop) does upload the file!

submitted by /u/horoblast
[link] [comments]

Weekly useful Drupal things to know thread

What's a useful tip or technique or tool (or anything) that you picked up and think others should know about?

(Check out the weekly post schedule in the sidebar)

submitted by /u/AutoModerator
[link] [comments]

What choices I`ve got in making native mobile apps

Learn Programming - 52 min 39 sec ago

I am assigned to create a mobile application at work. I heard about "Pybee", but is it a good choice? Or should I stick with java/swift? And are there any other alternatives for building native apps?

submitted by /u/todorov525
[link] [comments]

To allocate or to pool?

Programming - 53 min 49 sec ago
Categories: Programming

Creating a composer file for a custom module. How should I test it?

I've been working on a D8 module Flot, and I want to get it so simplytest.me can install it for users and developers to test. I was trying to get a drush make file set up for it, but I just read that drush make is deprecated, so I'm moving to composer. This module depends on a javascript library that is not in composer. simplytest.me says , " Composer support for modules should now be functional " and that, " it will execute composer install in the projects root directory. "

Here is my composer.json.

{ "name": "drupal/flot", "description": "This module provides a wrapper for the javascript FLOT library.", "type": "drupal-module", "homepage": "https://drupal.org/project/flot", "minimum-stability": "dev", "repositories": [ { "type": "package", "package": { "name": "flot/flot", "version": "master", "type": "drupal-library", "source": { "type": "git", "url": "https://github.com/flot/flot.git", "reference": "master" } } } ], "require": { "flot/flot": "master" }, "extra": { "installer-paths": { "../../libraries/{$name}": [ "type:drupal-library" ] } } }

I'm having a hard time getting the libraries installed correctly. If I just have this file and type composer require flot/flot it will download. If I install drupal and type composer require drupal/flot it does not. Any advice on changes I should make?

submitted by /u/TheRealBeakerboy
[link] [comments]

I'm not sure what language I should begin to learn for my first project

Learn Programming - 1 hour 25 min ago

Hi,

I've set my first project to be some kind of sleep diary app for android, as I have a bit of trouble with my sleep schedule rn. I imagined the UI(if i can call it that) to have the visuals of a calendar. Select a day and you can type in the amount of sleep, how well you slept, what you did to help you get sleepy, etc. I read the 'read this first' post here, but the only recommendation i could see was Java. The link to more recommendations was broken.

Soo should I begin to learn Java? Can I even make this app with that?

Thanks in advance

submitted by /u/PewPewLaserDude
[link] [comments]

What frameworks or libraries help me build “shared experiences“ on the web?

Learn Programming - 1 hour 32 min ago

I’d like to build a webapp where a user in the webapp can can request help from a company representative. I want the rep to be able to hook into the user’s session and be able to “point” at things (via a 2nd cursor image). like an interactive screen share. Think Fire tablet’s old Mayday button feature that connected amazon employees to a user’s tablet.

What is this kind of “shared session” technology called? i am having trouble querying for this on google.

are there existing tools to get started building this sort of experience? I can imagine how I’d build it myself via web sockets connecting the customer’s session and the rep’s session, and exchanging information like the mouse position so the other session can render it to the other persons web page.

thanks for any direction or pointers!

submitted by /u/jakereadit
[link] [comments]

[C] Putchar overwriting a character rather than adding to the end of line as expected on Mac, but works normally on Windows

Learn Programming - 2 hours 16 min ago

Hello everyone, long time lurker but first time poster here. I tried to stick to the posting guidelines!

So the first assignment for a C/Assembly course I'm taking this term was to modify code given to us by a professor to rotate a text input from a file, so that say "abcd" became "bcda" [the first character in a given string is moved to the end]. Though I know I could've taken the time to figure out the syntax/tools for an algorithm, I wrote out a quick way since this was just an in-class assignment to "dust off' and code something small on the first day back.

The following is my modified code to complete the assignment:

#include <stdio.h> #define BUFFER_SIZE 81 int main(int argc, char **argv) { char string[BUFFER_SIZE]; while(fgets(string, BUFFER_SIZE, stdin)) { int numChars = 0; while(string[numChars] && string[numChars] != '\n') ++numChars; int i; for(i = 1; i < numChars; ++i) // This loop prints out the input starting at the second letter { putchar(string[i]); } putchar(string[0]); /* This is supposed to add the first character from the input to the end of the string prior to printing to console*/ putchar('\n'); fflush(stdout); } return 0; }

I also have an input.txt to pass to the program. Let's say that the original text in the file was "ABCDEFG". The desired output is "BCDEFGA".

The trouble is, after compiling and running this code on Mac and passing my input file to it, I get "ACDEFG".

After tinkering with the code, it looks like the for loop is printing out the input starting from the second letter as it should, but when it goes to "putchar(string[0])", it replaces the first letter rather than adding it to the end.

I was at wits end trying to modify this to work properly, but I'd always end up with a variation of the same issue - putchar seemed to revert to the start of the line, overwrite characters from there, and then print that line after calling fflush. After having a friend look over it and telling me it compiled and completed properly on his machine, I thought to try it on my PC......and sure enough, it worked properly x_x. 3-4 hours or so of reading documentation, trying new code, and searching for similar problems only to realize that it worked the first time, just not on my platform.

In trying to learn more about the issue, I added more "putchar" statements beneath the one next to my second comment, and noticed that the second putchar would overwrite the second character, and a third putchar would overwrite the third, etc. So say I added 3 "putchar(string[0])", the output would be "AAAFG", rather than "CDEFGAAA".

My question is - why the difference in output with the exact same code? I figure it's a cross-platform issue, but it seems like such an odd issue...though I do realize my knowledge on this subject is incredibly limited, as this is my very first day with C. How could I modify this code to give me the desired output on Mac? I've searched far and wide, and couldn't find anything relating to the problem of putchar overwriting characters.

For what it's worth - I'm using Visual Studio Code and compiling in terminal using gcc. I've also already submitted my assignment, and plan on coding C in a VM to avoid these sorts of issues in the future. I would just like to know how this could be coded differently/potentially avoided, or some insight as to what exactly is going on here for my own benefit and understanding.

Thanks in advance!!

submitted by /u/PalestinianLiberator
[link] [comments]

Kubernetes in 5 mins

Programming - 2 hours 22 min ago
Categories: Programming

Pages