Selaa lähdekoodia

Feature / isolate transform

master
Safet Purkovic 4 vuotta sitten
vanhempi
commit
4bc6eed928

+ 2
- 1
src/parameters/contracts.js Näytä tiedosto

new Param("br-landscapetable",["table"]), new Param("br-landscapetable",["table"]),
new Param("br-transformrotate",["div", "table"]), new Param("br-transformrotate",["div", "table"]),
new Param("br-isolatedlandscape",["div", "table"]), new Param("br-isolatedlandscape",["div", "table"]),
new Param("br-hidechildren",["div"])
new Param("br-hidechildren",["div"]),
new Param("br-root",["div"])
]; ];
} }



+ 3
- 3
src/transformations/header-transformations/header-every-page-transformation.css Näytä tiedosto

} }
@media print { @media print {
.header-show { .header-show {
position: fixed;
/* position: fixed;
z-index: 9999; z-index: 9999;
left:0; left:0;
top: 0;
top: 0; */
} }
table { page-break-after:auto } table { page-break-after:auto }
tr { page-break-inside:avoid; page-break-after:auto } tr { page-break-inside:avoid; page-break-after:auto }
td { page-break-inside:avoid; page-break-after:auto } td { page-break-inside:avoid; page-break-after:auto }
thead { page-break-inside: auto; }
thead { display:table-header-group }
/* display:table-header-group - Da bude na svakoj stranici */ /* display:table-header-group - Da bude na svakoj stranici */
tfoot { display:table-footer-group } tfoot { display:table-footer-group }
} }

+ 20
- 0
src/transformations/isolation-transform.js Näytä tiedosto

import {Transform} from "./transform";
import $ from "jquery";

export class IsolationTransform extends Transform {
constructor(param){
super(param);
}
execute(){
const targets = $(`[isolation="true"]`);
for(let i = 0; i < targets.length; i++){
targets.removeAttr("isolation");
}
$(this.object).attr("isolation", "true");
}
rolback(){
$(this.object).show();
}

}

+ 1
- 1
src/transformations/print.js Näytä tiedosto

const newBlob = new Blob([resObj.blob], { type: 'application/pdf' }); const newBlob = new Blob([resObj.blob], { type: 'application/pdf' });
const bytes = new Uint8Array(newBlob); const bytes = new Uint8Array(newBlob);
//console.log(bytes); //console.log(bytes);
modifyPdf(bytes);
//modifyPdf(bytes);
// MS Edge and IE don't allow using a blob object directly as link href, instead it is necessary to use msSaveOrOpenBlob // MS Edge and IE don't allow using a blob object directly as link href, instead it is necessary to use msSaveOrOpenBlob
if (window.navigator && window.navigator.msSaveOrOpenBlob) { if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob); window.navigator.msSaveOrOpenBlob(newBlob);

+ 112
- 0
src/transformations/root-transformation.js Näytä tiedosto

import { Transform } from "./transform";
import $ from 'jquery';

