Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balazs separate functions #20

Merged
merged 5 commits into from Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
401 changes: 15 additions & 386 deletions web/src/app.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions web/src/app/contactdatahandling.js
@@ -0,0 +1,30 @@
'use strict';

const konnektApp = angular.module('konnektApp');

konnektApp.factory('ContactDataHandling', ['HttpService', function (HttpService) {

var contactData = {};

// returns stored contact info
function getContactData() {
return contactData;
}

// read contact info from server
function setContactData(sessionToken) {
return HttpService.getAllContacts(sessionToken)
.then(function (successResponse) {
if (successResponse.status === 200) {
contactData = Object.assign(contactData, successResponse.data.contacts);
} else {
console.log('contact data loading error');
}
});
}

return {
getContactData: getContactData,
setContactData: setContactData,
};
}]);
33 changes: 33 additions & 0 deletions web/src/app/createcontroller.js
@@ -0,0 +1,33 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.controller('createController', ['$scope', '$window', 'UserService', function ($scope, $window, UserService) {

$scope.create_header = 'új kontakt';
$scope.create_welcome = 'Adj hozzá egy hasznos ismerőst!';
$scope.button = 'mehet';

var contactData = {
name: '',
description: ''
};

function saveContact(newContactData) {
contactData = Object.assign(contactData, newContactData);
console.log('saved contact data: ', contactData);
};

$scope.createContact = function () {
let newContactData = {};
newContactData.name = $scope.createName;
newContactData.description = $scope.createDescription;
saveContact(newContactData);
};

console.log(contactData);

}]);
})();
31 changes: 31 additions & 0 deletions web/src/app/dashboardcontroller.js
@@ -0,0 +1,31 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.controller('dashboardController', ['UserService', 'ContactDataHandling', '$window', function (UserService, ContactDataHandling, $window) {

let vm = this;
vm.newContact = 'új kontakt';
vm.logoutUser = 'kilépés';

vm.logoutMember = function () {
UserService.logoutUser();
$window.location.href = '#!/login';
};

// if user reload browser, needs update data from browser's local storage (inspirated by Tibi);
if (typeof UserService.getUserData().id === 'undefined') {
if (UserService.getUserLocalStorage()) {
ContactDataHandling.setContactData();
} else {
UserService.logoutUser();
}
}

vm.loggedInUserId = UserService.getUserData().id;
vm.allContacts = ContactDataHandling.getContactData();

}]);
})();
24 changes: 24 additions & 0 deletions web/src/app/editcontroller.js
@@ -0,0 +1,24 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.controller('editController', ['$scope', 'UserService', 'ContactDataHandling', function ($scope, UserService, ContactDataHandling) {

$scope.header = 'kontakt szerk';
$scope.welcome = 'Változtass az ismerőseiden!';
$scope.button = 'mehet';

ContactDataHandling.setContactData(UserService.getUserData.session_token).then(function () {
$scope.editName = ContactDataHandling.getContactData()[0].name;
$scope.editDescription = ContactDataHandling.getContactData()[0].description;
});

$scope.editContact = function () {
console.log($scope.editName);
console.log($scope.editDescription);
console.log(ContactDataHandling.getContactData()[0].name);
};
}]);
})();
42 changes: 42 additions & 0 deletions web/src/app/httpservice.js
@@ -0,0 +1,42 @@
'use strict';

// *****************************************************************************
// IMPORTANT! Set your server url here!
// *****************************************************************************
//
// for localhost testing
const appUrl = 'http://localhost:3000';
//
// for lasers web
// const appUrl = 'https://lasers-cornubite-konnekt.herokuapp.com';
//
// for raptors web
// const appUrl = 'https://raptor-konnekt.herokuapp.com';
//
// for api docs web
// const appUrl = 'https://konnekt-api-spec.herokuapp.com';
//
// *****************************************************************************

const konnektApp = angular.module('konnektApp');

konnektApp.factory('HttpService', ['$http', function ($http) {

function login(userData) {
return $http.post(`${appUrl}/login`, JSON.stringify(userData), { withCredentials: true });
}

function register(userData) {
return $http.post(`${appUrl}/register`, JSON.stringify(userData));
}

function getAllContacts(sessionToken) {
return $http.get(`${appUrl}/contacts`, { headers: { 'session_token': sessionToken } });
}

return {
login: login,
register: register,
getAllContacts: getAllContacts,
};
}]);
31 changes: 31 additions & 0 deletions web/src/app/logincontroller.js
@@ -0,0 +1,31 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.controller('loginController', ['$scope', 'UserService', function ($scope, UserService) {

$scope.header = 'lépj be';
$scope.welcome = 'üdv a Konnekt Kontaktkezelőben!';
$scope.button = 'mehet';
$scope.errormessage = UserService.getUserData().errormessage;

$scope.loginMember = function () {
let newUserData = {};
newUserData.email = $scope.userLogin.email;
newUserData.password = $scope.userLogin.password;
UserService.setUserData(newUserData);
UserService.login()
.then(function() {
$scope.errormessage = UserService.getUserData().errormessage;
});
};

if (UserService.getUserLocalStorage()) {
console.log('automatic log on');
UserService.login();
}

}]);
})();
27 changes: 27 additions & 0 deletions web/src/app/registrationcontroller.js
@@ -0,0 +1,27 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.controller('registrationController', ['$scope', 'UserService', function ($scope, UserService) {

$scope.header = 'regisztrálj.';
$scope.welcome = 'üdv a Konnekt Kontaktkezelőben!';
$scope.button = 'mehet';

$scope.addNewMember = function () {
if ($scope.newUser.password === $scope.newUser.passwordConfirmation) {
let newUserData = {};
newUserData.email = $scope.newUser.email;
newUserData.password = $scope.newUser.password;
newUserData.passwordConfirmation = $scope.newUser.passwordConfirmation;
UserService.setUserData(newUserData);
UserService.register();
} else {
userData.errormessage = "Kérlek add meg a regisztrációs adataidat!";

}
};
}]);
})();
43 changes: 43 additions & 0 deletions web/src/app/router.js
@@ -0,0 +1,43 @@
'use strict';

(function () {

const konnektApp = angular.module('konnektApp');

konnektApp.config(['$routeProvider', function ($routeProvider) {

$routeProvider
.when('/login', {
templateUrl: 'login.html',
controller: 'loginController',
})
.when('/register', {
templateUrl: 'registration.html',
controller: 'registrationController',
})
.when('/dashboard', {
templateUrl: 'dashboard.html',
controller: 'dashboardController as dashboard',
})
.when('/edit', {
templateUrl: 'edit.html',
controller: 'editController',
})
.otherwise({
redirectTo: '/login',
});
}]);

// APP RUN
konnektApp.run(['$rootScope', '$location', 'UserService', function ($rootScope, $location, UserService) {

$rootScope.$on('$routeChangeStart', function (event, next) {

if (next.templateUrl === 'registration.html') {
$location.path('/register');
} else if (!UserService.isLoggedIn()) {
$location.path('/login');
}
});
}]);
})();