Posts

Showing posts with the label AngularJS

Material Angular Time Picker

Image
Continuing off my article on android's material timepickers I wanted to include this feature in the web based version of mypatco. I don't think it will be officially included in the material angular project but just something I could have as my own and if anyone comes across it to use it just as any other component. The key difference with timepickers vs. datepicker just picking time, since time is a more necessary feature for cases like notifications or alerts/alarms.



First and foremost I recommend checking out the project which I forked to personalize and strip out any code related to datepicker. Since the datepicker is already implemented in material angular, instead I'm just going to focus on time pickers.  The rest of my notes are in the repo's issue tracking. You may see the results on mypatco.org for an example.

Intuitive Third Party Packages

In relevance  to my package npm "flavorstrap" this is a little of a working progress for me and a few of my github projects I hopes it helps others. I've based this heavily on what I've seen others do  and what I think looks helpful to others. In that there enough context provided for others to go off from github package. I I face this problem with sometimes but I love to code so I spend the extra time to read someone else's code using a project as well. It helps if the documentation isn't there or if the code shows something the developer didn't think of.  Now this is just in my opinion and not so much a complain but advice for myself. I would definitely say I have used my share of third party libraries more often than actually written any but I do appreciate the ones well written. For example bootstrap and android's documentation pretty good and they even include some examples. However there are a couple of things I would suggest. For starters d…

Dynamic Development to Static Deploy

I believe this is an approach beneficial to any application for performance reason. If an application needs to be scalable but can remove the dynamic references there is a opportunity for improvement. With task runner or build process like gulp, grunt and asp.net mvc's bundle for example this is the same solution. What I'm point to is the things I want to create in javascript but don't necessarily need to be dynamic. For example Angular's template property with directives or component's and even routes. While I do like to use templateUrl in development for performances reason I want to include it in the statement as a template. If I'm trying to make the most of my code I need to inject directly
but for validation or organizational reasons I want to point it dynamically.
   This isn't a new problem in the computer science field but I think a lot of web developers will agree to injecting regardless if its development. It makes the code a little less manag…

UI-Bootstrap Collapsible Sticky Footer

I could have done this a lot of ways and ultimately I made it work with javascript modifying the class names. I also had to create multiple class names which I didn't like to much, I might come back and improve this but for now this is was I got. Also I call bootstrap+angularjs = ui-bootstrap, not sure if that's common sense but thought I should include it somewhere in my notes.


Working Example:
http://plnkr.co/edit/2N9ENlbw3bSvg1W9n0ch?p=preview

This little css was key to prevent any kind of animation on the collapse, which would result in a scrollbar appearing on the body. A scrollbar can appear when the content's too long but not on the sticky foot duh!

.no-animate { transition-duration: 0.0125s; }

Research
Angular-UI Bootstrap Collapse without animation - Stack Overflow
http://jsfiddle.net/paulalexandru/Z2Lu5/ - Was looking at this to see if I could reuse it but I ended but just doing my own thing.


Another way which I've seen

Using a sticky nav and position to the…

AngularJS: Single Page App Notes

This is article long overdue and I just wanted to talk about a few things I think others should know before starting. My first piece of advise is use use ui-route rather than ng-router. Really get to know ui-router because of its awesomeness.

Using Parameters
    I've come to really enjoy using parameters in all my apps and if you work with them well enough you can find some really cool ways to simplify your code. Example using the value of a parameter to set up detailed information in a child view saves time building out the whole app because with the url you can save the state. Just a small way to change your app rather than always looking up a global list. So that in mind for tracking information. Also when possible make "beautiful routes" or readable routes it helps other people following the structure.

Backward Compatible
    I have been able to get ui-router to work with ie8 using es5-shim, if you don't need to control the browser history you pretty much saf…

My Career at Coriell Institute and Personal Achievements

