GOVUK Frontend with Angular issue with javascript - javascript

I'm trying to use the government design system with angular but not having a great deal of success (GDS).
I've gone down the route of using the pre-compiled files rather than npm and styling-wise things are working. But functionality-wise not so much.
I've included the javascript file in my index.html and am not getting any console errors
<!doctype html>
<html lang="en" class="govuk-template ">
<head>
<meta charset="utf-8">
<title>Explosives</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body class="govuk-template__body ">
<script>
document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');
</script>
<app-root></app-root>
<script src="/assets/js/govuk-frontend-4.4.1.min.js"></script>
<script>
window.GOVUKFrontend.initAll()
</script>
</body>
</html>
I've tried to use Tabs and Accordion components but they don't behave like they should.
Accordion is showing the sections but not giving me any option to show or hide
when it should look like this
GDS Accordion
And my Tabs Panel looks perfect
But clicking the tabs only adds a hash to the url and nothing changes with the tabs when it should behave like this example.
GDS Tabs
I was using this article as a guide. But it only got me so far (Stack Overflow)
I can only think the javascript file isn't being included properly but I'm at a loss as to what else I can try.
Debugging Steps
create a new angular app using the Angular CLI
download the following files from GDS
govuk-frontend-4.4.1.min.css
govuk-frontend-4.4.1.min.js
add the files to the specific folders
src/assets/css
src/assets/js
update angular.json to include these files
"styles": [
"src/styles.css",
"src/assets/css/govuk-frontend-4.4.1.min.css"
],
"scripts": [
"src/assets/js/govuk-frontend-4.4.1.min.js"
]
update index.html
<!doctype html>
<html lang="en" class="govuk-template ">
<head>
<meta charset="utf-8">
<title>Explosives</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body class="govuk-template__body ">
<script>
document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');
</script>
<app-root></app-root>
<script src="/assets/js/govuk-frontend-4.4.1.min.js"></script>
<script>
window.GOVUKFrontend.initAll()
</script>
</body>
</html>
create a new component using the angular cli
ng g c tabs
update new component html
<div class="govuk-tabs" data-module="govuk-tabs">
<h2 class="govuk-tabs__title">
Contents
</h2>
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item govuk-tabs__list-item--selected">
<a class="govuk-tabs__tab" href="#past-day">
Past day
</a>
</li>
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab" href="#past-week">
Past week
</a>
</li>
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab" href="#past-month">
Past month
</a>
</li>
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab" href="#past-year">
Past year
</a>
</li>
</ul>
<div class="govuk-tabs__panel" id="past-day">
<h2 class="govuk-heading-l">Past day</h2>
<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Case manager</th>
<th scope="col" class="govuk-table__header">Cases opened</th>
<th scope="col" class="govuk-table__header">Cases closed</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">David Francis</td>
<td class="govuk-table__cell">3</td>
<td class="govuk-table__cell">0</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Paul Farmer</td>
<td class="govuk-table__cell">1</td>
<td class="govuk-table__cell">0</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Rita Patel</td>
<td class="govuk-table__cell">2</td>
<td class="govuk-table__cell">0</td>
</tr>
</tbody>
</table>
</div>
<div class="govuk-tabs__panel govuk-tabs__panel--hidden" id="past-week">
<h2 class="govuk-heading-l">Past week</h2>
<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Case manager</th>
<th scope="col" class="govuk-table__header">Cases opened</th>
<th scope="col" class="govuk-table__header">Cases closed</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">David Francis</td>
<td class="govuk-table__cell">24</td>
<td class="govuk-table__cell">18</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Paul Farmer</td>
<td class="govuk-table__cell">16</td>
<td class="govuk-table__cell">20</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Rita Patel</td>
<td class="govuk-table__cell">24</td>
<td class="govuk-table__cell">27</td>
</tr>
</tbody>
</table>
</div>
<div class="govuk-tabs__panel govuk-tabs__panel--hidden" id="past-month">
<h2 class="govuk-heading-l">Past month</h2>
<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Case manager</th>
<th scope="col" class="govuk-table__header">Cases opened</th>
<th scope="col" class="govuk-table__header">Cases closed</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">David Francis</td>
<td class="govuk-table__cell">98</td>
<td class="govuk-table__cell">95</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Paul Farmer</td>
<td class="govuk-table__cell">122</td>
<td class="govuk-table__cell">131</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Rita Patel</td>
<td class="govuk-table__cell">126</td>
<td class="govuk-table__cell">142</td>
</tr>
</tbody>
</table>
</div>
<div class="govuk-tabs__panel govuk-tabs__panel--hidden" id="past-year">
<h2 class="govuk-heading-l">Past year</h2>
<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Case manager</th>
<th scope="col" class="govuk-table__header">Cases opened</th>
<th scope="col" class="govuk-table__header">Cases closed</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">David Francis</td>
<td class="govuk-table__cell">1380</td>
<td class="govuk-table__cell">1472</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Paul Farmer</td>
<td class="govuk-table__cell">1129</td>
<td class="govuk-table__cell">1083</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Rita Patel</td>
<td class="govuk-table__cell">1539</td>
<td class="govuk-table__cell">1265</td>
</tr>
</tbody>
</table>
</div>
</div>
import the new component into the app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { AppComponent } from './app.component';
import { TabsComponent } from './tabs/tabs.component';
#NgModule({
declarations: [
AppComponent,
TabsComponent,
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
update app.component.html to include GDS code
<header class="govuk-header " role="banner" data-module="govuk-header">
<div class="govuk-header__container govuk-width-container">
<div class="govuk-header__logo">
<a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype">
<!--[if gt IE 8]><!-->
<svg aria-hidden="true" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 132 97" height="30" width="36">
<path fill="currentColor" fill-rule="evenodd" d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"></path>
</svg>
<!--<![endif]-->
<!--[if IE 8]>
<img src="/assets/images/govuk-logotype-crown.png" class="govuk-header__logotype-crown-fallback-image" width="36" height="32">
<![endif]-->
<span class="govuk-header__logotype-text">
GOV.UK
</span>
</span>
</a>
</div>
</div>
</header>
<div class="govuk-width-container ">
<main class="govuk-main-wrapper " id="main-content" role="main">
<app-tabs></app-tabs>
</main>
</div>
<footer class="govuk-footer " role="contentinfo">
<div class="govuk-width-container ">
<div class="govuk-footer__meta">
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
<svg aria-hidden="true" focusable="false" class="govuk-footer__licence-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 483.2 195.7" height="17" width="41">
<path fill="currentColor" d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145" />
</svg>
<span class="govuk-footer__licence-description">
All content is available under the
<a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated
</span>
</div>
<div class="govuk-footer__meta-item">
<a class="govuk-footer__link govuk-footer__copyright-logo" href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">© Crown copyright</a>
</div>
</div>
</div>
</footer>
run the app using npm start
You'll see that the tab component isn't working as expected

Figured out a solution, though may be a bit of a workaround.
I removed the script tags from index.html, and instead am relying on the scripts array in angular.json to handle all the javascript.
I am now using the javascript file from the node_module folder; though it should work the same with the min.js file I had before.
Also created an extra js file, which would literally just run the initAll() method
// govuk-init.js
document.addEventListener("DOMContentLoaded", function(event) {
window.GOVUKFrontend.initAll();
})
// angular.json
"scripts": [
"node_modules/govuk-frontend/govuk/all.js",
"src/assets/js/govuk-init.js"
]
This way I know the initAll method will definitely run after all the other code has been run, and it seems to function correctly now.

Related

Integrating Html2Pdf with CouchCMS and AJAX

I am using the following:
Html2Pdf GitHub
CouchCMS Official Site
Firefox Developers Edition
I am working on generating a PDF file. When I use the code given in the documentation I am able to generate the PDF. Also, when I try to include the CouchCMS code the PDF is generated (as in a PDF which opens in a browser PDF Viewer).
My CouchCMS Code is:
<?php
require_once '../couch/cms.php';
require __DIR__.'/vendor/autoload.php';
?>
<cms:php>
use Spipu\Html2Pdf\Html2Pdf;
$html = '<cms:pages masterpage="pdf-generation/index.php"><h1>HelloWorld</h1>This is my first test</cms:pages>';
$html2pdf = new Html2Pdf();
$html2pdf->writeHTML($html);
$html2pdf->output();
</cms:php>
<?php COUCH::invoke(); ?>
Now I am trying to achieve the following:
From a list view of students, a button is clicked
This button click sends the button id to an AJAX script
AJAX Script needs to generate the following:
a. Open a Download dialog box with a custom pdf file name and allow to save locally.
b. Open a new window to display the generated pdf with the student info.
My codes for the above are:
List view of Student:
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Birth</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<cms:pages masterpage=k_template_name>
<cms:no_results>
<tr>
<td class="text-center" colspan="5">
- No record(s) found -
</td>
</tr>
</cms:no_results>
<tr>
<td>
<cms:show k_absolute_count /> (<cms:show k_page_id />)
</td>
<td>
<cms:show fname />
</td>
<td>
<cms:show lname />
</td>
<td>
<cms:if dob>
<cms:date dob format='d-m-Y' />
<cms:else />
1970-01-01
</cms:if>
</td>
<td class="text-center">
<form>
<button class="btn btn-danger btn-sm text-uppercase" type="submit" data-id="<cms:show k_page_id />">
<i class="fa fa-file-pdf-o"></i> Generate PDF
</button>
</form>
</td>
</tr>
</cms:pages>
</tbody>
</table>
AJAX Script to Call AJAX file:
<script type="text/javascript">
$("button").click(function(e) {
e.preventDefault();
var i = $(e.currentTarget).attr('data-id');
$.ajax({
type: "POST",
url: "<cms:show k_site_link />pdf-generation/html2pdf.php",
data: {
id: i
},
success: function(response) {
$("body").html(response);
// window.location.href = '<cms:show k_site_link />pdf-generation/pdf-test.php?id=';
}
});
});
</script>
AJAX File Code:
<?php
require_once '../couch/cms.php';
require __DIR__.'/vendor/autoload.php';
?>
<cms:set page_id="<cms:gpc 'id' method='POST' />" "global" />
<cms:content_type "application/pdf" />
<cms:php>
use Spipu\Html2Pdf\Html2Pdf;
$html = '<cms:pages masterpage="pdf-generation/index.php" id=page_id limit="1">
<div style="width: 210mm; height: 148.5mm;">
<!-- Page Border -->
<div style="width: 205mm; height: 143.5mm; border: 2px solid rgba(0,0,0,0.5);">
<!-- Content Margin from Page Border : 3mm all sides -->
<div style="margin: 3mm;">
<!-- Schools Details : Header -->
<div style="width: 191mm; height: 25mm; text-align: center;">
<h3 style="margin-bottom: 0; margin-top: 0;">School Name</h3>
<small>
<p style="margin: 0;">Address Line #1</p>
<p style="margin: 0;">Address Line #2</p>
<p style="margin: 0;">Phone Number</p>
</small>
</div>
<!-- Schools Details : Header -->
<!-- Certificate Title -->
<div style="width: 191mm; height: 5mm; line-height: 5mm; text-align: center;">
<strong style="text-transform: uppercase;">BONAFIDE CERTIFICATE</strong>
</div>
<!-- Certificate Title -->
<!-- Certificate & GR Number -->
<div style="width: 191mm; height: 5mm; line-height: 5mm;">
<div style="width: 95.5mm; float: left; text-align: center;">
<strong>Certificate No. # </strong>2022001
</div>
<div style="width: 95.5mm; margin-left: 95.5mm; text-align: center;">
<strong>Student GR No. # </strong>12345
</div>
</div>
<!-- Certificate & GR Number -->
<!-- Spacing -->
<div style="width: 191mm; height: 5mm;"></div>
<!-- Spacing -->
<!-- Certificate Content -->
<div style="width: 191mm; font-size: 16px; line-height: 25px;">
This is to certify that <em><u><cms:show fname /> <cms:show lname /></u></em> son/daughter of <em>_______</em>, is/ was a bonafide student of our school during the academic session <em>_____</em> to <em>_____</em>. His/ Her Date of birth according to the school records is <em><u><cms:date dob format="d M Y" /></u></em> He/ She bears a Good Moral Character.
</div>
<!-- Certificate Content -->
<!-- Spacing -->
<div style="width: 191mm; height: 5mm;"></div>
<!-- Spacing -->
<!-- Certificate Issue Date -->
<div style="width: 191mm; height: 5mm; line-height: 5mm;">
<strong>Date of Issue: </strong>Jan 01, 2022
</div>
<!-- Certificate Issue Date -->
<div style="width: 191mm; height: 28mm;">
<div style="width: 95.5mm; float: left; text-align: center; margin-top: 18mm;">
<strong>Headmistress</strong>
<div style="padding-top: 1px;"></div>
(Stamp and Sign)
</div>
<div style="width: 95.5mm; margin-left: 95.5mm; text-align: center; margin-top: 18mm;">
<strong>School Seal</strong>
<div style="padding-top: 1px;"></div>
(Stamp)
</div>
</div>
</div>
<!-- Content Margin from Page Border : 3mm all sides -->
</div>
<!-- Page Border -->
</div></cms:pages>';
$html2pdf = new Html2Pdf();
$html2pdf->writeHTML($html);
$html2pdf->output();
</cms:php>
<?php COUCH::invoke(); ?>
When I click the Generate PDF Button, I get the following Output, but no pdf is shown in PDF Viewer:
%PDF-1.7 %���� 7 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20220328130254+00'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /Contents 8 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 6 0 R ] /PZ 1 >> endobj 8 0 obj <> stream x��Z[S�H~�_q��ũҶ�}��{��#�����O�V�[��/��˞WFXU5��x�G�C p��fD1 �9�ALkN�+bM%"�1-� I��2A,��R��=/����I��vU � U�J��Ōr��)�\�_kڪ�T�/�Vj0/��^��Q8'�0^1nA����$��Y��9���U���?-q�%��ƭNRE�YgOU)x3^T}u>z�Y�ʊ����f���2H��ȯ�04fHI����׽�t4̡a� ��i��\�d`�#4۽4����0Η�`J#�D�E� �C A\s��Q�"������>\�a�����=;���9�Ǖ톛��F��^O�Ohn�]GDh��� ��l͇�u�>y2��O�\���Y/w8ǘ��/T �'�^F��V��U^���g�l� �9յ�8��S�)ęL��������14�oZ�'�O��R�Y�� ��PͰE"�W|]܈]�t���c�J��b�_;t�S�̠���yS�ڕ%d�'g.�4���Of�䡙���W�ӛ�\A.$bj���r >��f�om�tZ=�3h�qHM�S^r��%��<�v돐�l�H:{ΐ�56��;Rgbh]m����O�g���k��)_#X��`$'���y=/���k�F�Ԯ8d��0��n/�����z�� Ė,���U����e-�}Z�0�X�K���D1d���v ���p� A���f��b����� ۶Q��u��˛�s�_�!��C<�A=,{�vX��i: endstream endobj 1 0 obj << /Type /Pages /Kids [ 7 0 R ] /Count 1 >> endobj 3 0 obj <> endobj 4 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 3 0 R /F2 4 0 R /F3 5 0 R >> /XObject << >> >> endobj 6 0 obj <> /H /I>> endobj 9 0 obj << /Creator (��Html2Pdf - TCPDF) /Producer (��TCPDF 6.4.4 \(http://www.tcpdf.org\)) /CreationDate (D:20220328130254+00'00') /ModDate (D:20220328130254+00'00') /Trapped /False >> endobj 10 0 obj << /Type /Metadata /Subtype /XML /Length 4656 >> stream application/pdf 2022-03-28T13:02:54+00:00 Html2Pdf - TCPDF 2022-03-28T13:02:54+00:00 2022-03-28T13:02:54+00:00 TCPDF 6.4.4 (http://www.tcpdf.org) uuid:3fbc284a-635c-7e1d-254c-6d5fc16a3de2 uuid:3fbc284a-635c-7e1d-254c-6d5fc16a3de2 http://ns.adobe.com/pdf/1.3/ pdf Adobe PDF Schema internal Adobe PDF Schema InstanceID URI http://ns.adobe.com/xap/1.0/mm/ xmpMM XMP Media Management Schema internal UUID based identifier for specific incarnation of a document InstanceID URI http://www.aiim.org/pdfa/ns/id/ pdfaid PDF/A ID Schema internal Part of PDF/A standard part Integer internal Amendment of PDF/A standard amd Text internal Conformance level of PDF/A standard conformance Text endstream endobj 11 0 obj << /Type /Catalog /Version /1.7 /Pages 1 0 R /Names << >> /ViewerPreferences << /Direction /L2R >> /PageLayout /SinglePage /PageMode /UseNone /OpenAction [7 0 R /FitH null] /Metadata 10 0 R >> endobj xref 0 12 0000000000 65535 f 0000001753 00000 n 0000002143 00000 n 0000001812 00000 n 0000001918 00000 n 0000002029 00000 n 0000002267 00000 n 0000000015 00000 n 0000000483 00000 n 0000002483 00000 n 0000002726 00000 n 0000007465 00000 n trailer << /Size 12 /Root 11 0 R /Info 9 0 R /ID [ <3fbc284a635c7e1d254c6d5fc16a3de2> <3fbc284a635c7e1d254c6d5fc16a3de2> ] >> startxref 7674 %%EOF
When I check my XHR Call, In the Response Payload I get a string, this string when appended to:
data:application/pdf;base64,XXXXXXXXXXX
generates the PDF and opens it in PDF Viewer.
I request for help with the following:
Open the PDF Viewer in a new tab to view the PDF (current output opens in the same tab and on the url where the list view is displayed but not in pdf viewer, but not in a new tab with probably the AJAX url)
Open a Download Dialog box to save the PDF with a custom, pre-supplied file name.
Any help will be really appreciated.
Regards,
Aashish

