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
const allInputs = document.querySelectorAll( 'a' ); | |
const urlToSearch = 'https://github.com/byverdu'; | |
let found; | |
let position; | |
// Ways to iterate over a NodeList to find an element | |
// 1 | |
allInputs.forEach(( link, index ) => { | |
if (link.href.indexOf( urlToSearch ) !== -1 ) { |
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
// app/client/views/item.pug | |
block content | |
.wrapper(ng-controller="ImdbController as imdb") | |
div(ng-show="!imdb.contentReady") Loading ... | |
div(ng-show="imdb.contentReady") | |
imdb-card(data="imdb.singleItem", call-action="imdb.showForm()" text-btn="Add Rating") | |
form(ng-submit="imdb.updateItem()", ng-show="imdb.revealForm") | |
h3 Add your Rating | |
input(type="text", ng-model="imdb.rating", placeholder="rating ...") |
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
// app/client/js/controllers/imdbController.js | |
module.exports = function( service, $routeParams, broadcaster, $rootScope, $timeout, Notification ) { | |
const $imdb = this; | |
$imdb.title = `${$routeParams.collection}`; | |
$imdb.collection = []; | |
$imdb.contentReady = false; | |
$imdb.singleItem = {}; | |
$imdb.rating = 0; | |
$imdb.revealForm = false; |
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
// API, server side | |
router.get( '/api/all/:imdb', ( req, res ) => { | |
// req.params.imdb === 'movie' || 'series' | |
Imdb.find({ type: req.params.imdb }) | |
.exec() | |
.then(( response ) => { | |
res.type( 'json' ); | |
res.json( response ); | |
}); | |
}); |
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
// app/client/js/controllers/homeController.js | |
module.exports = function ( service, broadcaster, $rootScope, $timeout, Notification ) { | |
const $home = this; | |
$home.title = 'Welcome to ImdbApp'; | |
$home.imdbText = ''; // texto del formulario | |
$home.imdbType = 'movie'; // usar 'movie' como tipo por defecto | |
$home.imdbData = {}; | |
$home.links = [ | |
{ text: 'Movies', url: '/imdb/movie' }, |
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
// app/client/js/services/imdbService.js | |
module.exports = function ( $http ) { | |
return { | |
getImdbData( name, type ) { | |
return $http({ | |
method: 'POST', | |
url: `./api/search?q=${name}&t=${type}` | |
}); | |
}, |
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
// app/client/js/controllers/homeModule.js | |
import angular from 'angular'; | |
import { buildImdbCard } from '../services/directives'; | |
const imdbService = require( '../services/imdbService' ); | |
const imdbBroadcaster = require( '../services/imdbBroadcaster' ); | |
const homeController = require( './homeController' ); | |
require( 'angular-ui-notification/dist/angular-ui-notification' ); |
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
// app/client/views/layout.pug | |
<!DOCTYPE html> | |
html(lang="en", ng-app="imdbApp") | |
head | |
meta(charset="UTF-8") | |
meta(name="viewport", content="width=device-width, initial-scale=1.0") | |
meta(http-equiv="X-UA-Compatible", content="ie=edge") | |
link(rel="stylesheet", type="text/css", href="../static/styles.css") | |
link(rel="stylesheet", type="text/css", href="../static/notification.css") |
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
// app/client/js/services/directive.js | |
export function buildImdbCard() { | |
return { | |
restrict: 'E', | |
replace: true, | |
templateUrl: './views/imdbItem', | |
scope: { | |
data: '<', | |
callAction: '&', |
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
// app/client/js/router.js | |
const angular = require( 'angular' ); | |
require( 'angular-route' ); | |
require( './controllers/homeModule' ); | |
require( './controllers/imdbModule' ); | |
angular.module( 'imdbApp', ['ngRoute', 'homeModule', 'imdbModule']) | |
.config(['$routeProvider', '$locationProvider', ( $routeProvider, $locationProvider ) => { |
NewerOlder