Image
The time has come where I need a change in my career and sadly that requires me to leave my current position at Coriell Institute. So just like what I did way back in 2013 with Northern Safety, I thought I would wrap things up in an article and look back on my achievements. 
Achievements (Order of Completion)
The ones with asterisks are ones I built in groups. 
Atlas Project - Storage Module -Provided an interface to store unique data sets in multi-forms.Coriell Bio-Repository Catalog* Atlas Project - Manager Module - Provided managers to control other user to access data.Blits Project - Modules  Issues & Repairs* - Reported equipment  that were broken or had problems.Inspections* - Collected equipment w/ schedules for inspections. Maintenance - Collected equipment  for regular maintenance and setup schedules. Dashboard* - Graphical dashboard on data provided from other modules.My Goals and Plans While attending Coriell, I had a lot of plans to bring the Front-end at Coriell on t…

AngularJS: ng-model cannot be assigned to functions

Image
This was one of the errors I faced when I started out with Angularjs, and the problem comes from thinking like Jquery developer still. I still use Jquery heavly in a few of my personal projects but have been avoiding this issue complete since.

Common error: nonassign Non-Assignable Expression


Solutions
One approach is to use directives to solve the issue and another is to use ng-init from what I've seen but I prefer using directives instead. http://jsfiddle.net/z5z9s/ - an example using ng-init (not by me).

Resources
AngularJS - ngModel cannot be assigned to function - Stack Overflow
http://stackoverflow.com/a/17793772/1265036

UI-grid: Bootstrap Styled and Dynamic Height for Pagination

Image
If you've looked at my catalog-demo, you might have noticed that I used UI-grid instead of Ng-grid. I still work on a few ng-grids but I've started to really use ui-grids.




Code:
$scope.gridOptions.onRegisterApi = function(gridApi){ gridApi.pagination.on.paginationChanged($scope, function (pageNumber, pageSize) { var newHeight = (pageSize * 30) + 68; angular.element(document.getElementsByClassName('grid')[0]).css('height', newHeight + 'px'); console.log('get pageSize - ', pageSize); }); };
Solution: https://fassetar.github.io/blog-examples/uigrid-responsiveheight/

Notes
To get the grid's height multiple the grid by 30px and the page size. Then add 68 to prevent the scroll-wheel moving the grid ever so slightly. Set the default for you're page size in css as well. The css I created to make the grid look like a bootstrap table is very basic and proba…

UI-grid: Bootstrap Styled and Dynamic Height for Pagination

Image
If you've looked at my catalog-demo, you might have noticed that I used UI-grid instead of Ng-grid. I still work on a few ng-grids but I've started to really use ui-grids.




Code:
$scope.gridOptions.onRegisterApi = function(gridApi){ gridApi.pagination.on.paginationChanged($scope, function (pageNumber, pageSize) { var newHeight = (pageSize * 30) + 68; angular.element(document.getElementsByClassName('grid')[0]).css('height', newHeight + 'px'); console.log('get pageSize - ', pageSize); }); };
Solution:

Notes
To get the grid's height multiple the grid by 30px and the page size. Then add 68 to prevent the scroll-wheel moving the grid ever so slightly. Set the default for you're page size in css as well. The css I created to make the grid look like a bootstrap table is very basic and probably could use a lot more styling. Like the column controls could l…

Angularjs + Asp.net MVC Routes with Partial Views

Image
Recently I've had the great opportunity to create something pretty awesome and I think it helped me seperate or clear up any confusion I had on project where I used two MVC frameworks on top of each other. Those two frameworks are usually AngularJs and Asp.net MVC. It can be a little hairy especially if you're new to Angularjs but when you use them right web developing is be a snap.

Client Side
$routeProvider.when('/', { templateUrl: 'home/_home', controller: 'AppCtrl' }).when('/product/:id', { templateUrl: function(params) { return 'home/_product/' + params.id; }, controller: 'AppCtrl' }).otherwise({ redirectTo: '/' });
  What's really important here is the route for product and the parameter (look where it takes id). The id can hookup to any middle tier and from there it can handed to a model bound partial view. You can even mix in angular html attributes since the page will be pu…

