/ Gists

Gists

On gists

Přihlášení backend usera do frontu a obráceně

Nette Nette-Tricks

backend-frontend-user.php #

<?php

// https://forum.nette.org/cs/34290-prihlaseni-admina-jako-uzivatel
// bez přepisování $user proměné 
public function handleKlientLogin($hash)
{
	overim hash a nactu data klienta

	$user = $this->getUser();
	$user->getStorage()->setNamespace('frontend');
	$user->login(new Identity($user->id, $user->role, ['username' => $user->username]));
	$this->redirect(....);
}

On gists

fluid-images.css

fluid-images.css #

_

On gists

Fluid images

CSS CSS trick

fluid-images.css #

/* https://www.zachleat.com/web/fluid-images/ */

img {
  max-width: 100%;
}
img[width] {
  width: auto; /* Defer to max-width */
}
img[width][height] {
  height: auto; /* Preserve aspect ratio */
}

/* Let SVG scale without boundaries */
img[src$=".svg"] {
  width: 100%;
  height: auto;
  max-width: none;
}

On gists

Test datových typů, Nette 2.0 AW

AW

dataTypes.php #

<?php

		/**
		 * TEST DATOVYCH TYPU
		 */

		call_user_func(function() { 

			// krabice
			$krabiceActiveRow = $this->connection->table('eshop_item')->where('id', 1467)->fetch();
			$krabiceDataset = $krabiceActiveRow->getDataset();
			$pv = $krabiceDataset->getPrimaryVariant();
			_bardump($krabiceActiveRow);

		});

		call_user_func(function() { 

			// varianta
			$varianta = $this->connection->table('eshop_item_variant')->where('id', 5411)->fetch();
			$krabiceActiveRow = $varianta->eshop_item;
			$krabiceDataset = $krabiceActiveRow->getDataset();
			$pv = $krabiceDataset->getPrimaryVariant(); // nerfunkcni viz http://bit.ly/2zzn4NI

			_bardump($krabiceActiveRow);

		});

On gists

VUE - Directives

Vue.js

Directives.vue #

export default {
  install (Vue) {

    Vue.directive('test-demo', {
      mounted(el, binding) {
        
        const modifiers = binding.modifiers
        const state = binding.arg === "a" ? "a" : "b"

        if (state === 'a') {
          el.style.color = 'red'
        } else {
          el.style.color = 'green'
        }

        if (modifiers.underline) {
          el.style.textDecoration = "underline"
        }
        if (modifiers.overline) {
          el.style.textDecoration = "overline"
        }

      }
    })

    Vue.directive('width', {
      mounted: function (el, binding) {
        el.style.width = binding.value + 'px'
      }
    })

    // mounted + update both
    Vue.directive('color-swatch', function (el, binding) {
      el.style.backgroundColor = binding.value
    })

    Vue.directive('demo', function (el, binding) {

      el.style.color = binding.value.color // => "white"
      el.textContent = binding.value.text
    })
  }

}

On gists

Transform origin - Filled buttons

CSS CSS trick

index.html #

<!-- https://jsbin.com/bowaxu/1/edit?html,css,output -->

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

	<a href="" class="button"><span class="button-text"></span></a>
	
</body>
</html>

On gists

SCSS: @at-root

SCSS

at-root-example.scss #

// Sass
.Component {
  .title {
    color: black;
    
    .is-active#{&} {
      color: blue;
    }
  }
}

// shitty
.Component .title {
  color: black;
}
.Component .title .is-active.Component .title {
  color: blue;
}


// at-root ------------------------------ //
// sass
.Component {
  .title {
    color: black;
    
    @at-root .is-active#{&} {
      color: blue;
    }
  }
}
// css
.Component .title {
  color: black;
}
.is-active.Component .title {
  color: blue;
}



@mixin variant($selector) {
  @at-root #{$selector}#{&} {
    @content;
  }
}

