Skip to content

Commit

Permalink
Merge pull request #1543 from eciis/webchat-chat
Browse files Browse the repository at this point in the history
Merge webchat-dev
  • Loading branch information
Luiz-FS authored Mar 18, 2019
2 parents 7640118 + 375f441 commit 0980270
Show file tree
Hide file tree
Showing 117 changed files with 18,491 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ frontend/config.js
support/config.js
landing/config.js
feature-toggles/config.js
webchat/config.js

frontend/firebase-config.js
support/firebase-config.js
webchat/firebase-config.js
backend/firebase_config.py
feature-toggles/firebase-config.js

Expand All @@ -550,3 +552,7 @@ backend/Pipfile
frontend/test/package-lock.json
frontend/test/yarn.lock
feature-toggles/test/yarn.lock

# Webchat tests
webchat/test/package-lock.json
frontend/test/yarn.lock
1 change: 1 addition & 0 deletions backend/handlers/erro_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ def get(self):
"msg": "Not found",
"status": 404
}))
self.response.set_status(404)
8 changes: 5 additions & 3 deletions ecis
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ BACKEND_YAML=backend/backend.yaml
WORKER_YAML=backend/worker.yaml
SUPPORT_YAML=support/support.yaml
FEATURE_YAML=feature-toggles/feature.yaml
WEBCHAT_YAML=webchat/webchat.yaml

config_files=(
"frontend/config.js"
"support/config.js"
"landing/config.js"
"feature-toggles/config.js"
"webchat/config.js"
);

SW_FILE="frontend/sw.js"
Expand Down Expand Up @@ -156,7 +158,7 @@ case "$1" in
fi

$(gcloud beta emulators datastore env-init)
dev_appserver.py $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WORKER_YAML -A development-cis --support_datastore_emulator=$emulator $other_parameter
dev_appserver.py $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WEBCHAT_YAML $WORKER_YAML -A development-cis --support_datastore_emulator=$emulator $other_parameter
$(gcloud beta emulators datastore env-unset)
;;

Expand Down Expand Up @@ -309,11 +311,11 @@ case "$1" in
if [ ! -z $3 ]; then # Especified one or more yaml configuration files
gcloud app deploy --version $version --no-promote $3
else
gcloud app deploy --version $version --no-promote $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WORKER_YAML queue.yaml
gcloud app deploy --version $version --no-promote $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WEBCHAT_YAML $WORKER_YAML queue.yaml
fi
else
generate_config_file $ENV $APP_VERSION ${config_files[@]}
gcloud app deploy $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WORKER_YAML
gcloud app deploy $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WEBCHAT_YAML $WORKER_YAML
fi

exit 0
Expand Down
5 changes: 3 additions & 2 deletions frontend/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var Config = {
LANDINGPAGE_URL: 'http://localhost:8080',
SUPPORT_URL: 'http://localhost:8083',
FRONTEND_URL: 'http://localhost:8081',
APP_VERSION: 'master'
};
WEBCHAT_URL: 'http://localhost:8084',
APP_VERSION: 'webchat'
}
6 changes: 5 additions & 1 deletion generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config_local_list=(
"http://localhost:8083" #SUPPORT
"http://localhost:8081" #FRONTEND
"http://localhost:8084" #FEATURE
"http://localhost:8085" #WEBCHAT
);

APP_DOMAIN="development-cis.appspot.com";
Expand All @@ -16,6 +17,7 @@ config_development_list=(
"https://support-dot-$APP_DOMAIN" #SUPPORT
"https://frontend-dot-$APP_DOMAIN" #FRONTEND
"https://feature-dot-$APP_DOMAIN" #FEATURE
"https://webchat-dot-$APP_DOMAIN" #WEBCHAT
);

APP_DOMAIN="plataformacis.org";
Expand All @@ -25,6 +27,7 @@ config_production_list=(
"https://support.$APP_DOMAIN" #SUPPORT
"https://frontend.$APP_DOMAIN" #FRONTEND
"https://feature.$APP_DOMAIN" #FEATURE
"https://webchat.$APP_DOMAIN" #WEBCHAT
);


Expand All @@ -42,7 +45,8 @@ var Config = {
SUPPORT_URL: '$3',
FRONTEND_URL: '$4',
FEATURE_URL: '$5',
APP_VERSION: '$6'
WEBCHAT_URL: '$6',
APP_VERSION: '$7'
};"