export class RootTransformation extends Transform
{
constructor(param){
super(param);
this.before = {};
}
execute(){
let array = [];
this.before = $('#root');
// const v = $(':eq(0)'); // za root element
const va = $('div.fade').children().toArray(); // gledamo div-fade kao root
let i = 1, temp = 0;
const divRootElement = document.createElement('div');
divRootElement.className = 'root';
const divElementPageBreak = document.createElement('div');
divElementPageBreak.style.pageBreakBefore = "always";
va.forEach(element => {
// 59.338582677165356 is sum of default top and bottom print margins
// 842 is height in pixels for A4 format
const razlika = element.clientHeight + temp - (i * 842 - 59.338582677165356);
if (razlika < 0) {
temp += element.clientHeight;
divRootElement.append(element);
console.log(temp);
}
else if (razlika === 0) {
i++;
temp = 0;
divRootElement.append(divElementPageBreak);
console.log(temp);
}
else {
if (element.hasChildNodes && element.childNodes.length === 1) {
const node = element.childNodes[0];
if (node.hasChildNodes && node.childNodes.length === 1) {
const subNode = node.childNodes[0];
if (subNode.hasChildNodes) {
const nodes = subNode.childNodes;
for (let j = 0; j < nodes.length; j++) {
const razlikaNodes = nodes[j].clientHeight + temp - (i * 842 - 59.338582677165356);
if (razlikaNodes < 0) {
temp += nodes[j].clientHeight;
console.log("bez apenda" + temp);
console.log(nodes[j]);
// divRootElement.append(nodes[j]);
array.push(nodes[j]);
}
else if (razlikaNodes === 0) {
i++;
temp = 0;
divRootElement.append(nodes[j]);
console.log(temp);
}
else {
if (nodes[j].hasChildNodes && nodes[j].childNodes.length > 1) {
const subNodes = nodes[j].childNodes;
for (let k = 0; k < subNodes.length; k++) {
const razlikaSubNodes = subNodes[k].clientHeight + temp - (i * 842 - 59.338582677165356);
if (razlikaSubNodes < 0) {
temp += subNodes[k].clientHeight;
divRootElement.append(subNodes[k]);
console.log(temp);
}
else {
i++;
temp = 0;
divRootElement.append(divElementPageBreak);
console.log(temp);
}
}
}
}
}
}
}
}
else if (element.hasChildNodes && element.childNodes.length > 1) {
const nodes = element.childNodes;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].clientHeight + temp < (i * 842 - 59.338582677165356)) {
temp += nodes[i].clientHeight;
divRootElement.append(nodes[i]);
console.log(temp);
}
else {
i++;
temp = 0;
console.log("bez apenda" + temp);
}
}
}
}

});
$('#root').empty();
$('#root').append(divRootElement);
array.forEach(element => {
console.log(element);
});
console.log(divRootElement);
}
rolback(){
$('#root').empty();
$('#root').append(this.before);
}
}

+ 2
- 2
src/transformations/show-number-rows-transformation.js Näytä tiedosto

execute(){ execute(){
const rows = this.value; const rows = this.value;
const count = ($(this.object).find("tbody")).children('tr').length; const count = ($(this.object).find("tbody")).children('tr').length;
$this.object.find("tbody").each(function () {
$(this.object).find("tbody").each(function () {
for(let i=rows;i<count;i++) for(let i=rows;i<count;i++)
{ {
$(this).find('tr').eq(i).hide(); $(this).find('tr').eq(i).hide();
$this.object.find("tbody").each(function () { $this.object.find("tbody").each(function () {
for(let i=rows;i<count;i++) for(let i=rows;i<count;i++)
{ {
$(this).find('tr').eq(i).hide();
$(this).find('tr').eq(i).show();
} }
}); });
}; };

+ 3
- 0
src/transformations/transform.js Näytä tiedosto

this.object = param.object; this.object = param.object;
this.selectors = param.selectors; this.selectors = param.selectors;
this.selector = this.object.tagName; this.selector = this.object.tagName;
try{
const arrayCode = this.object.getAttribute("code").split('-'); const arrayCode = this.object.getAttribute("code").split('-');
if(arrayCode.length > 2) if(arrayCode.length > 2)
{ {
this.value = arrayCode[2]; this.value = arrayCode[2];
} }
} }
catch{}
}
validate(){ validate(){
return (this.selectors.indexOf(this.selector.toLowerCase()) > -1); return (this.selectors.indexOf(this.selector.toLowerCase()) > -1);
}; };

+ 6
- 0
src/transforms-factory.js Näytä tiedosto

import { TransformRotate } from "./transformations/transform-rotate"; import { TransformRotate } from "./transformations/transform-rotate";
import { IsolatedLandscapeTransformation } from "./transformations/isolated-landscape-transformation"; import { IsolatedLandscapeTransformation } from "./transformations/isolated-landscape-transformation";
import { Hidechildren } from "./transformations/hide-children/hide-children"; import { Hidechildren } from "./transformations/hide-children/hide-children";
import { IsolationTransform } from "./transformations/isolation-transform";
import { RootTransformation } from "./transformations/root-transformation";


export class TransformsFactory { export class TransformsFactory {
produce(code, object, selectors) { produce(code, object, selectors) {
return new IsolatedLandscapeTransformation(param); return new IsolatedLandscapeTransformation(param);
case "br-hidechildren": case "br-hidechildren":
return new Hidechildren(param); return new Hidechildren(param);
case "br-root":
return new RootTransformation(param);
case "isolate":
return new IsolationTransform(param);
} }


return null; return null;

Loading…
Peruuta
Tallenna