diff --git a/lab-regan/.babelrc b/lab-regan/.babelrc new file mode 100644 index 00000000..c13c5f62 --- /dev/null +++ b/lab-regan/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/lab-regan/.eslintrc b/lab-regan/.eslintrc new file mode 100644 index 00000000..633c96de --- /dev/null +++ b/lab-regan/.eslintrc @@ -0,0 +1,24 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + +Error: Parse error on line 11: +... "node": true, }, "ecmaFeatures": +----------------------^ +Expecting 'STRING' +}, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/lab-regan/.gitignore b/lab-regan/.gitignore new file mode 100644 index 00000000..d6f86b4e --- /dev/null +++ b/lab-regan/.gitignore @@ -0,0 +1,132 @@ + +# Created by https://www.gitignore.io/api/osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +###Local Files### +build + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,node,linux,windows diff --git a/lab-regan/app/assets/cfLogo.png b/lab-regan/app/assets/cfLogo.png new file mode 100644 index 00000000..38a23b2d Binary files /dev/null and b/lab-regan/app/assets/cfLogo.png differ diff --git a/lab-regan/app/assets/cfLogo.svg b/lab-regan/app/assets/cfLogo.svg new file mode 100644 index 00000000..1108a137 --- /dev/null +++ b/lab-regan/app/assets/cfLogo.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/lab-regan/app/assets/labicons9.png b/lab-regan/app/assets/labicons9.png new file mode 100644 index 00000000..4d7d93ac Binary files /dev/null and b/lab-regan/app/assets/labicons9.png differ diff --git a/lab-regan/app/component/gallery/create-gallery/_create-gallery.scss b/lab-regan/app/component/gallery/create-gallery/_create-gallery.scss new file mode 100644 index 00000000..df781bcb --- /dev/null +++ b/lab-regan/app/component/gallery/create-gallery/_create-gallery.scss @@ -0,0 +1,7 @@ +.create-gallery{ + h2{ + padding-left: 10%; + margin-bottom: -2em; + padding-top: 2em; + } +} diff --git a/lab-regan/app/component/gallery/create-gallery/create-gallery.html b/lab-regan/app/component/gallery/create-gallery/create-gallery.html new file mode 100644 index 00000000..12b89bf3 --- /dev/null +++ b/lab-regan/app/component/gallery/create-gallery/create-gallery.html @@ -0,0 +1,19 @@ + diff --git a/lab-regan/app/component/gallery/create-gallery/create-gallery.js b/lab-regan/app/component/gallery/create-gallery/create-gallery.js new file mode 100644 index 00000000..f5e34d7d --- /dev/null +++ b/lab-regan/app/component/gallery/create-gallery/create-gallery.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = { + template: require('./create-gallery.html'), + controller:['$log', 'galleryService', CreateGalleryController], + controllerAs: 'createGalleryCtrl' +}; + +function CreateGalleryController($log, galleryService){ + $log.debug('CreateGalleryController'); + + this.gallery = {}; + this.createGallery= function(){ + galleryService.createGallery(this.gallery) + .then( () => { + this.gallery.name = null; + this.gallery.desc = null; + }); + }; +}; diff --git a/lab-regan/app/component/gallery/edit-gallery/_edit-gallery.scss b/lab-regan/app/component/gallery/edit-gallery/_edit-gallery.scss new file mode 100644 index 00000000..d525478a --- /dev/null +++ b/lab-regan/app/component/gallery/edit-gallery/_edit-gallery.scss @@ -0,0 +1,42 @@ +@import "../../../scss/lib/theme/vars"; + +.edit { + width: 80%; + margin: 0 auto; + padding: 0.75em; + border-radius: 8px; + color: $site-primary; + div { + &:first-child{ + background: $site-secondary; + border-radius: 6px; + }, + &:nth-child(2){ + text-align: right; + } + .btn-std{ + margin-right: 0; + } + } + fieldset{ + margin: 0.75em 0; + + span{ + float: left; + &:first-child{ + font-weight: bold; + } + } + input .input-std { + float: left; + display: inline-block; + &:first-child { + border: 1px red dotted; + margin-left: 4%; + } + } + } + } + // & > span { + // margin: 1em 0; + // } diff --git a/lab-regan/app/component/gallery/edit-gallery/edit-gallery.html b/lab-regan/app/component/gallery/edit-gallery/edit-gallery.html new file mode 100644 index 00000000..82d1b5ae --- /dev/null +++ b/lab-regan/app/component/gallery/edit-gallery/edit-gallery.html @@ -0,0 +1,23 @@ +
+ +
diff --git a/lab-regan/app/component/gallery/edit-gallery/edit-gallery.js b/lab-regan/app/component/gallery/edit-gallery/edit-gallery.js new file mode 100644 index 00000000..5f660b4a --- /dev/null +++ b/lab-regan/app/component/gallery/edit-gallery/edit-gallery.js @@ -0,0 +1,21 @@ +'use strict'; + +require('./_edit-gallery.scss'); + +module.exports = { + template: require('./edit-gallery.html'), + controller: ['$log', 'galleryService', EditGalleryController], + controllerAs: 'editGalleryCtrl', + //this is a reserved property name + bindings: { + gallery: '<' + } +}; + +function EditGalleryController($log, galleryService){ + $log.debug('EditGalleryController'); + + this.updateGallery = function(){ + galleryService.updateGallery(this.gallery._id, this.gallery); + }; +}; diff --git a/lab-regan/app/component/gallery/gallery-item/_gallery-item.scss b/lab-regan/app/component/gallery/gallery-item/_gallery-item.scss new file mode 100644 index 00000000..fd396bc4 --- /dev/null +++ b/lab-regan/app/component/gallery/gallery-item/_gallery-item.scss @@ -0,0 +1,45 @@ +@import "../../../scss/lib/theme/vars"; + +.gallery-item { + .current-item { + width: 80%; + margin: 0 auto; + background: $site-secondary; + padding: 0.75em; + border-radius: 8px; + color: $site-primary; + div{ + margin: 0.75em 0; + + span{ + &:first-child{ + font-weight: bold; + } + } + } + & > span { + margin: 1em 0; + } + } + .edit-container { + width: 100%; + div{ + width: 80%; + margin: auto; + text-align: right; + span { + display: inline-block; + background: $site-primary; + color: $white; + padding: 0.25em 2em; + border-radius: 8px; + margin: 0.5em 0; + margin-bottom: 1.5em; + &:last-child{ + background: $site-tertiary; + color: $black; + } + } + } + } +} diff --git a/lab-regan/app/component/gallery/gallery-item/gallery-item.html b/lab-regan/app/component/gallery/gallery-item/gallery-item.html new file mode 100644 index 00000000..be9a1255 --- /dev/null +++ b/lab-regan/app/component/gallery/gallery-item/gallery-item.html @@ -0,0 +1,21 @@ + diff --git a/lab-regan/app/component/gallery/gallery-item/gallery-item.js b/lab-regan/app/component/gallery/gallery-item/gallery-item.js new file mode 100644 index 00000000..eca39d2a --- /dev/null +++ b/lab-regan/app/component/gallery/gallery-item/gallery-item.js @@ -0,0 +1,21 @@ +'use strict'; + +require('./_gallery-item.scss'); + +module.exports = { + template: require('./gallery-item.html'), + controller: ['$log', 'galleryService', GalleryItemController], + controllerAs: 'galleryItemCtrl', + bindings: { + gallery: '<' + } +}; + +function GalleryItemController($log, galleryService){ + $log.debug('GalleryItemController'); + + this.showEditGallery = false; + this.deleteGallery = function(){ + galleryService.deleteGallery(this.gallery._id); + }; +}; diff --git a/lab-regan/app/component/gallery/thumbnail-container/_thumbnail-container.scss b/lab-regan/app/component/gallery/thumbnail-container/_thumbnail-container.scss new file mode 100644 index 00000000..251b99fb --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail-container/_thumbnail-container.scss @@ -0,0 +1,3 @@ +.thumbnail-container { + margin: -15em 3em 1em 3em; +} diff --git a/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.html b/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.html new file mode 100644 index 00000000..5e32c32c --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.html @@ -0,0 +1,7 @@ +
+

{{thumbnailContainerCtrl.gallery.name | uppercase}}

+ +
+ +
+
diff --git a/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.js b/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.js new file mode 100644 index 00000000..18bf16d4 --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail-container/thumbnail-container.js @@ -0,0 +1,11 @@ +'use strict'; + +require('./_thumbnail-container.scss'); + +module.exports = { + template: require('./thumbnail-container.html'), + controllerAs: 'thumbnailContainerCtrl', + bindings: { + gallery: '<' + } +}; diff --git a/lab-regan/app/component/gallery/thumbnail/_thumbnail.scss b/lab-regan/app/component/gallery/thumbnail/_thumbnail.scss new file mode 100644 index 00000000..1188e2e1 --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail/_thumbnail.scss @@ -0,0 +1,6 @@ +.thumbnail { + border: 2px red dotted; + img { + width: 100%; + } +} diff --git a/lab-regan/app/component/gallery/thumbnail/thumbnail.html b/lab-regan/app/component/gallery/thumbnail/thumbnail.html new file mode 100644 index 00000000..27a44836 --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail/thumbnail.html @@ -0,0 +1,4 @@ +
+ {{ thumbnailCtrl.pic.desc }} + delete +
diff --git a/lab-regan/app/component/gallery/thumbnail/thumbnail.js b/lab-regan/app/component/gallery/thumbnail/thumbnail.js new file mode 100644 index 00000000..eaf924e0 --- /dev/null +++ b/lab-regan/app/component/gallery/thumbnail/thumbnail.js @@ -0,0 +1,23 @@ +'use strict'; + +require('./_thumbnail.scss'); + +module.exports = { + template: require('./thumbnail.html'), + controller: ['$log', 'picService', ThumbnailController], + controllerAs: 'thumbnailCtrl', + bindings: { + pic: '<', + gallery: '<' + } +}; + +function ThumbnailController($log, picService){ + $log.debug('ThumbnailController'); + + this.deletePic = function(){ + $log.debug('thumbnailCtrl.deletePic'); + + picService.deletePic(this.gallery, this.pic._id); + } +}; diff --git a/lab-regan/app/component/gallery/upload-pic/_upload-pic.scss b/lab-regan/app/component/gallery/upload-pic/_upload-pic.scss new file mode 100644 index 00000000..e69de29b diff --git a/lab-regan/app/component/gallery/upload-pic/upload-pic.html b/lab-regan/app/component/gallery/upload-pic/upload-pic.html new file mode 100644 index 00000000..0fff7540 --- /dev/null +++ b/lab-regan/app/component/gallery/upload-pic/upload-pic.html @@ -0,0 +1,17 @@ +
+
+

upload a new pic

+
+ + +
+
+

+ select a pic to upload! +

+ +
+
+
diff --git a/lab-regan/app/component/gallery/upload-pic/upload-pic.js b/lab-regan/app/component/gallery/upload-pic/upload-pic.js new file mode 100644 index 00000000..e4dcb1d4 --- /dev/null +++ b/lab-regan/app/component/gallery/upload-pic/upload-pic.js @@ -0,0 +1,26 @@ +'use strict'; + +require('./_upload-pic.scss'); + +module.exports = { + template: require('./upload-pic.html'), + controller: ['$log', 'picService', UploadPicController], + controllerAs: 'uploadPicCtrl', + bindings: { + gallery: '<' + } +}; + +function UploadPicController($log, picService){ + $log.debug('UploadPicController'); + + this.pic = {}; + this.uploadPic = function(){ + picService.uploadGalleryPic(this.gallery, this.pic) + .then( (returnobj) => { + this.pic.name = null; + this.pic.desc = null; + this.pic.file = null; + }); + }; +}; diff --git a/lab-regan/app/component/landing/login/_login.scss b/lab-regan/app/component/landing/login/_login.scss new file mode 100644 index 00000000..e69de29b diff --git a/lab-regan/app/component/landing/login/login.html b/lab-regan/app/component/landing/login/login.html new file mode 100644 index 00000000..0dea6f46 --- /dev/null +++ b/lab-regan/app/component/landing/login/login.html @@ -0,0 +1,31 @@ +
+
+
+ +
+ +
+ +
+ + +
+
diff --git a/lab-regan/app/component/landing/login/login.js b/lab-regan/app/component/landing/login/login.js new file mode 100644 index 00000000..dec7c927 --- /dev/null +++ b/lab-regan/app/component/landing/login/login.js @@ -0,0 +1,27 @@ +'use strict'; + +require('./_login.scss'); + +module.exports = { + template: require('./login.html'), + controller: ['$log', '$location', 'authService', LoginController], + controllerAs: 'loginCtrl' +}; + +function LoginController($log, $location, authService) { + $log.debug('LoginController'); + + authService.getToken() + .then( () => { + $location.url('/home'); + }); + + this.login = function() { + $log.debug('loginCtrl.login'); + + authService.login(this.user) + .then( () => { + $location.url('/home'); + }); + }; +}; diff --git a/lab-regan/app/component/landing/signup/_signup.scss b/lab-regan/app/component/landing/signup/_signup.scss new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lab-regan/app/component/landing/signup/_signup.scss @@ -0,0 +1 @@ + diff --git a/lab-regan/app/component/landing/signup/signup.html b/lab-regan/app/component/landing/signup/signup.html new file mode 100644 index 00000000..e1e1b7aa --- /dev/null +++ b/lab-regan/app/component/landing/signup/signup.html @@ -0,0 +1,26 @@ +
+
+

sign up

+ + + + + + + +
+ +
diff --git a/lab-regan/app/component/landing/signup/signup.js b/lab-regan/app/component/landing/signup/signup.js new file mode 100644 index 00000000..b5923714 --- /dev/null +++ b/lab-regan/app/component/landing/signup/signup.js @@ -0,0 +1,25 @@ +'use strict'; + +module.exports = { + template: require('./signup.html'), + controller: ['$log', '$location', 'authService', SignupController], + controllerAs: 'signupCtrl' +}; + +function SignupController($log, $location, authService) { + $log.debug('SignupController'); + + authService.getToken() + .then( () => { + $location.url('/home'); + }); + + this.signup = function(user) { + $log.debug('signupCtrl.signup'); + + authService.signup(user) + .then( () => { + $location.url('/home') + }); + }; +}; diff --git a/lab-regan/app/component/navbar/_navbar.scss b/lab-regan/app/component/navbar/_navbar.scss new file mode 100644 index 00000000..3bc4f452 --- /dev/null +++ b/lab-regan/app/component/navbar/_navbar.scss @@ -0,0 +1,24 @@ +.navbar { + img{ + width: 3em; + height: 3em; + margin: auto; + } + ul { + height: 100%; + width: 80%; + margin: auto; + li { + float: left; + height: 100%; + display: inline-block; + padding: auto 0; + &:first-child { + padding-top: 0.5em; + } + &:last-child { + padding: 1.5em; + } + } + } +} diff --git a/lab-regan/app/component/navbar/navbar.html b/lab-regan/app/component/navbar/navbar.html new file mode 100644 index 00000000..8deb1c26 --- /dev/null +++ b/lab-regan/app/component/navbar/navbar.html @@ -0,0 +1,18 @@ + diff --git a/lab-regan/app/component/navbar/navbar.js b/lab-regan/app/component/navbar/navbar.js new file mode 100644 index 00000000..7307ff2c --- /dev/null +++ b/lab-regan/app/component/navbar/navbar.js @@ -0,0 +1,43 @@ +'use strict'; + +require('./_navbar.scss'); + +module.exports = { + template: require('./navbar.html'), + controller: ['$log', '$location', '$rootScope', 'authService', NavbarController], + controllerAs: 'navbarCtrl' +}; + +function NavbarController($log, $location, $rootScope, authService){ + $log.debug('NavbarController'); + + this.checkPath = function(){ + let path = $location.path(); + if(path === '/join'){ + this.hideButtons = true; + }; + if(path !== '/join'){ + this.hideButtons = false; + authService.getToken() + .catch( () => { + // $location.url('/join#login'); + $location.url('/join#signup'); + }); + }; + }; + this.checkPath(); + + $rootScope.$on('$locationChangeSuccess', () => { + this.checkPath(); + }); + + this.logout = function(){ + $log.log('navbarCtrl.logout'); + + this.hideButtons = true; + authService.logout() + .then( () => { + $location.url('/'); + }); + }; +}; diff --git a/lab-regan/app/config/log-config.js b/lab-regan/app/config/log-config.js new file mode 100644 index 00000000..c84d58c8 --- /dev/null +++ b/lab-regan/app/config/log-config.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = ['$logProvider', logConfig]; + +function logConfig($logProvider) { + $logProvider.debugEnabled(__DEBUG__); +}; diff --git a/lab-regan/app/config/router-config.js b/lab-regan/app/config/router-config.js new file mode 100644 index 00000000..5357c24b --- /dev/null +++ b/lab-regan/app/config/router-config.js @@ -0,0 +1,31 @@ +'use strict'; + +module.exports = ['$stateProvider', '$urlRouterProvider', routerConfig]; + +function routerConfig($stateProvider, $urlRouterProvider) { + $urlRouterProvider.when('', '/join#signup'); + $urlRouterProvider.when('/', '/join#signup'); + $urlRouterProvider.when('/signup', '/join#signup'); + $urlRouterProvider.when('/login', '/join#login'); + + let states = [ + { + name: 'home', + url: '/home', + template: require('../view/home/home.html'), + controller: 'HomeController', + controllerAs: 'homeCtrl' + }, + { + name: 'landing', + url: '/join', + template: require('../view/landing/landing.html'), + controller: 'LandingController', + controllerAs: 'landingCtrl' + } + ]; + + states.forEach( state => { + $stateProvider.state(state); + }); +}; diff --git a/lab-regan/app/directive/_social-icons.scss b/lab-regan/app/directive/_social-icons.scss new file mode 100644 index 00000000..fb36502d --- /dev/null +++ b/lab-regan/app/directive/_social-icons.scss @@ -0,0 +1,39 @@ +.social-media-icons { + ul { + li{ + margin-top: 1em; + margin-left: 10%; + a { + float: left; + width: 128px; + height: 128px; + margin-right: 8px; + + &:first-child{ + background: url('../assets/labicons9.png') no-repeat 0 0; + width: 52px; + height: 52px; + } + + &:nth-child(2) { + background: url('../assets/labicons9.png') no-repeat -60px 0; + width: 52px; + height: 52px; + } + + &:nth-child(3) { + background: url('../assets/labicons9.png') no-repeat 0 -63px; + width: 52px; + height: 52px; + } + + &:last-child { + background: url('../assets/labicons9.png') no-repeat -60px -63px; + width: 52px; + height: 52px; + } + + } +} +} +} diff --git a/lab-regan/app/directive/social-icons.html b/lab-regan/app/directive/social-icons.html new file mode 100644 index 00000000..95b07574 --- /dev/null +++ b/lab-regan/app/directive/social-icons.html @@ -0,0 +1,6 @@ +
+

{{socialIconsCtrl.tester}}

+ +
diff --git a/lab-regan/app/directive/social-icons.js b/lab-regan/app/directive/social-icons.js new file mode 100644 index 00000000..d14562fe --- /dev/null +++ b/lab-regan/app/directive/social-icons.js @@ -0,0 +1,20 @@ +'use strict'; + +require('./_social-icons.scss'); + +module.exports = function(){ + return { + restrict: 'EAC', + template: require('./social-icons.html'), + controller: ['$log', SocialIconsController], + bindToController: true, + controllerAs: 'socialIconsCtrl', + scope: { + tester: '@' + } + }; +}; + +function SocialIconsController(){ + this.icons = ['snapchat', 'github', 'google', 'youtube'] +}; diff --git a/lab-regan/app/entry.js b/lab-regan/app/entry.js new file mode 100644 index 00000000..8ecfd5f0 --- /dev/null +++ b/lab-regan/app/entry.js @@ -0,0 +1,54 @@ +'use strict'; + +require('./scss/main.scss'); + +const path = require('path'); +const angular = require('angular'); +const camelcase = require('camelcase'); +const pascalcase = require('pascalcase'); +const uiRouter = require('angular-ui-router'); +const ngTouch = require('angular-touch'); +const ngAnimate = require('angular-animate'); +const ngFileUpload = require('ng-file-upload'); + +const cfgram = angular.module('cfgram', [ngTouch, ngAnimate, uiRouter, ngFileUpload]); + +let context = require.context('./config/', true, /\.js$/); +context.keys().forEach( key => { + cfgram.config(context(key)); +}); + +context = require.context('./view/', true, /\.js$/); +context.keys().forEach( key => { + let name = pascalcase(path.basename(key, '.js')); + let module = context(key); + cfgram.controller(name, module); +}); + +context = require.context('./service/', true, /\.js$/); +context.keys().forEach( key => { + let name = camelcase(path.basename(key, '.js')); + let module = context(key); + cfgram.service(name, module); +}); + +context = require.context('./component/', true, /\.js$/); +context.keys().forEach( key => { + let name = camelcase(path.basename(key, '.js')); + let module = context(key); + cfgram.component(name, module); +}); + +context = require.context('./filter/', true, /\.js$/); +context.keys().forEach( key => { + let name = camelcase(path.basename(key, '.js')); + let module = context(key); + cfgram.filter(name, module); +}); + +context = require.context('./directive/', true, /\.js$/); +context.keys().forEach( key => { + let name = camelcase(path.basename(key, '.js')); + let module = context(key); + cfgram.directive(name, module); +}); diff --git a/lab-regan/app/filter/gallery-search.js b/lab-regan/app/filter/gallery-search.js new file mode 100644 index 00000000..5dff6e13 --- /dev/null +++ b/lab-regan/app/filter/gallery-search.js @@ -0,0 +1,16 @@ +'use strict'; + +module.exports = function(){ + return function(galleries, searchTerm){ + let fuzzyRegEx = generateFuzzyRegex(searchTerm); + return galleries.filter(gallery => { + return fuzzyRegEx.test(gallery.name.toUpperCase()); + }); + }; +}; + +function generateFuzzyRegex(input){ + if(!input) return /.*/; + let fuzzyString = '.*' + input.toUpperCase().split('').join('.*') + '.*'; + return new RegExp(fuzzyString); +}; diff --git a/lab-regan/app/index.html b/lab-regan/app/index.html new file mode 100644 index 00000000..c6929e9b --- /dev/null +++ b/lab-regan/app/index.html @@ -0,0 +1,19 @@ + + + + + + cfgram + + +
+ +
+
+ +
+ + + diff --git a/lab-regan/app/scss/lib/base/_base.scss b/lab-regan/app/scss/lib/base/_base.scss new file mode 100644 index 00000000..139ca63a --- /dev/null +++ b/lab-regan/app/scss/lib/base/_base.scss @@ -0,0 +1,9 @@ +@import "../theme/vars"; + +*{ + box-sizing: border-box; +} + +body { + background: $site-secondary; +} diff --git a/lab-regan/app/scss/lib/base/_reset.scss b/lab-regan/app/scss/lib/base/_reset.scss new file mode 100644 index 00000000..ed11813c --- /dev/null +++ b/lab-regan/app/scss/lib/base/_reset.scss @@ -0,0 +1,48 @@ +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} diff --git a/lab-regan/app/scss/lib/layout/_footer.scss b/lab-regan/app/scss/lib/layout/_footer.scss new file mode 100644 index 00000000..fc441b69 --- /dev/null +++ b/lab-regan/app/scss/lib/layout/_footer.scss @@ -0,0 +1,19 @@ +@import "../theme/vars"; + +// footer { +// div{ +// ul{ +// li{ +// &:first-child{ +// // background: blue; +// background-image: url('../../../assets/fourIcons.png') no-repeat -268px -252px; +// width: 128px; +// height: 128px; +// } +// } +// } +// } +// } +footer { + height: 4em; +} diff --git a/lab-regan/app/scss/lib/layout/_header.scss b/lab-regan/app/scss/lib/layout/_header.scss new file mode 100644 index 00000000..cc38d31e --- /dev/null +++ b/lab-regan/app/scss/lib/layout/_header.scss @@ -0,0 +1,13 @@ +@import "../theme/vars"; + +header { + width: 100%; + height: 4em; + background: $site-primary; + + .btn-std { + float: right; + margin-right: 10%; + margin-top: 2em; + } +} diff --git a/lab-regan/app/scss/lib/layout/_main.scss b/lab-regan/app/scss/lib/layout/_main.scss new file mode 100644 index 00000000..8ebc30ae --- /dev/null +++ b/lab-regan/app/scss/lib/layout/_main.scss @@ -0,0 +1,22 @@ +@import "../theme/vars"; + +form { + width: 100%; + padding-top: 2.5em; + h3 { + margin-left: 10%; + margin-bottom: 1.5%; + } + input { + display: block; + width: 80%; + height: 4em; + margin: auto; + margin-bottom: 3em; + border-radius: 8px; + } +.btn-std { + width: 25%; + margin-right: 10%; +} +} diff --git a/lab-regan/app/scss/lib/theme/_vars.scss b/lab-regan/app/scss/lib/theme/_vars.scss new file mode 100644 index 00000000..6b6f5b70 --- /dev/null +++ b/lab-regan/app/scss/lib/theme/_vars.scss @@ -0,0 +1,7 @@ +$site-primary: #444; +$site-secondary: #888; +$site-tertiary: #aaa; +$black: #000; +$white: #fff; +$grey: #ccc; +$gutter: 1vw; diff --git a/lab-regan/app/scss/main.scss b/lab-regan/app/scss/main.scss new file mode 100644 index 00000000..270f25d6 --- /dev/null +++ b/lab-regan/app/scss/main.scss @@ -0,0 +1,16 @@ +// base +@import "lib/base/reset"; +@import "lib/base/base"; +// layout +@import "lib/layout/header"; +@import "lib/layout/footer"; +@import "lib/layout/main"; +// components +@import "../component/navbar/navbar"; +@import "../component/landing/signup/signup"; +@import "../component/landing/login/login"; +@import "../component/gallery/gallery-item/gallery-item"; +@import "../component/gallery/edit-gallery/edit-gallery"; +@import "../component/gallery/create-gallery/create-gallery"; +@import "../component/gallery/thumbnail-container/thumbnail-container"; +@import "../directive/social-icons"; diff --git a/lab-regan/app/service/auth-service.js b/lab-regan/app/service/auth-service.js new file mode 100644 index 00000000..95ad39e7 --- /dev/null +++ b/lab-regan/app/service/auth-service.js @@ -0,0 +1,89 @@ +'use strict'; + +module.exports = ['$q', '$log', '$http', '$window', authService]; + +function authService($q, $log, $http, $window) { + $log.debug('authService'); + + let service = {}; + let token = null; + + function setToken(_token) { + $log.debug('authService.setToken'); + + if (! _token) { + return $q.reject(new Error('no token')); + }; + + $window.localStorage.setItem('token', _token); + token = _token; + return $q.resolve(token); + } + + service.getToken = function() { + $log.debug('authService.getToken'); + if (token) { + return $q.resolve(token); + }; + + token = $window.localStorage.getItem('token'); + if (token) return $q.resolve(token); + return $q.reject(new Error('token not found')); + }; + + service.signup = function(user) { + $log.debug('authService.signup'); + + let url = `${__API_URL__}/api/signup`; + let config = { + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }; + + + return $http.post(url, user, config) + .then( res => { + $log.log('success:', res.data); + return setToken(res.data); + }) + .catch( err => { + $log.error('failure:', err.message); + return $q.reject(err); + }); + }; + + service.logout = function() { + $log.debug('authService.logout'); + + $window.localStorage.removeItem('token'); + token = null; + return $q.resolve(); + }; + + service.login = function(user) { + $log.debug('authService.login'); + + let url = `${__API_URL__}/api/login`; + let base64 = $window.btoa(`${user.username}:${user.password}`); + let config = { + headers: { + Accept: 'application/json', + Authorization: `Basic ${base64}` + } + }; + + return $http.get(url, config) + .then( res => { + $log.log('success', res.data); + return setToken(res.data); + }) + .catch( err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + return service; +}; diff --git a/lab-regan/app/service/gallery-service.js b/lab-regan/app/service/gallery-service.js new file mode 100644 index 00000000..daf835f9 --- /dev/null +++ b/lab-regan/app/service/gallery-service.js @@ -0,0 +1,122 @@ +'use strict'; + +module.exports = ['$q', '$log', '$http', 'authService', galleryService]; + +function galleryService($q, $log, $http, authService){ + $log.debug('galleryService'); + + let service = {}; + service.galleries = []; + + service.createGallery = function(gallery){ + $log.debug('galleryService.createGallery'); + + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery`; + let config = { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + } + }; + return $http.post(url, gallery, config); + }) + .then( res => { + $log.log('gallery created'); + let gallery = res.data; + service.galleries.unshift(gallery); + return gallery; + }) + .catch(err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + service.fetchGalleries = function(){ + $log.debug('galleryService.fetchGalleries'); + + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery`; + let config = { + headers: { + 'Accept': 'application/json', + 'Authorization': `Bearer ${token}` + } + }; + return $http.get(url, config); + }) + .then( res => { + $log.log('galleries retrieved'); + service.galleries = res.data; + return service.galleries; + }) + .catch(err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + service.updateGallery = function(galleryID, galleryData){ + $log.debug('galleryService.updateGallery'); + + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery/${galleryID}` + let config = { + headers: { + 'Accept': 'application/json', + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + } + }; + return $http.put(url, galleryData, config); + }) + .then( res => { + for( let i = 0; i < service.galleries.length; i++){ + let current = service.galleries[i]; + if(current._id === galleryID){ + service.galleries[i] = res.data; + break; + }; + }; + return res.data; + }) + .catch(err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + service.deleteGallery = function(galleryID){ + $log.debug('galleryService.deleteGallery'); + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery/${galleryID}`; + let config = { + headers: { + 'Authorization': `Bearer ${token}` + } + }; + return $http.delete(url, config); + }) + .then( res => { + for(let i =0; i < service.galleries.length; i++){ + let current = service.galleries[i]; + if(current._id === galleryID){ + service.galleries.splice(i, 1); + break; + }; + }; + }) + .catch( err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + return service; +}; diff --git a/lab-regan/app/service/pic-service.js b/lab-regan/app/service/pic-service.js new file mode 100644 index 00000000..c29e3bbe --- /dev/null +++ b/lab-regan/app/service/pic-service.js @@ -0,0 +1,70 @@ +'use strict'; + +module.exports = ['$q', '$log', '$http', 'Upload', 'authService', picService]; + +function picService($q, $log, $http, Upload, authService){ + $log.debug('picService'); + + let service = {}; + + service.uploadGalleryPic = function(galleryData, picData){ + $log.debug('service.uploadGalleryPic'); + + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery/${galleryData._id}/pic`; + let headers = { + 'Authorization': `Bearer ${token}`, + 'Accept': 'application/json' + }; + return Upload.upload({ + url, + headers, + method: 'POST', + data: { + name: picData.name, + desc: picData.desc, + file: picData.file + } + }); + }) + .then( res => { + galleryData.pics.unshift(res.data); + return res.data; + }) + .catch( err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + service.deletePic = function(galleryData, picID){ + $log.debug('galleryService.deletePic'); + console.log(galleryData.pics, 'WOW THERE IS THE pic array!'); + return authService.getToken() + .then( token => { + let url = `${__API_URL__}/api/gallery/${galleryData._id}/pic/${picID}`; + let config = { + headers: { + 'Authorization': `Bearer ${token}` + } + }; + return $http.delete(url, config); + }) + .then( res => { + for(let i = 0; i < galleryData.pics.length; i++){ + let current = galleryData.pics[i]; + if(current._id === picID){ + galleryData.pics.splice(i, 1); + break; + }; + }; + }) + .catch( err => { + $log.error(err.message); + return $q.reject(err); + }); + }; + + return service; +}; diff --git a/lab-regan/app/view/home/_home.scss b/lab-regan/app/view/home/_home.scss new file mode 100644 index 00000000..fbb35988 --- /dev/null +++ b/lab-regan/app/view/home/_home.scss @@ -0,0 +1,24 @@ +@import "../../scss/lib/theme/vars"; + +.home { + background: $grey; + h2{ + padding-left: 10%; + font-weight: bold; + } + + ul { + width: 100%; + padding-bottom: 15em; + .bolden { + font-weight: bold; + } + } + .fuzzy-input { + margin-left: 10%; + margin-bottom: 2em; + width: 35%; + height: 3em; + border-radius: 8px; + } +} diff --git a/lab-regan/app/view/home/home-controller.js b/lab-regan/app/view/home/home-controller.js new file mode 100644 index 00000000..aac11dac --- /dev/null +++ b/lab-regan/app/view/home/home-controller.js @@ -0,0 +1,34 @@ +'use strict'; + +require('./_home.scss'); + +module.exports = ['$log', '$rootScope', 'galleryService', HomeController]; + +function HomeController($log, $rootScope, galleryService) { + $log.debug('HomeController'); + + this.galleries = []; + + this.fetchGalleries = function() { + galleryService.fetchGalleries() + .then( galleries => { + this.galleries = galleries; + this.currentGallery = galleries[0]; + + }); + }; + + this.galleryDeleteDone = function(gallery){ + if(this.currentGallery._id === gallery._id){ + this.currentGallery = null; + } + }; + + this.fetchGalleries(); + + $rootScope.$on('$locationChangeSuccess', () => { + this.fetchGalleries(); + }); + + +}; diff --git a/lab-regan/app/view/home/home.html b/lab-regan/app/view/home/home.html new file mode 100644 index 00000000..05cf7335 --- /dev/null +++ b/lab-regan/app/view/home/home.html @@ -0,0 +1,12 @@ +
+ + + + +

Galleries

+

{{homeCtrl.galleries[0]}}

+ + +
diff --git a/lab-regan/app/view/landing/_landing.scss b/lab-regan/app/view/landing/_landing.scss new file mode 100644 index 00000000..49b4e18e --- /dev/null +++ b/lab-regan/app/view/landing/_landing.scss @@ -0,0 +1,7 @@ +.landing { + min-height: 14em; + p { + width: 23%; + margin-left: 80%; + } +} diff --git a/lab-regan/app/view/landing/landing-controller.js b/lab-regan/app/view/landing/landing-controller.js new file mode 100644 index 00000000..783dfec3 --- /dev/null +++ b/lab-regan/app/view/landing/landing-controller.js @@ -0,0 +1,10 @@ +'use strict'; + +require('./_landing.scss'); + +module.exports = ['$log', '$location', '$rootScope', 'authService', LandingController]; + +function LandingController($log, $location, authService) { + let url = $location.url(); + this.showSignup = url === '/join#signup' || url === '/join'; +}; diff --git a/lab-regan/app/view/landing/landing.html b/lab-regan/app/view/landing/landing.html new file mode 100644 index 00000000..76a71302 --- /dev/null +++ b/lab-regan/app/view/landing/landing.html @@ -0,0 +1,24 @@ +
+
+
+ + + + +
+
+ +
+
+ +

want to sign up?

+ + + +
+
+
diff --git a/lab-regan/karma.conf.js b/lab-regan/karma.conf.js new file mode 100644 index 00000000..e93869bb --- /dev/null +++ b/lab-regan/karma.conf.js @@ -0,0 +1,74 @@ +// Karma configuration +// Generated on Tue Apr 04 2017 10:16:36 GMT-0700 (PDT) +const webpack = require('./webpack.config.js'); +delete webpack.entry; + +module.exports = function(config) { + config.set({ + webpack, + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + 'app/entry.js', + 'test/**/*-test.js', 'node_modules/angular-mocks/angular-mocks.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + 'test/**/*-test.js': ['webpack'], + 'app/entry.js': ['webpack'] + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['mocha'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/lab-regan/package.json b/lab-regan/package.json new file mode 100644 index 00000000..05806e0d --- /dev/null +++ b/lab-regan/package.json @@ -0,0 +1,53 @@ +{ + "name": "lab-regan", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "./node_modules/webpack/bin/webpack.js", + "watch": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot", + "test": "./node_modules/karma/bin/karma start --single-run", + "test-watch": "./node_modules/karma/bin/karma start" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "angular": "^1.6.3", + "angular-animate": "^1.6.3", + "angular-touch": "^1.6.3", + "angular-ui-router": "^0.4.2", + "babel-core": "^6.24.0", + "babel-loader": "^6.4.1", + "babel-preset-es2015": "^6.24.0", + "camelcase": "^4.0.0", + "clean-webpack-plugin": "^0.1.16", + "css-loader": "^0.27.3", + "dotenv": "^4.0.0", + "extract-text-webpack-plugin": "^2.1.0", + "file-loader": "^0.10.1", + "html-loader": "^0.4.5", + "html-webpack-plugin": "^2.28.0", + "image-webpack-loader": "^3.3.0", + "ng-file-upload": "^12.2.13", + "node-sass": "^4.5.1", + "pascalcase": "^0.1.1", + "resolve-url-loader": "^2.0.2", + "sass-loader": "^6.0.3", + "style-loader": "^0.16.1", + "svg-loader": "0.0.2", + "ui-router": "^1.0.0-alpha.3", + "url-loader": "^0.5.8", + "webpack": "^2.3.2" + }, + "devDependencies": { + "angular-mocks": "^1.6.4", + "jasmine-core": "^2.5.2", + "karma": "^1.5.0", + "karma-chrome-launcher": "^2.0.0", + "karma-jasmine": "^1.1.0", + "karma-mocha-reporter": "^2.2.3", + "karma-webpack": "^2.0.3", + "webpack-dev-server": "^2.4.2" + } +} diff --git a/lab-regan/test/auth-service-test.js b/lab-regan/test/auth-service-test.js new file mode 100644 index 00000000..7825a6ea --- /dev/null +++ b/lab-regan/test/auth-service-test.js @@ -0,0 +1,29 @@ +'use strict'; + +describe('Auth Service', function(){ + beforeEach( () => { + angular.mock.module('cfgram'); + angular.mock.inject(($rootScope, authService, $window, $httpBackend) => { + this.$window = $window; + this.$rootScope = $rootScope; + this.authService = authService; + this.$httpBackend = $httpBackend; + }); + }); + + describe('authService.getToken', () => { + it('should return a token', () => { + this.authService.token = null; + this.$window.localStorage.setItem('token', 'test toker-e-no'); + this.authService.getToken() + .then( token => { + expect(token).toEqual('test toker-e-no'); + }) + .catch( err => { + expect(err).toEqual(null); + }); + //this should be at the bottom of *most* test files + this.$rootScope.$apply(); + }); + }); +}); diff --git a/lab-regan/test/edit-gallery-component-test.js b/lab-regan/test/edit-gallery-component-test.js new file mode 100644 index 00000000..6bc0f02d --- /dev/null +++ b/lab-regan/test/edit-gallery-component-test.js @@ -0,0 +1,64 @@ +'use strict'; + +describe('Edit Gallery Component', function(){ + beforeEach( () => { + angular.mock.module('cfgram'); + angular.mock.inject(($rootScope, $componentController, $httpBackend, authService) => { + this.$rootScope = $rootScope; + this.$componentController = $componentController; + this.$httpBackend = $httpBackend; + this.authService = authService; + }); + }); + + it('should contain proper component bindings', () => { + let mockBindings = { + gallery: { + name: "test gallery name", + desc: "test gallery description" + } + }; + + let editGalleryCtrl = this.$componentController('editGallery', null, mockBindings); + expect(editGalleryCtrl.gallery.name).toEqual(mockBindings.gallery.name); + expect(editGalleryCtrl.gallery.desc).toEqual(mockBindings.gallery.desc); + this.$rootScope.$apply(); + }); + + describe('editGalleryCtrl.updateGallery', () => { + it('should make a valid PUT request', () => { + let url = "http://localhost:8000/api/gallery/9999"; + let headers = { + "Accept": "application/json", + "Authorization": "Bearer test toker-e-no", + "Content-Type": "application/json" + }; + + this.$httpBackend.expectPUT(url, { + _id: '9999', + name: 'updated name', + desc: 'updated description' + }, headers).respond(200); + + let mockBindings = { + gallery: { + _id: '9999', + name: 'yarr name', + desc: 'yarr desc' + } + }; + + let editGalleryCtrl = this.$componentController('editGallery', null, mockBindings); + this.$componentController('editGallery', null, mockBindings); + editGalleryCtrl.gallery.name = 'updated name'; + editGalleryCtrl.gallery.desc = 'updated description'; + editGalleryCtrl.updateGallery(); + expect(editGalleryCtrl.gallery.name).toEqual('updated name'); + expect(editGalleryCtrl.gallery.desc).toEqual('updated description'); + + + this.$httpBackend.flush(); + this.$rootScope.$apply(); + }); + }); +}); diff --git a/lab-regan/test/example-test.js b/lab-regan/test/example-test.js new file mode 100644 index 00000000..f3bc6b1a --- /dev/null +++ b/lab-regan/test/example-test.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('Example Test', function(){ + it('should pass this test', ()=>{ + expect(true).toEqual(true); + }); +}); diff --git a/lab-regan/test/gallery-item-component-test.js b/lab-regan/test/gallery-item-component-test.js new file mode 100644 index 00000000..55527d17 --- /dev/null +++ b/lab-regan/test/gallery-item-component-test.js @@ -0,0 +1,67 @@ + + + +//workin + + + +'use strict'; + +describe('Gallery Item Component', function(){ + beforeEach( () => { + angular.mock.module('cfgram'); + angular.mock.inject(($rootScope, $componentController, $httpBackend, authService) => { + this.$rootScope = $rootScope; + this.$componentController = $componentController; + this.$httpBackend = $httpBackend; + this.authService = authService; + }); + }); + + it('should contain proper component bindings', () => { + let mockBindings = { + gallery: { + _id: '9999', + name: "test gallery name", + desc: "test gallery description" + } + }; + + let galleryItemCtrl = this.$componentController('galleryItem', null, mockBindings); + expect(galleryItemCtrl.gallery.name).toEqual(mockBindings.gallery.name); + expect(galleryItemCtrl.gallery.desc).toEqual(mockBindings.gallery.desc); + this.$rootScope.$apply(); + }); + + describe('galleryItemCtrl.deleteGallery', () => { + it('should make a valid DELETE request', () => { + let url = "http://localhost:8000/api/gallery/9999"; + let headers = { + "Authorization": "Bearer test toker-e-no", + "Accept": "application/json, text/plain, */*" + }; + + this.$httpBackend.expectDELETE(url, headers).respond(204); + + let mockBindings = { + gallery: { + _id: '9999', + name: 'yarr name', + desc: 'yarr desc' + } + }; + + let galleryItemCtrl = this.$componentController('galleryItem', null, mockBindings); + this.$componentController('galleryItem', null, mockBindings); + galleryItemCtrl.gallery.name = 'updated name'; + galleryItemCtrl.gallery.desc = 'updated description'; + galleryItemCtrl.deleteGallery(); + expect(galleryItemCtrl.gallery.name).toEqual('updated name'); + expect(galleryItemCtrl.gallery.desc).toEqual('updated description'); + + + this.$httpBackend.flush(); + this.$rootScope.$apply(); + }); + }); +}); diff --git a/lab-regan/test/gallery-service-test.js b/lab-regan/test/gallery-service-test.js new file mode 100644 index 00000000..20a87976 --- /dev/null +++ b/lab-regan/test/gallery-service-test.js @@ -0,0 +1,58 @@ +'use strict'; + +describe('Gallery Service', function(){ + beforeEach(() => { + angular.mock.module('cfgram'); + angular.mock.inject(($rootScope, authService, galleryService, $window, $httpBackend) => { + this.$window = $window; + this.$rootScope = $rootScope; + this.authService = authService; + this.galleryService = galleryService; + this.$httpBackend = $httpBackend; + }); + }); + describe('galleryService.createGallery', () => { + it('should create a new gallery', () => { + let galleryData = { + name: 'example gallery', + desc: 'example description' + }; + let headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': 'Bearer test toker-e-no' + }; + this.$httpBackend.expectPOST('http://localhost:8000/api/gallery', galleryData, headers) + .respond(200, { + _id: '1234', + username: 'test user', + name: galleryData.name, + desc: galleryData.desc, + pics: [] + }); + this.galleryService.createGallery(galleryData); + this.$httpBackend.flush(); + this.$rootScope.$apply(); + }); + }); + + describe('galleryService.deleteGallery', () => { + it('should delete agallery', () => { + let galleryData = { + _id: '1234', + name: 'example gallery', + desc: 'example description' + }; + let headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': 'Bearer test toker-e-no' + }; + + this.$httpBackend.expectDELETE(`http://localhost:8000/api/gallery/${galleryData._id}`, headers) + .respond(204); + this.galleryService.deleteGallery(galleryData); + }); + }); + +}); diff --git a/lab-regan/webpack.config.js b/lab-regan/webpack.config.js new file mode 100644 index 00000000..129cad88 --- /dev/null +++ b/lab-regan/webpack.config.js @@ -0,0 +1,50 @@ +'use strict'; + +const dotenv = require('dotenv'); +const webpack = require('webpack'); +const HTMLPlugin = require('html-webpack-plugin'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); + +const production = process.env.NODE_ENV === 'production'; + +dotenv.load(); + +module.exports = { + devtool: 'eval', + entry: `${__dirname}/app/entry.js`, + output: { + filename: 'bundle.js', + path: `${__dirname}/build` + }, + plugins: [ + new HTMLPlugin({ + template: `${__dirname}/app/index.html` + }), + new ExtractTextPlugin('bundle.css'), + new webpack.DefinePlugin({ + __API_URL__: JSON.stringify(process.env.API_URL), + __DEBUG__: JSON.stringify(!production) + }) + ], + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader' + }, + { + test: /\.html$/, + loader: 'html-loader' + }, + { + test: /\.scss$/, + loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']) + }, + { + test: /\.png$/, + loader: 'url-loader' + } + ] + } +};