The Three Types of Material Design Libraries Available

Image
There are a tons Material Design projects out there but I choose these three because of their popularity and for the fact I just found these projects interesting for a few of own projects. I work in a variety of environments so each gave me certain advantages over the other. This article is just how I broke them down and what projects I plan use them for.

https://material.angularjs.org/Useful for when you are using angularjs.missing some stuff or just not shown in the documents.Great for my single page example.http://fezvrasta.github.io/bootstrap-material-design/Useful for bootstrap project and updating them to material design themes.Wish they used Sauce labs Tests like bootstrap.Great for updating my bootstrap sites and my blog.https://github.com/Dogfalo/materializeUses Jquery, and simple to get up and run just like bootstrap.Very close to other css libraries but still different; only a question of how much support.Great use for my emberjs project.

AngularJS: Not Working on Plunker

Image
Plunker is my goto cloud based IDE for quick setup and demo purposes. It's all about what you prefer really and there a tons of choices out there. This is two common problems that I faced but haven't since I'm aware of them, they're not really a problem anymore. I just wanted to keep notes on this incase I forget in the future.

First: "The plunker has ng-app instead of ng-app='directive' in the index.html"
Resource: Why this angularjs example doesn't work on plunker?

Second: "useangular.bootstrap($('#your_div_loaded_in_ajax'), "myApp","other_module"]);"
Resource:  AngularJs ReferenceError: angular is not defined

Notes
Also for the angular file don't use async or defer. This always goes without saying your custom script should come after the angular file even if its in the index.html file itself; just for good measure.

AngularJS: Facets in a Search Grid

Sometime back I really needed this code however it came a little too late and unfortunately didn't make it into the final product. However I have since then built a complete explain showing how to hand facets with little javascript code and with a whole lot of functionality!

Requirements
Load appropriate facets, make a search. Update the UI, reload page if necessary but scale up for a single page application. Make things bookmarkable but don't lose that awesomeness from SPA's.

Example
http://jsfiddle.net/t7kr8/211/ - I forget where I found this but its probably buried somewhere in my resources.

My Example
https://fassetar.github.io/blog-examples/catalog-facets/