Why is the table cutoff in Chrome but not Internet Explorer?

I'm currently following a tutorial in order to learn how to create a dashboard to track cryptocurrency prices. However, I have become stuck on an issue where the top of my tables gets cut off when I run the webpage on chrome , while the top of the webpage is supposed to look like this at the top of the webpage as can be seen when ran on IE . When I disable javascript within Chrome I get something like . The program's backend uses next.js, coingecko API to fetch prices and bootstrap for formatting. I would greatly appreciate any tips that could help in pushing me towards the solution. I have attached the relevant code and resources below.
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import CoinGecko from 'coingecko-api';
const coinGeckoClient = new CoinGecko();
export default function Home(props) {
const { data } = props.result;
const formatPercent = number =>
`${new Number(number).toFixed(2)}%`
const formatDollar = (number, maximumSignificantDigits) =>
new Intl.NumberFormat(
'en-US',
{
style: 'currency',
currency: 'USD',
maximumSignificantDigits
})
.format(number);
return (
<div className={styles.container}>
<Head>
<title>Coinmarketcap clone</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<h1>Coinmarketcap clone</h1>
<table className="table">
<thead>
<tr>
<th>Symbol</th>
<th>24H Change</th>
<th>Price</th>
<th>Market cap</th>
</tr>
</thead>
<tbody>
{data.map(coin => (
<tr key={coin.id}>
<td>
<img
src={coin.image}
style={{width: 25, height: 25, marginRight: 10}}
/>
{coin.symbol.toUpperCase()}
</td>
<td>
<span
className={coin.price_change_percentage_24h > 0 ? (
'text-success'
) : 'text-danger'}
>
{formatPercent(coin.price_change_percentage_24h)}
</span>
</td>
<td>{formatDollar(coin.current_price, 20)}</td>
<td>{formatDollar(coin.market_cap, 12)}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
Tutorial: https://www.youtube.com/watch?v=klFeYge2G0I
Repo: https://github.com/jklepatch/eattheblocks/tree/master/screencast/226-coinmarketcap-clone

VueJs not rendering when add <div> tag in <template>

My VueJs Init
I use webpack and initialize the vuejs:
import Vue from "vue";
import CarrierList from '../components/carrier/CarrierList';
/**
* Create a fresh Vue Application instance
*/
new Vue({
el: '#app',
components: {CarrierList},
}).$mount('#app');
My Component:
<template>
<table class="table table-striped">
<thead>
<tr>
<th>ID </th>
<th>Name</th>
<th>Kontaktperson</th>
<th>Telefon</th>
<th>Region</th>
<th>Email Empfänger</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="carrier in carriers">
<td>{{ carrier.id }}</td>
<td><a :href="route.generate('carrier_show', {id : carrier.id })">{{ carrier.name }}</a></td>
<td>{{ carrier.contact_person }}</td>
<td>{{ carrier.phone }}</td>
<td><span v-if="carrier.region">{{ carrier.region.name }}</span></td>
<td>{{ carrier.email }}</td>
<td>
<a :href="route.generate('carrier_show', {id : carrier.id })"><span class="badge badge-secondary pointer" data-toggle="tooltip" data-placement="top" title="Spedition anzeigen"><i class="fa fa-info-circle" aria-hidden="true"></i></span></a>
<a :href="route.generate('carrier_edit', {id : carrier.id })"><span class="badge badge-info pointer" data-toggle="tooltip" data-placement="top" title="Spedition bearbeiten"><i class="fa fa-pencil-alt" aria-hidden="true"></i></span></a>
</td>
</tr>
</tbody>
</table>
</template>
<script>
import axios from 'axios';
export default {
name: "CarrierList",
data() {
return {
carriers: {},
route: FosRouting,
loading: false,
}
},
mounted() {
this.loading = true
axios.post(this.route.generate('api_carrier_list'))
.then(response => {
// JSON responses are automatically parsed.
this.carriers = response.data
})
.catch(e => {
this.errors.push(e)
});
},
methods: {}
}
</script>
<style scoped>
.loader{ /* Loader Div Class */
position: absolute;
top:0px;
right:0px;
width:100%;
height:100%;
background-color:#eceaea;
background-image: url('/images/ajax-loader.gif');
background-size: 50px;
background-repeat:no-repeat;
background-position:center;
z-index:10000000;
opacity: 0.4;
filter: alpha(opacity=40);
}
</style>
All is working right, the table will render with all the data that I get from the ajax request.
But now I want to add a simple div (for loading the ajax loading spinner) into the template:
<template>
<div class="loader" v-if="loading"></div>
<table class="table table-striped">
<thead>
<tr>
<th>ID </th> ....
But now, nothing will render. Why? I can't add a anywhere outside my table element.
Question:
What am I doing wrong and how can I add a single simple outside my table element and vuejs render my CarrierList Template?
Info:
I do not get an error in my console - nothing but the template still will not rendering.
When I remove the <div class="loader" v-if="loading"></div> the template will render and everything works normal.

Sort by all columns in table pure angular

I am trying to give a table the ability to sort by all columns, but having a bit of trouble. I am pulling some data from a webservice to populate the table but then want to sort wherever the user wants. I have a plunker here. Of my close attempt. I was thinking something like this:
$scope.order = function(predicate, reverse) {
$scope.recentalerts = orderBy($scope.recentalerts, predicate, reverse);
};
like from the angular website might work, but am having a bit of trouble integrating it into my own table. What am I doing wrong? Or is there an easier way to do so? I'd like to just stick with plain angular like this example.
Your example is working (after fixing the plunkR), however you always force reverse to false.
If you want to reproduce what Angular do, which is inverse the reverse parameter on each click, you could for instance add somehting like this:
$scope.orders[predicate] = !$scope.orders[predicate];
$scope.recentalerts = orderBy($scope.recentalerts, predicate, $scope.orders[predicate]);
See working plunkr:
http://plnkr.co/edit/Z9LDlWvwWV82D65pfiF6?p=preview
Or in a simpler form, use a common $scope.reverse attribute:
http://plnkr.co/edit/sMD7ZqmsJ7bULa26jo6q?p=preview
Here's a snippet of what I use for rolling my own sorting in tables. Simply using a string to determine what property I want to sort by (with reverse supported) and changing it dynamically, then using orderBy on the ng-repeat.
Hope this helps.
angular.module('app', [])
.controller('testCtrl', ['$scope',
function($scope) {
$scope.sortBy = 'ID';
$scope.sort = function(sortBy) {
if ($scope.sortBy == sortBy) {
$scope.sortBy = '-' + sortBy
} else {
$scope.sortBy = sortBy;
}
}
$scope.people = [{
'ID': 1,
'Name': 'Aaron',
'Age': 70
}, {
'ID': 28,
'Name': 'Ben',
'Age': 60
}, {
'ID': 2,
'Name': 'Claire',
'Age': 50
}, {
'ID': 14,
'Name': 'Damian',
'Age': 40
}, {
'ID': 8,
'Name': 'Frank',
'Age': 30
}];
}
]);
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet"/>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="app">
<div ng-controller="testCtrl">
<div id="wrapper">
<div style="margin: 1em">
<h4>Recent Alerts</h4>
<div>
<table class="table table-hover table-striped">
<thead>
<tr>
<th ng-click="sort('ID')">ID
<i class="fa fa-caret-down" ng-show="sortBy=='-ID'"></i>
<i class="fa fa-caret-up" ng-show="sortBy=='ID'"></i>
</th>
<th ng-click="sort('Name')">Name
<i class="fa fa-caret-down" ng-show="sortBy=='-Name'"></i>
<i class="fa fa-caret-up" ng-show="sortBy=='Name'"></i>
</th>
<th ng-click="sort('Age')">Age
<i class="fa fa-caret-down" ng-show="sortBy=='-Age'"></i>
<i class="fa fa-caret-up" ng-show="sortBy=='Age'"></i>
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="person in people | orderBy: sortBy">
<td ng-bind="person.ID"></td>
<td ng-bind="person.Name"></td>
<td ng-bind="person.Age"></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
</div>
</body>
</html>

EmberData RESTAdapter, regular refresh on one page with url filter

I have a Host model that is, for the moment, pretty simple:
App.Host = DS.Model.extend
name: DS.attr 'string'
The data adapter is handle by ember-data, my route looks like this:
App.HostsRoute = Ember.Route.extend
init: ->
#_super()
#refresh()
model: ->
#store.find 'host',
problematic: 1
refresh: ->
setTimeout =>
#store.find('host', { problematic: 1 }).then (hosts) =>
#controller.set 'content', hosts
#refresh()
, 10000
My template will show a list of boxes to list and manage nagios alerts:
<h2>Hosts list</h2>
<div class="row">
<div class="col-md-8">
{{#each host in controller}}
<div class="box box-solid box-default collapsed-box">
<div class="box-header">
<h5 class="box-title">
<i class="fa fa-server"></i>
{{ host.name }}
</h5>
<div class="box-tools pull-right">
<button class="btn btn-default btn-sm" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="box-body no-padding table-responsive" style="display: none">
{{#link-to 'host' host}}{{host.name}}{{/link-to}}
<table class="table table-hover">
<colgroup>
<col/>
<col style="width: 100%"/>
<col/>
<col/>
</colgroup>
<thead>
<tr>
<th>Service</th>
<th>Message</th>
<th>State</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{{/each}}
</div>
<div class="col-md-4">
{{outlet}}
</div>
</div>
My boxes are collapsed by default and can be uncollapsed by a js trick.
In each refresh, boxes are again collapsed. In fact, all the html is rewritten.
If I try without the problematic: 1 query parameter (calls /hosts instead of /hosts?problematic=1) it's works like a charm without rewriting all the html. The boxes stay uncollapsed.
So the problem source seems to be the additional query param but I don't know why.
What is wrong? How can I solve it?
Thanks.
UPDATE: Also tried with filter method:
model: ->
#store.filter 'host', {}, (host) ->
host.get 'problematic'
.then (hosts) ->
hosts
refresh: ->
setTimeout =>
#store.filter 'host', {}, (host) ->
host.get 'problematic'
.then (hosts) =>
#controller.set 'content', hosts
#refresh()
, 10000
But same problem, change nothing.
I have absolutely no idea of why this not works with filter or query param...

Categories