Angular8 - Getting File a Binary String from a Drop Zone File - drag-and-drop

In my Angular8 app, I have a drop zone where I can drag & drop files, such as PDF, MS Word, CSV, etc. I am using the technique found on this blog, but also documented by Mozilla MDN. The code works very well, but the one important thing I can't figure out is how to capture the file bytes being uploaded, so that I can save them to the database.
I placed a screenshot of the Opera browser source debugger below, showing the typescript and resulting fileObj and blobObj values. The debugger complains about readAsBinaryString(blobObj), saying that blobObj is not a Blob. Looking at the blobObj value, I can see it's not a Blob that I've seen before. And, looking at all the values, none stand-out to me as a Blob. Also, the file bytes aren't obvious either. Looking at the html, below, I can't think of a change that would reveal the bytes.
I'm hoping someone with drag and drop experience can explain how it's done.
Thanks!
Debugger Screenshot
HTML
<table class="table table-striped table-forum">
<tbody>
<tr>
<td>
<div class="container" style="float: left; padding-top: 10px; padding-left: 10px;" appDnd (fileDropped)="onFileDropped($event)" (itemDropped)="onItemDropped($event)">
<input type="file" #fileDropRef id="fileDropRef" multiple (change)="fileBrowseHandler($event.target.files)" />
<img src="assets/img/dnd/ic-upload-file.svg" alt="">
<h3>Drag and drop file here</h3>
<h3>or</h3>
<label for="fileDropRef" style="font-size: 14px; font-weight: 600; height: 25px; padding: 5px 5px;">Browse for File</label>
</div>
</td>
</tr>
<tr>
<td>
<div class="files-list" style="width: 35%;">
<div class="single-file" *ngFor="let file of files; let i = index">
<img src="assets/img/dnd/ic-file.svg" width="45px" alt="file">
<div class="info">
<h4 class="name">
{{ file?.name }}
</h4>
<p class="size">
{{ formatBytes(file) }}
</p>
<app-progress [progress]="file?.progress" style="width: 200px;"></app-progress>
</div>
<img src="assets/img/dnd/ic-delete-file.svg" class="delete" width="20px" alt="file" (click)="deleteFile(i)">
</div>
</div>
</td>
</tr>
</tbody>
</table>

const reader = new FileReader();
// FileReader has an onload event that you handle when it has loaded data
reader.onload = (e: any) => {
const data = e.target.result as any;
console.log({type: 'GalleryComponent prepareFilesList - data:', data});
};
// this will kick off the onload handler above
reader.readAsDataURL(file);

Related

Scala Play forms

I have a strange issue i cannot explain. i am using the play framework and when i try to run the View below it only works when i REPEAT the form action below... it works but i know it's not right. appreciative if anyone can help explain or correct.
#(errorMessage: String = "")(implicit messages: Messages)
#helper.form(routes.ApplicationHomeController.login) {
#main(title = messages("single.title")) {
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div id="userbox">
<form action="#{routes.ApplicationController.doLogin()}" method="post"></form>
<form action="#{routes.ApplicationController.doLogin()}" method="post">
<div style="color: red">#errorMessage</div>
<h1 id="logintxt" style="background-color: rgb(11, 146, 9);
background-position: initial;
background-repeat: initial;">Driver Service <b>ß</b>eta</h1>
<div id="submit_giff" style="display: none;">
<hi> Authenticating: <img src="/assets/images/loader-bar.gif" align="absmiddle"> </hi>
</div>
<input id="name" name="userName" placeholder="Username" style="opacity: 1;
background-color: rgb(255, 255, 255);
background-position: initial;
background-repeat: initial;">
<input id="pass" name="password" type="password" placeholder="Password" style="opacity: 1;
background-color: rgb(255, 255, 255);
background-position: initial;
background-repeat: initial;">
<p id="namealert" style="display: none;
opacity: 1;">Username:</p>
<p id="passal" style="display: none;
opacity: 1;">Password:</p>
<input id="loginbtn" style="opacity: 0.2;
cursor: default;" type="submit" value="Login">
</form>
</div>
<script src="/assets/javascripts/login.js"></script>
}
}
Two immediate observations.
One: #helper.form(...) will write a <form> element into the HTML that ultimately gets generated. Your view then includes other literal <form>s nested inside the first form. Nested forms are invalid HTML. You have one form submitting to routes.ApplicationController.doLogin and the other submitting to routes.ApplicationController.login. Who knows which of these the browser will actually submit to? We can't really predict because nested forms are invalid.
Two: you have your #main(...) view nested inside your #helper.form(...). I assume your main view contains <html>...</html>. This is going to result in HTML that starts with a <form> element, inside which is the <html> element. This is horribly invalid markup too.
My guess is one or both of these issues are your problem.
Try taking your generated HTML and running it through an HTML validator like https://validator.nu/. Fix any issues the validator finds, don't nest forms, and decide which (single) route the login form should actually submit to.