Javascript code
var myApp = angular.module('myApp', []); myApp.controller('mainController', function($scope) { $scope.items = [{ item:"apples", flag: true }, { item:"oranges", flag: true }, { item:"pears&quo…

AngularJS: Select All Checkboxes

There were very few examples I found on this idea however most of them were not complete or depended on libraries were not included in my projects. I could simply include them and call it a day but that would be too easy. So I took the best example I could find and rewrote it in just AngularJS.

Code:
$scope.items = [ {item:1, flag: true}, {item:2, flag: true}, {item:3, flag: true }]; $scope.allNeedsClicked=function () { var newValue =!$scope.allNeedsMet(); for (var i =0; i <$scope.items.length; i++) { $scope.items[i].flag = newValue; } }; $scope.allNeedsMet=function () { var needsMet = []; for (var i =0; i <$scope.items.length; i++) { if ($scope.items[i].flag ===true) needsMet.push(true); } console.log($scope.items.length, needsMet.length); return (needsMet.length===$scope.items.length); };

Solution: https://fassetar.github.io/blog-examples/angularjs-select-all-checkboxes/

Notes
I should probably put this in a direct…

Bootstrap: Navbar Header

I don't see too many examples in bootstrap with something like this but what it is incase you don't know is a banner of some kind above the navbar. In fact I don't see too many sites with this kind of structure lately and from my experience I can understand why not. If you're going for responsiveness it's difficult to create since you are always checking to see if you have enough space on both sides for whatever it is your trying to display in between. From the sites that I have seen that do have this can really pull it off and use something similar to bootstrap's affix feature.
    When I first started using bootstrap which was sometime around 3.0, I was using the navbar-brand to hook into the styles already written for me. However since bootstrap 3.1navbar-brandhas now been given a height where before I was using the image's auto or attributes to adjust the height. I was able to give my header an even amount of padding around my header which might not …

A Thought on Server Side and Client Side Models

The truth is if you want to take server side models for example in Asp.net Mvc directly to a client side mvc framework's enviroment the common approach is via ajax. What has me troubled about this approach is that in some cases we already know the information that will be passed from server side to client before the call based on the request in some cases. So why do we make clients call this ajax? It's simply because we don't have enough ways to bridge the two technologies. Now just to be clear I'm not talking about third party api's or in any extreme case where the data is so dynamic that it is dependent on the front-end. What I am talking about is in cases where the data is in within the web application and we know what is needed by the page request. In case I haven't made myself clear (probably not) here is an example of what I mean.

Example
I'm going to use an example from a Asp.net Mvc perspective just because that is what I'm familar with but I …

Ng-grid: Export Feature

From a front-end standpoint it's easy to use ng-grid since a lot of the variables already exist. What I did in my implementation was leverage as much of ng-grid as possible before creating my own functions. Displayed fields in the grid that are checked by default are also checked in the export dialog. This feature was written up to handle hidden fields in the grid as well and gives the user the option to select or deselect all the available fields to export. However this example assumes that "name" field is a key on the server side and if passed to the server could give you whatever is in the database. So if you were looking to attach this to a more meaningful system you would pass just the key and fields to the server in order to get your results.

Solution:
<!--Html part--> <button type="button" class="btn btn-success pull-right" data-toggle="modal" data-target="#exportModal">Export to Data</button> <div cla…

Clicking Text Selects Corresponding Input

This article is just a quick note for some of the things I have forgotten sadly Html but also give an example using AngularJs.

Basic Html Solution
<inputid="1"type="checkbox"/><labelfor="1">TEST</label>
AngularJs Solution
<inputid="{{$index}}"type="checkbox"/><labelfor="{{$index}}"ng-model="field"></label>
Thoughts
   If I was going to make this more scalable I would need to guarantee that the id is unique. It might become a problem if I'm using multiple ng-repeats then the index would not be so special in the view , maybe I can do the index plus the number for that particular element.

Resources
Clicking the text to select corresponding radio button - Stack Overflow
http://plnkr.co/edit/llSc8o?p=preview

Angularjs: Blinking Syntax

This is a issue I call the angularjs "blinking syntax" because for a quick second users are able to see angularjs syntax in the web page, which isn't good. This issue becomes a greater problem for those with a slow connection. Cause is simple, using {{}} inline, which is much slower compared to other methods. Instead one solution is to use the ng-bind inline or can also create a directive.

Resource
why ng-bind is better than {{}} in angular? - Stack Overflow
inline conditionals in angular.js - Stack Overflow - Also by using a directive you can separate your logic more. Making your code cleaner or easier to maintain.
ng-cloak/ng-show elements blink - Stack Overflow - This will not always solve the problem, but using this along with ng-bing or a directive I think is appropriate.

Ng-grid: Start and End Items for a Grid

With my recent experience using ng-grid, I came up with two dynamic variables that would display based on the location of where they were in relationship to a particular page. I wasn't sure how to find a specific example on this. Since most might wrap this up with pagination concept it's difficult to find something on this for Ng-grid.. Not that I need an example but I like to think of them as separate, or as metadata.

Dependency
     I could have made the dependency on a ajax  return call but I had multiple ways for the Grid data to be insert, so rather than set it at that point I just hooked in the dom. If you wanted to go the other route just change the self.domAccessProvider call  to whatever you name your data object in the grid . As for the start number this is easier to handle, so there is no dependencies.

Solution
$scope.endItem = function () { var self = this; //Last page... if (self.maxPages() == self.pagingOptions.currentPage) { …