.Component {
  .title {
    color: black;
    
    @include variant('.is-active') {
      color: blue;
    }
  }
}

On gists

Multiple background

CSS

multi.css #

#https://jsbin.com/tedukoyara/edit?css,output
section
{
  height: 600px;
  border: 1px solid blue;
  
  background: 
    url(https://www.flaticon.com/svg/static/icons/svg/3823/3823859.svg) right bottom / 100px no-repeat, 
    url(https://www.flaticon.com/svg/static/icons/svg/3823/3823866.svg) left top / 100px no-repeat,
    url(https://www.flaticon.com/svg/static/icons/svg/3823/3823855.svg) 50% / 100px no-repeat;
}

On gists

Translator - null

Nette-Forms Nette-Tricks

translator.php #

<?php

$form['yearofbirth']->setTranslator(NULL);

On gists

BC Dummy data - SQL

AW

dummy-data-sql.sql #

-- dokumenty, regiony, klient, konkretni klient
SET @clientId = 10809;

INSERT INTO 

bc_stats (bc_document_id, bc_region_id, bc_client_id)

SELECT
id, 
bc_region_id,
@clientId
FROM 

bc_document 
WHERE bc_client_id = @clientId
AND bc_category_id != 0;


-- vsichni klienti
INSERT INTO 
bc_stats (bc_document_id, bc_region_id, bc_client_id)
SELECT
id, 
bc_region_id,
bc_client_id
FROM 
bc_document 
WHERE 1
AND bc_category_id != 0;



-- storage_id
update bc_stats t
    set bc_storage_id = elt(floor(rand()*12) + 1, 
	 8640,
     8641,
	 4409,
     5318,
     5338,
     6901,
     5314,
     3949,
     3332,
     3333,
     3404,
     11311
	);


-- emaily
update bc_stats t
    set email = elt(floor(rand()*15) + 1, 
	 
	 'janko@andweb.cz',
	  'stancek@andweb.cz', 
	  'netolicky@andweb.cz',
	  
	  'aaa@andweb.cz',
	  'bbb@andweb.cz', 
	  'ccc@andweb.cz',
	  
	  'ddd@andweb.cz',
	  'eee@andweb.cz', 
	  'fff@andweb.cz',
	  
	  'ggg@andweb.cz',
	  'hhh@andweb.cz', 
	  'iii@andweb.cz',
	  
	    
	  'jjj@andweb.cz',
	  'kkk@andweb.cz', 
	  'lll@andweb.cz'
	);
	

-- datumy
SET @MIN = '2017-06-29 00:53:27';
SET @MAX = '2020-04-29 13:53:27';
 
UPDATE bc_stats
SET created = TIMESTAMPADD(SECOND, FLOOR(RAND() * TIMESTAMPDIFF(SECOND, @MIN, @MAX)), @MIN);


-- akce
update bc_stats t
    set action_type = elt(floor(rand()*7) + 1, 
	 		'login',
			'view',
			'share',
			'publish',
			'download',
			'upload',
			'comment'
	 );


 -- uzivatele
SELECT substring_index(GROUP_CONCAT(id), ',', 50) FROM bc_user 
WHERE lastname != ''
ORDER BY id ASC into @users;

SET @sql:= CONCAT('update bc_stats t set bc_user_id = elt(floor(rand()*50) + 1,', ' ', @users, ' )');

PREPARE stmt FROM @sql;
EXECUTE stmt;

-- share
update bc_stats t
    set bc_share_id = FLOOR( RAND() * (11100-11000+1) + 11000 );
	 


-- zopakovat radky
INSERT INTO bc_stats (action_type,created,bc_client_id,bc_user_id,bc_document_id,bc_region_id,bc_share_id,bc_comment_id,bc_upload_id,bc_storage_id,email) 
SELECT action_type,created,bc_client_id,bc_user_id,bc_document_id,bc_region_id,bc_share_id,bc_comment_id,bc_upload_id,bc_storage_id,email 
FROM bc_stats