Datetime picker inherits style from my table

I'm using the datepicker from eonasdan (https://github.com/Eonasdan/bootstrap-datetimepicker)
It works great, but when I put it inside a table, it inherits the style of the table. It is as if the datepicker also becomes a table.
How can I avoid this?
I have the following in my CSS:
table.table {
tr {
th {
color: #ff0000; //red
}
}
}
This is my html file:
<table class="table">
<tr>
<th>Reconcile Date</th>
</tr>
<tr>
<td>
<div class="pickdate">
<input type="text" placeholder="Reconcile Date" class="form-control ">
</div>
</td>
</tr>
</table>
This sets the text in my table header to red. It also sets the days of the week and month name in my datepicker to red. Note the pickdate class load the datepicker
By using Google Chrome's inspection tools I was able to find one of the classes on your datepicker table and add the CSS at that level. Here is the CSS and jsfiddle link:
.table tr th{ color: red; }
.table-condensed thead tr th{ color: black;}
https://jsfiddle.net/w8gmcgv4/5/
let me know if these work for you. Thanks!
You can add the following rule to your stylesheet to customize datetimepicker style:
.bootstrap-datetimepicker-widget {
table {
tr {
th {
color: black;
}
}
}
}
Note that the picker has the debug option that allows you inspect component's HTML to simplyfy style customization.
Working example:
jQuery('#dates-ifbZ6A4b6r568bad40cd473').datetimepicker({
format: "DD/MM/YYYY", debug: true
});
table.table tr th {
color: #ff0000;
}
.bootstrap-datetimepicker-widget table tr th {
color: #000000;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<table class="table">
<tr>
<th>Debt Ref</th>
<th>Reconcile Date</th>
</tr>
<tr>
<td>
<div>NOR087-DAN052</div>
</td>
<td>
<div class="col-sm-12">
<input type="text" placeholder="Reconcile Date" name="dates[ifbZ6A4b6r568bad40cd473]" id="dates-ifbZ6A4b6r568bad40cd473" class="form-control ">
</div>
</td>
</tr>
</table>
<p>
The text in the datepicker shouldn't be red
</p>

How to click on a particular image within pop up window in watir-webdriver

This is my first attempt at using watir-webdriver for automating. As I go through each test case,I learn new things and face new challenges.I'm so grateful for all the questions and answers here as it has helped me tremendously.Thanks
I'm faced with a new challenge and it's with popups and I'm not very clear on how to resolve this even after going through lot of popup questions on stackoverflow.
I haven't written the watir code yet....just trying to figure out how to do it.So appriciate some pointers.
So I'm trying to create a user profile-fill the form with all relevant information and hit Create profile button.(All this is coded and works fine).
On clicking the Create Profile button a pop up window pops up with lot of images on it in a tabular form and with text "please click on the image of apple". The text is randomly generated-so instead of apple I could be asked to click on a plane.I then need to click on that particular image.
How can I have watir-webdriver do this for me?How do i tell watir-webdriver to use pop up window,read the text at top,match it with image and click on the image?
Thanks.
Here's the error I get.Also included is watir code and HTML
Error:
ArgumentError: invalid window selector: {:id=>"humanVerificationContainer"}
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir- webdriver/window.rb:15:in `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir- webdriver/has_window.rb:35:in `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir- webdriver/has_window.rb:35:in `window'
===============================================================================
$b.window(:id => "humanVerificationContainer").use do
$b.link(:id => "humanVerificationQuestion").click
<div id="humanVerificationContainer" style="position: fixed; z-index: 9999; top: 50px; left: 750.5px; display: block;"><a class="close"></a><div id="humanVerificationQuestion" class="modal">
<h2>Click the picture of an aircraft carrier</h2>
<table>
<tbody><tr>
<td>
<div answer="0" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat -300px 0px; height:100px; width:100px"> </div>
</td>
<td>
<div answer="1" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat 0px -100px; height:100px; width:100px"> </div>
</td>
<td>
<div answer="2" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat 0px -200px; height:100px; width:100px"> </div>
</td>
<td>
<div answer="3" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat -200px -100px; height:100px; width:100px"> </div>
</td>
</tr><tr>
<td>
<div answer="4" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat -300px -400px; height:100px; width:100px"> </div>
</td>
<td>
<div answer="5" class="humanImage" style="float:left; background:url('/images/security_image_tile.png') no-repeat -600px -200px; height:100px; width:100px"> </div>
</td>
<td>
When a new browser window is opened, you can invoke the use method.
browser.window(:title => "annoying popup").use do
browser.button(:id => "close").click
end
Based on the html, the popup does not appear to be an actual window. Instead, it is just a div tag within the main page that looks like a popup. Assuming it is not in an frame, you can treat it like you would any other div tag.
To get the "popup":
popup = $b.div(:id => "humanVerificationContainer")
To get the subject at the top of the popup:
subject = popup.h2.text.gsub(/^Click the picture of an? /, '')
#=> "aircraft carrier"
To click the "image", which is actually a div with a background image:
popup.div(:class => 'humanImage').click
However, there does not appear to be a way to determine which image is the aircraft. So your developers will likely need to put some sort of identifier in or make sure the image is always in the same answer (just for the test environment).

Issue with image in table using GMail online client

I am creating an email template to use in Pardot. I have coded the email up. It works fine in OSX Mail, Outlook 07 +, Opera Mail, however GMail is being a real pain. It is adding some weird height or something to the tr or td in my table.
Any suggestions?
<table border="0" cellpadding="0" cellspacing="0" width="228">
<tbody>
<tr valign="bottom">
<td valign="bottom"><span pardot-region=""><img src="widget_top.jpg" alt="Placeholder"></span></td>
</tr>
<tr bgcolor="#ffd13f">
<td style="padding: 10px;">
<h2><span pardot-region="">Subheading span across one or two lines for best practice:</span></h2>
<span pardot-region=""><p><b>Date:</b> Thursday 29 November</p>
<p><b>Time:</b> 1.30pm (GMT)</p>
<p><b>Where:</b> Register online ></p>
<p><b>Topic:</b> Dynamic performance management</p>
<p><b>Presenters:</b> Octavius Black, CEO and Sebastian Bailey, President</p></span>
</td>
</tr>
<tr valign="top">
<td valign="top"><span pardot-region=""><img src="widget_bottom.jpg" alt="Placeholder"></span></td>
</tr>
</tbody>
</table>
(this table is inside a set of tested tables).
Screen shot can be found here: http://i45.tinypic.com/15wzda9.png
Cheers :)
On the images you have to put (inline)
style="display:block;"
:)
display:block; is definitely needed. You probably should zero out everything in all img tags, and set width and heights also.
<img style="margin: 0; border: 0; padding: 0; display: block;" src="" width="600" height="150"
alt="">
Also, you don't need the spans inside the table cells. If you want to keep them, make sure they have margin and padding zero'd out there too.

Select nth child in xQuery / select next element

I am having trouble finding good xQuery tutorials, basically what I am trying to do is retreive the text etc... from this html node
<div class="venue">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
<p class="item-big">blabla</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">PHONE:</p>
<p class="item-big">123</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
<p class="item-big">etc...</p>
</div><br class="clear">
</div>
I'd like to know how can I get the data out of the 2nd p in the third div[#class="vitem"]
Or the p directly following the p[#class="label"] that contains the text WEB:
Edit: Answeres already helped a great bit, however my second question is if the layout changes to something like this
<div class="venue">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
<p class="item-big">blabla</p>
</div><br class="clear">
<div class="vitem">
<p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
<p class="item-big">etc...</p>
</div><br class="clear">
</div>
How do i get the etc..., knowing only that it follows a p with the class label containing the text WEB:? it's no longer in div[3]/p[2]
Thanks!
I'd like to know how can I get the
data out of the 2nd p in the third
div[#class="vitem"]
Use:
/*/div[#class='vitem'][3]/p[2]/text()
This means: get all the text node children of the second p child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.
Or the p directly following the
p[#class="label"] with the data WEB:
Use:
/*/div[#class='vitem'][3]/p[#class='label']
/following-sibling::p[1]/text()
This means: get all the text node children of the first following-sibling p of any p element with class attribute with value "label", that is a child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.
UPDATE: The OP has added a second question: he wants just to select the p that has as a string value the text "etc..."
Use:
/*/div/p[.='etc...']
I'd like to know how can I get the
data out of the 2nd p in the third
div[#class="vitem"] Or the p directly following the p[#class="label"]
The semantically equal XPath/XQuery expressions are:
/div
/div[#class='vitem'][3]
/p[2]
Or
/div
/div[#class='vitem'][3]
/p[#class='label']
/following-sibling::p[1]