echo "$config"
Expand Down
5 changes: 3 additions & 2 deletions landing/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var Config = {
LANDINGPAGE_URL: 'http://localhost:8080',
SUPPORT_URL: 'http://localhost:8083',
FRONTEND_URL: 'http://localhost:8081',
APP_VERSION: 'master'
};
WEBCHAT_URL: 'http://localhost:8084',
APP_VERSION: 'webchat'
}
5 changes: 3 additions & 2 deletions support/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var Config = {
LANDINGPAGE_URL: 'http://localhost:8080',
SUPPORT_URL: 'http://localhost:8083',
FRONTEND_URL: 'http://localhost:8081',
APP_VERSION: 'master'
};
WEBCHAT_URL: 'http://localhost:8084',
APP_VERSION: 'webchat'
}
165 changes: 165 additions & 0 deletions webchat/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
(function() {
'use strict';

const app = angular.module('webchat', [
'ui.router',
'ngMaterial',
'ngMessages',
'firebase',
]);

const rootName = 'main';
app.constant('STATES', {
abstract: rootName,
home: `${rootName}.home`,
login: 'login',
error: 'error',
});

app.constant('WEBSOCKET', {
url: "ws://webchat-server-dot-development-cis.appspot.com/",
maxRetries: 5,
});

app.config((STATES, $mdIconProvider, $mdThemingProvider, $stateProvider, $urlRouterProvider,
$httpProvider, $locationProvider) => {
$mdIconProvider.fontSet('md', 'material-icons');
$mdThemingProvider.theme('docs-dark');
$mdThemingProvider.theme('input')
.primaryPalette('green');
$mdThemingProvider.theme('dialogTheme')
.primaryPalette('teal');

$stateProvider
.state(STATES.abstract, {
abstract: true,
views: {
main: {
templateUrl: "app/main/main.html",
controller: "mainController",
controllerAs: "mainCtrl",
},
},
})
.state(STATES.home, {
url: "/",
views: {
content: {
templateUrl: "app/home/home.html",
controller: "HomeController",
controllerAs: "homeCtrl",
},
},
})
.state(STATES.login, {
url: "/login",
views: {
main: {
templateUrl: "app/auth/login.html",
controller: "LoginController as controller",
},
},
})
.state(STATES.error, {
url: '/error',
views: {
main: {
templateUrl: 'app/error/error.html',
controller: 'ErrorController as errorCtrl',
},
},

params: {
'msg': 'Desculpe! Ocorreu um erro.',
'status': '500'
},
});

$urlRouterProvider.otherwise(($injector, $location) => {
const state = $injector.get('$state');

state.go(STATES.error, {
msg: `Página não encontrada! "${$location.path()}"`,
status: '404'
});

return;
});

$httpProvider.interceptors.push('BearerAuthInterceptor');
$locationProvider.html5Mode(true);
});

app.factory('BearerAuthInterceptor', ['STATES', '$injector', '$q', '$state',
function (STATES, $injector, $q, $state) {
return {
request: function(config) {
const AuthService = $injector.get('AuthService');
config.headers = config.headers || {};
if (AuthService.isLoggedIn()) {
return AuthService.getUserToken().then(token => {
config.headers.Authorization = 'Bearer ' + token;

const API_URL = "/api/";
const FIRST_POSITION = 0;
const requestToApi = config.url.indexOf(API_URL) == FIRST_POSITION;

if (!_.isEmpty(AuthService.getCurrentUser().institutions) && requestToApi) {
config.headers['Institution-Authorization'] = AuthService.getCurrentUser().current_institution.key;
}
Utils.updateBackendUrl(config);
return config || $q.when(config);
});
}

Utils.updateBackendUrl(config);
return config || $q.when(config);
},
response: function(response) {
const app_version = response.headers("app_version");
const AuthService = $injector.get('AuthService');
AuthService.setAppVersion(app_version);
return response || $q.when(response);
},
responseError: function(rejection) {
const AuthService = $injector.get('AuthService');
if (rejection.status === 401) {
if (AuthService.isLoggedIn()) {
AuthService.logout();
rejection.data.msg = "Sua sessão expirou!";
} else {
$state.go(STATES.login);
}
} else if(rejection.status === 403) {
rejection.data.msg = "Você não tem permissão para realizar esta operação!";
} else if(rejection.status === 404) {
$state.go(STATES.error, {
msg: `URL não encontrada! "${Utils.getApiPath(rejection.config.url)}"`,
status: '404'
});
} else {
$state.go(STATES.error, {
msg: rejection.data.msg || "Desculpa! Ocorreu um erro.",
status: rejection.status
});
}
return $q.reject(rejection);
}
};
}]);

app.run(function authInterceptor(STATES, AuthService, $transitions, $state) {
const ignored_routes = [
STATES.login,
STATES.error,
];

$transitions.onStart({
to: function(state) {
return !(_.includes(ignored_routes, state.name)) && !AuthService.isLoggedIn();
}
}, function(transition) {
$state.go(STATES.login);
});
});
})();
Loading

0 comments on commit 0980270

Please sign in to comment.