Created
March 16, 2013 18:04
-
-
Save konrad-garus/5177550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tutorial.app | |
(:require [tutorial.controllers :as ctrl])) | |
(defn ng-route [provider path route-spec] | |
(.when provider path (clj->js route-spec))) | |
(defn ng-route-otherwise [provider route-spec] | |
(.otherwise provider (clj->js route-spec))) | |
(doto (angular/module "phonecat" (array "phonecatFilters" "phonecatServices")) | |
(.config (array "$routeProvider" | |
(fn [$routeProvider] | |
(doto $routeProvider | |
(ng-route "/phones" {:templateUrl "partials/phone-list.html" | |
:controller ctrl/phone-list-ctrl}) | |
(ng-route "/phones/:phoneId" {:templateUrl "partials/phone-detail.html" | |
:controller ctrl/phone-detail-ctrl}) | |
(ng-route-otherwise {:redirectTo "/phones"})))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tutorial.controllers) | |
(defn ^:export phone-list-ctrl [$scope Phone] | |
; Unfortunately, with custom actions (like Phone.query) the advanced | |
; compilation will lose the name, so we have to get it by string explicitly | |
(aset $scope "phones" ((aget Phone "query"))) | |
(aset $scope "orderProp" "age")) | |
(aset phone-list-ctrl "$inject" (array "$scope" "Phone")) | |
(defn ^:export phone-detail-ctrl [$scope $routeParams Phone] | |
; Setting $scope.phone from "right hand side" and $scope.mainImageUrl | |
; from success callback is nuts, but that's what the tutorial does | |
(aset $scope "phone" (.get Phone | |
(clj->js {:phoneId (aget $routeParams "phoneId")}) | |
(fn [phone] (aset $scope "mainImageUrl" (first (.-images phone)))))) | |
(aset $scope "setImage" (partial aset $scope "mainImageUrl"))) | |
(aset phone-detail-ctrl "$inject" (array "$scope" "$routeParams" "Phone")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tutorial.filters) | |
(doto (angular/module "phonecatFilters" (array)) | |
(.filter "checkmark" | |
(fn [] | |
(fn [input] | |
(if input "\u2713" "\u2718"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tutorial.services) | |
(doto (angular/module "phonecatServices" (array "ngResource")) | |
(.factory "Phone" | |
(array "$resource" | |
(fn [$resource] | |
($resource | |
"app/phones/:phoneId" | |
(clj->js {}) | |
(clj->js {:query {:method "GET" :params {:phoneId ""} :isArray true}})))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment