Skip to content

Instantly share code, notes, and snippets.

Pavel cpoDesign

View GitHub Profile
@cpoDesign
cpoDesign / gist:c934d0a8bc04fd53f580
Last active Aug 29, 2015
String comparison using different implementation and its results
View gist:c934d0a8bc04fd53f580
using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
const string PostcodeSubstitute = "PJ15 8JJ";
const string MatchingPostcode = "PJ15 8QJ";
@cpoDesign
cpoDesign / gist:37b602ec02b872c6368f
Last active Aug 29, 2015
Basic unit testing with angular - variable in controller
View gist:37b602ec02b872c6368f
// for every module you include here, you need to add required resource files into your test file
var app = angular.module('app', ['ngSanitize', 'ngResource', 'ngRoute']);
// definition of controller
'use strict';
app.controller('AdminCtr',
function AdminCtr() {
this.helpAndSupportText = 'Hello';
});
@cpoDesign
cpoDesign / gist:e37c78a8e5f4da71b45b
Created Jun 11, 2014
Example of creating directive that adds html to start and end of template
View gist:e37c78a8e5f4da71b45b
// use example: <my-button>
testApp.directive('myButton', function(){
return {
link: function (scope, element, attrs) {
var markup = "<button>Hello</button>";
element.prepend(markup); // adds html before any child
element.append(markup); // adds html after last child
}
}
@cpoDesign
cpoDesign / gist:0223dc05141aacc27b88
Last active Aug 29, 2015
Example of creating directive that adds html to start and end of template.
View gist:0223dc05141aacc27b88
// used in: http://blog.cpodesign.com/blog/angular-directives-in-examples/
// use example: <my-button>
testApp.directive('myButton', function(){
return {
link: function (scope, element, attrs) {
var markup = "<button>Hello</button>";
element.prepend(markup); // adds html before any child
element.append(markup); // adds html after last child
}
@cpoDesign
cpoDesign / gist:e9267a424a623ba34e91
Created Jun 12, 2014
Implementing select dropdown with default select option
View gist:e9267a424a623ba34e91
app.controller('myController', function($scope){
$scope.teams = [
{id:1, name:'team 1'},
{id:2, name:'team 2'},
{id:3, name:'team 3'}];
// if I want to preselect item I can do following
// $scope.myTeam = 1;
});
@cpoDesign
cpoDesign / app.js
Last active Aug 29, 2015
Implementing breadcrumbs into site with AngularJS v1.2.16. Implementation uses breadcrumb module by Ian Kennington Walter (http://ianvonwalter.com)
View app.js
var app = angular.module('app', ['ngRoute','ng-breadcrumbs']);
app.config(function($routeProvider) {
$routeProvider.when('/',
{
templateUrl: 'templates/list.html',
controller: 'listCtr',
label:'Administration'
})
.when('/detail/',
@cpoDesign
cpoDesign / example1.js
Last active Aug 29, 2015
using $resource in examples
View example1.js
// service with parameters
// How do I not send url template parameters with request body in angular?
// Source: http://stackoverflow.com/questions/19529483/how-do-i-not-send-url-template-parameters-with-request-body-in-angular
resource = $resource(
'http://foo.com/service/:type/:id',
{},
{save: {
method:'PUT',
transformRequest:function(data) {
delete data.type;
@cpoDesign
cpoDesign / index.html
Created Jun 16, 2014
Generic implementation for loader. It will target root scope while any promise is in process
View index.html
<p>
Implementation of loader in $rootScope
</p>
<div style="float:right;padding-top:1em;" data-ng-show="loading">
<img src="~/images/ajax-loader-inline.gif" /> Loading, please wait ...
</div>
@cpoDesign
cpoDesign / notificationBar.js
Last active Aug 29, 2015
Original implementation of directive message, contains only error message
View notificationBar.js
.directive("notificationBar", function () {
return {
transclude: false,
require: '^ngModel',
templateUrl: 'notificationBar/template.html',
scope: {
displayMessage: '@'
},
controller: function ($scope){
$scope.showMessage = function() {
@cpoDesign
cpoDesign / app.js
Created Jun 18, 2014
New version of notification directive to allow add errorMessage, successMessage, warnMessage
View app.js
var app = angular.module('app', []);
app.controller('priorityCtr',
function priorityCtr($rootScope, $scope){
$scope.showError = function(){
$rootScope.errorMessage='test error message';
$rootScope.successMessage='';
$rootScope.warnMessage='';
};
You can’t perform that action at this time.