diff --git a/.gitignore b/.gitignore index dcc31b0ab..db36ad1b6 100644 --- a/.gitignore +++ b/.gitignore @@ -526,12 +526,14 @@ paket-files/ 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 backend/app_version.py @@ -549,6 +551,7 @@ backend/Pipfile #Frontend tests frontend/test/package-lock.json frontend/test/yarn.lock +feature-toggles/test/yarn.lock # Webchat tests webchat/test/package-lock.json diff --git a/Jenkinsfile b/Jenkinsfile index 519e28352..8f15f70b6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,14 +7,23 @@ pipeline { } stages { + stage('build') { + steps { + sh './setup_env_test clean' + sh './setup_frontend_tests' + } + } stage('Tests') { steps { parallel( "Backend": { - sh './ecis test server --clean' + sh './ecis test server' }, "Frontend": { - sh './ecis test client --clean' + sh './ecis test client' + }, + "Feature": { + sh './ecis test feature' } ) } diff --git a/backend/admin.py b/backend/admin.py index d96e5a8d1..8deeeb0cc 100644 --- a/backend/admin.py +++ b/backend/admin.py @@ -17,12 +17,14 @@ from models import Comment from models import Invite from models import Event +from models import Feature from utils import NotAuthorizedException from google.appengine.ext import ndb from google.appengine.api import search INDEX_INSTITUTION = 'institution' INDEX_USER = 'user' +INDEX_EVENT = 'event' TEXT = 'At vero eos et accusamus et iusto odio dignissimos \ ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti \ quos dolores et quas molestias excepturi sint occaecati cupiditate \ @@ -37,6 +39,22 @@ delectus, ut aut reiciendis voluptatibus maiores alias consequatur \ aut perferendis doloribus asperiores repellat.' +features = [ + { + "name": 'manage-inst-edit', + "enable_mobile": "DISABLED", + "enable_desktop": "ALL", + "translation_dict": { + "pt-br": "Editar informações da instituição" + } + } +] + +def create_features(): + for feature in features: + if not Feature.get_by_id(feature['name']): + Feature.create(**feature) + def add_comments_to_post(user, user_reply, post, institution, comments_qnt=3): """Add comments to post.""" @@ -165,7 +183,8 @@ def clear_data_store(): delete_all_in_index(index_institution) index_user = search.Index(name=INDEX_USER) delete_all_in_index(index_user) - + index_event = search.Index(name=INDEX_EVENT) + delete_all_in_index(index_event) class BaseHandler(webapp2.RequestHandler): """Base Handler.""" @@ -313,7 +332,7 @@ def get(self): 'address': address_key, 'actuation_area': 'GOVERNMENT_AGENCIES', 'description': 'Ministério da Saúde', - 'photo_url': 'https://i1.wp.com/notta.news/wp-content/uploads/2017/08/tbg_20170713080909_62787.jpg?w=1024', + 'photo_url': 'https://firebasestorage.googleapis.com/v0/b/development-cis.appspot.com/o/images%2Fministerio_da_saude_logo-1551970633722?alt=media&token=a658e366-a3b6-4699-aa98-95dc79eff3b5', 'email': 'deciis@saude.gov.br', 'phone_number': '61 3315-2425', 'state': 'active', @@ -520,11 +539,55 @@ def get(self): splab.posts = [] splab.put() + create_features() + jsonList.append({"msg": "database initialized with a few posts"}) self.response.write(json.dumps(jsonList)) + +class CreateFeaturesHandler(BaseHandler): + def get(self): + create_features() + self.response.write({"msg": "database initialized with a few features"}) + + +class UpdateHandler(BaseHandler): + """Temporary handler. + + It handles with the entities update for some attributes. + """ + + def get(self): + """Retrieve all users and institutions to + create their new attributes avoiding an error in production. + """ + from datetime import datetime + + users = User.query().fetch() + + for user in users: + user.last_seen_institutions = datetime.now() + user.put() + + existing_institutions = Institution.query().fetch() + + for institution in existing_institutions: + institution.creation_date = datetime.now() + institution.put() + + existing_events = Event.query().fetch() + + for event in existing_events: + event.put() + + self.response.write("worked") + + + app = webapp2.WSGIApplication([ ('/admin/reset', ResetHandler), + ('/admin/create-features', CreateFeaturesHandler), + ('/admin/update', UpdateHandler) ], debug=True) diff --git a/backend/custom_exceptions/__init__.py b/backend/custom_exceptions/__init__.py index 6c7f0858d..e3d9e3709 100644 --- a/backend/custom_exceptions/__init__.py +++ b/backend/custom_exceptions/__init__.py @@ -5,7 +5,8 @@ from .notAuthorizedException import * from .queryException import * from .queueException import * +from .notAllowedException import * -exceptions = [entityException, fieldException, notAuthorizedException, queryException, queueException] +exceptions = [entityException, fieldException, notAuthorizedException, queryException, queueException, notAllowedException] __all__ = [prop for exception in exceptions for prop in exception.__all__] diff --git a/backend/custom_exceptions/notAllowedException.py b/backend/custom_exceptions/notAllowedException.py new file mode 100644 index 000000000..87368b4b1 --- /dev/null +++ b/backend/custom_exceptions/notAllowedException.py @@ -0,0 +1,10 @@ +"""Not Allowed Exception.""" + +__all__ = ['NotAllowedException'] + +class NotAllowedException(Exception): + """Not Allowed Exception.""" + + def __init__(self, msg=None): + """Init method.""" + super(NotAllowedException, self).__init__(msg or 'Operation not allowed.') \ No newline at end of file diff --git a/backend/fcm.py b/backend/fcm.py index 3666717f1..5f1ad8da5 100644 --- a/backend/fcm.py +++ b/backend/fcm.py @@ -65,10 +65,15 @@ def send_push_notifications(data, tokens): tokens: The devices' tokens that will receive the notification. """ - validate_object(data, ['title', 'body', 'click_action']) + validate_object(data, [ + 'title', + 'body_message', + 'click_action', + 'type' + ]) title = data['title'] - body = data['body'] + body = {'data': data['body_message'], 'type': data['type']} click_action = data['click_action'] if tokens: diff --git a/backend/handlers/__init__.py b/backend/handlers/__init__.py index a3f6e98a3..4269bdbf1 100644 --- a/backend/handlers/__init__.py +++ b/backend/handlers/__init__.py @@ -42,6 +42,9 @@ from .invite_user_handler import * from .institution_parent_handler import * from .institution_children_handler import * +from .event_followers_handler import * +from .feature_toggle_handler import * +from .current_state_email_request_handler import * handlers = [ base_handler, erro_handler, event_collection_handler, event_handler, @@ -61,6 +64,8 @@ user_request_collection_handler, user_timeline_handler, vote_handler, invite_hierarchy_collection_handler, invite_user_collection_handler, invite_institution_handler, invite_user_handler, institution_parent_handler, - institution_children_handler] + institution_children_handler, event_followers_handler, feature_toggle_handler, + current_state_email_request_handler +] __all__ = [prop for handler in handlers for prop in handler.__all__] diff --git a/backend/handlers/current_state_email_request_handler.py b/backend/handlers/current_state_email_request_handler.py new file mode 100644 index 000000000..ce27e18fb --- /dev/null +++ b/backend/handlers/current_state_email_request_handler.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +"""Current state link request email handler.""" + +import json + +from util import login_required +from utils import json_response +from . import BaseHandler +from send_email_hierarchy import RequestStateEmailSender + +__all__ = ['CurrentStateEmailRequestHandler'] + + +class CurrentStateEmailRequestHandler(BaseHandler): + """Current state email request handler.""" + + @login_required + @json_response + def post(self, user): + body = json.loads(self.request.body) + + subject = "Link para preenchimento de formulario" + + email_sender = RequestStateEmailSender(**{ + 'receiver': user.email, + 'subject': subject, + 'body': body + }) + email_sender.send_email() diff --git a/backend/handlers/event_collection_handler.py b/backend/handlers/event_collection_handler.py index 125ee8da4..491483b3b 100644 --- a/backend/handlers/event_collection_handler.py +++ b/backend/handlers/event_collection_handler.py @@ -56,8 +56,8 @@ def get_filtered_events(filters, user): december = month == 12 begin_selected_month_utc = datetime(year, month, 1, 3) end_selected_month_utc = datetime(year if not december else year+1, month+1 if not december else 1, 1, 3) - query = ndb.gql("SELECT __key__ FROM Event WHERE institution_key IN :1 AND state =:2 AND start_time < DATETIME(:3)", - user.follows, 'published', end_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S")) + query = ndb.gql("SELECT __key__ FROM Event WHERE institution_key IN :1 AND start_time < DATETIME(:2)", + user.follows, end_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S")) if query.count() > 0: return ndb.gql("SELECT * FROM Event WHERE __key__ IN :1 AND end_time >= DATETIME(:2)", query.fetch(), begin_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S")).order(Event.end_time, Event.key) diff --git a/backend/handlers/event_followers_handler.py b/backend/handlers/event_followers_handler.py new file mode 100644 index 000000000..cc38f28cc --- /dev/null +++ b/backend/handlers/event_followers_handler.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +"""Event Followers Handler.""" +import json +from google.appengine.ext import ndb + +from models import Event +from utils import Utils +from util import login_required +from utils import NotAuthorizedException +from utils import json_response +from . import BaseHandler + +__all__ = ['EventFollowersHandler'] + +class EventFollowersHandler(BaseHandler): + """Event Followers Handler.""" + + @json_response + @login_required + def post(self, user, event_urlsafe): + """.""" + event = ndb.Key(urlsafe=event_urlsafe).get() + + Utils._assert(event.state != 'published', + 'The event is not published', + NotAuthorizedException) + + event.add_follower(user) + + @json_response + @login_required + def delete(self, user, event_urlsafe): + """.""" + event = ndb.Key(urlsafe=event_urlsafe).get() + + Utils._assert(event.state != 'published', + 'The event is not published', + NotAuthorizedException) + + event.remove_follower(user) \ No newline at end of file diff --git a/backend/handlers/event_handler.py b/backend/handlers/event_handler.py index 8ea7f5ab4..99202e237 100644 --- a/backend/handlers/event_handler.py +++ b/backend/handlers/event_handler.py @@ -10,6 +10,7 @@ from utils import json_response from util import JsonPatch from . import BaseHandler +from service_entities import enqueue_task __all__ = ['EventHandler'] @@ -56,6 +57,25 @@ def delete(self, user, event_urlsafe): event.last_modified_by_name = user.name event.put() + params = { + 'receiver_key': event.author_key.urlsafe(), + 'sender_key': user.key.urlsafe(), + 'entity_key': event.key.urlsafe(), + 'entity_type': 'DELETED_EVENT', + 'current_institution': user.current_institution.urlsafe(), + 'sender_institution_key': event.institution_key.urlsafe(), + 'field': 'followers', + 'title': event.title + } + + enqueue_task('multiple-notification', params) + + enqueue_task('send-push-notification', { + 'type': 'DELETED_EVENT', + 'receivers': [follower.urlsafe() for follower in event.followers], + 'entity': event.key.urlsafe() + }) + @json_response @login_required def patch(self, user, event_urlsafe): @@ -85,3 +105,22 @@ def patch(self, user, event_urlsafe): """Update event.""" event.put() + + params = { + 'receiver_key': event.author_key.urlsafe(), + 'sender_key': user.key.urlsafe(), + 'entity_key': event.key.urlsafe(), + 'entity_type': 'UPDATED_EVENT', + 'current_institution': user.current_institution.urlsafe(), + 'sender_institution_key': event.institution_key.urlsafe(), + 'field': 'followers', + 'title': event.title + } + + enqueue_task('multiple-notification', params) + + enqueue_task('send-push-notification', { + 'type': 'UPDATED_EVENT', + 'receivers': [follower.urlsafe() for follower in event.followers], + 'entity': event.key.urlsafe() + }) diff --git a/backend/handlers/feature_toggle_handler.py b/backend/handlers/feature_toggle_handler.py new file mode 100644 index 000000000..2ca87cd10 --- /dev/null +++ b/backend/handlers/feature_toggle_handler.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +"""Feature Toggle handler.""" + +import json +from . import BaseHandler +from utils import json_response, Utils +from util import login_required +from models import Feature, get_deciis +from custom_exceptions import NotAuthorizedException + + +__all__ = ['FeatureToggleHandler'] + +def to_json(feature_list, language="pt-br"): + """ + Method to generate list of feature models in json format object. + + Params: + feature_list -- List of features objects + """ + + features = [feature.make(language) for feature in feature_list] + return json.dumps(features) + +class FeatureToggleHandler(BaseHandler): + """Feature toggle hanler.""" + + @json_response + @login_required + def get(self, user): + """ + Method to get all features or filter by name using query parameter. + """ + + feature_name = self.request.get('name') + language = self.request.get('lang') + + if feature_name: + features = [Feature.get_feature(feature_name)] + else: + features = Feature.get_all_features() + + self.response.write(to_json(features, language)) + + @login_required + @json_response + def put(self, user): + """ + Method for modifying the properties of one or more features. + """ + + """ + The super user is the admin of + 'Departamento do Complexo Industrial e Inovação em Saúde". + """ + super_user = get_deciis().admin + + Utils._assert(not (super_user == user.key), "User not allowed to modify features!", NotAuthorizedException) + + feature_body = json.loads(self.request.body) + feature = Feature.set_visibility(feature_body) + self.response.write(json.dumps(feature.make())) diff --git a/backend/handlers/institution_children_handler.py b/backend/handlers/institution_children_handler.py index 8bac2386c..38df1b5eb 100644 --- a/backend/handlers/institution_children_handler.py +++ b/backend/handlers/institution_children_handler.py @@ -11,7 +11,6 @@ from models import Institution -from service_messages import send_message_notification from service_entities import enqueue_task from util import get_subject diff --git a/backend/handlers/institution_handler.py b/backend/handlers/institution_handler.py index 88500a976..ce7eb52c4 100644 --- a/backend/handlers/institution_handler.py +++ b/backend/handlers/institution_handler.py @@ -242,3 +242,9 @@ def delete(self, user, institution_key): "entity": json.dumps(notification_entity) } enqueue_task('notify-followers', notification_params) + + enqueue_task('send-push-notification', { + 'type': 'DELETED_INSTITUTION', + 'receivers': [follower.urlsafe() for follower in institution.followers], + 'entity': institution.key.urlsafe() + }) diff --git a/backend/handlers/institution_members_handler.py b/backend/handlers/institution_members_handler.py index 75c3cef72..de4bec40e 100644 --- a/backend/handlers/institution_members_handler.py +++ b/backend/handlers/institution_members_handler.py @@ -10,6 +10,7 @@ from util import get_subject from service_messages import send_message_notification from send_email_hierarchy import RemoveMemberEmailSender +from service_entities import enqueue_task from . import BaseHandler @@ -69,4 +70,11 @@ def delete(self, user, url_string): 'institution_key': institution.key.urlsafe(), 'html': 'remove_member_email.html' if member.state != 'inactive' else 'inactive_user_email.html' }) - email_sender.send_email() \ No newline at end of file + email_sender.send_email() + + + enqueue_task('send-push-notification', { + 'type': 'DELETE_MEMBER', + 'receivers': [member.key.urlsafe()], + 'entity': institution.key.urlsafe() + }) \ No newline at end of file diff --git a/backend/handlers/institution_parent_handler.py b/backend/handlers/institution_parent_handler.py index 2e2aab129..2454ca341 100644 --- a/backend/handlers/institution_parent_handler.py +++ b/backend/handlers/institution_parent_handler.py @@ -101,3 +101,9 @@ def delete(self, user, institution_parent_urlsafe, institution_children_urlsafe) entity_key=institution_children.key.urlsafe(), message=notification_message ) + + enqueue_task('send-push-notification', { + 'type': notification_type, + 'receivers': [admin.urlsafe()], + 'entity': institution_children.key.urlsafe() + }) diff --git a/backend/handlers/like_handler.py b/backend/handlers/like_handler.py index ddafd8738..b190d2d6f 100644 --- a/backend/handlers/like_handler.py +++ b/backend/handlers/like_handler.py @@ -80,10 +80,11 @@ def post(self, user, post_key, comment_id=None, reply_id=None): 'entity_key': post.key.urlsafe(), 'entity_type': entity_type, 'current_institution': user.current_institution.urlsafe(), - 'sender_institution_key': post.institution.urlsafe() + 'sender_institution_key': post.institution.urlsafe(), + 'field': 'subscribers' } - enqueue_task('post-notification', params) + enqueue_task('multiple-notification', params) is_first_like = post.get_number_of_likes() == 1 if is_first_like: diff --git a/backend/handlers/post_collection_handler.py b/backend/handlers/post_collection_handler.py index 19db58ac7..b67d23b57 100644 --- a/backend/handlers/post_collection_handler.py +++ b/backend/handlers/post_collection_handler.py @@ -75,9 +75,15 @@ def create_post(post_data, user, institution): 'institution_key': post.institution.urlsafe(), 'current_institution': user.current_institution.urlsafe() } - + enqueue_task('notify-followers', params) + enqueue_task('send-push-notification', { + 'type': 'CREATE_POST', + 'receivers': [follower.urlsafe() for follower in institution.followers], + 'entity': post.key.urlsafe() + }) + if(post.shared_post): shared_post = post.shared_post.get() entity_type = 'SHARED_POST' @@ -90,7 +96,7 @@ def create_post(post_data, user, institution): 'sender_institution_key': shared_post.institution.urlsafe() } - enqueue_task('post-notification', params) + enqueue_task('multiple-notification', params) elif post.shared_event: shared_event = post.shared_event.get() if shared_event.author_key != user.key: diff --git a/backend/handlers/post_comment_handler.py b/backend/handlers/post_comment_handler.py index d310b1945..060a7a9ad 100644 --- a/backend/handlers/post_comment_handler.py +++ b/backend/handlers/post_comment_handler.py @@ -63,17 +63,15 @@ def post(self, user, post_key): 'entity_key': post.key.urlsafe(), 'entity_type': entity_type, 'current_institution': user.current_institution.urlsafe(), - 'sender_institution_key': post.institution.urlsafe() + 'sender_institution_key': post.institution.urlsafe(), + 'field': 'subscribers' } - enqueue_task('post-notification', params) - - is_first_comment = post.get_number_of_comment() == 1 - if is_first_comment: - enqueue_task('send-push-notification', { - 'type': entity_type, - 'receivers': [subscriber.urlsafe() for subscriber in post.subscribers], - 'entity': post.key.urlsafe() - }) + enqueue_task('multiple-notification', params) + enqueue_task('send-push-notification', { + 'type': entity_type, + 'receivers': [subscriber.urlsafe() for subscriber in post.subscribers], + 'entity': post.key.urlsafe() + }) self.response.write(json.dumps(Utils.toJson(comment))) diff --git a/backend/handlers/post_handler.py b/backend/handlers/post_handler.py index 5aac6884b..bf59e19a5 100644 --- a/backend/handlers/post_handler.py +++ b/backend/handlers/post_handler.py @@ -12,6 +12,7 @@ from models import SurveyPost from models import Like from service_messages import send_message_notification +from service_entities import enqueue_task from . import BaseHandler @@ -70,6 +71,12 @@ def delete(self, user, post_urlsafe): entity=json.dumps(post.make(self.request.host)) ) + enqueue_task('send-push-notification', { + 'type': 'DELETE_POST', + 'entity': post.key.urlsafe(), + 'receivers': [post.author.urlsafe()] + }) + @json_response @login_required def patch(self, user, post_urlsafe): diff --git a/backend/handlers/reply_comment_handler.py b/backend/handlers/reply_comment_handler.py index 7801fdd26..d2ff345b7 100644 --- a/backend/handlers/reply_comment_handler.py +++ b/backend/handlers/reply_comment_handler.py @@ -11,6 +11,7 @@ from service_messages import send_message_notification from custom_exceptions import NotAuthorizedException from custom_exceptions import EntityException +from service_entities import enqueue_task from . import BaseHandler from models import Comment @@ -82,6 +83,12 @@ def post(self, user, post_key, comment_id): message=notification_message ) + enqueue_task('send-push-notification', { + 'type': notification_type, + 'entity': post.key.urlsafe(), + 'receivers': [comment.get('author_key')] + }) + self.response.write(json.dumps(Utils.toJson(reply))) @json_response diff --git a/backend/handlers/search_handler.py b/backend/handlers/search_handler.py index a0c26d9be..52183a152 100644 --- a/backend/handlers/search_handler.py +++ b/backend/handlers/search_handler.py @@ -6,14 +6,14 @@ import json from . import BaseHandler -from search_module import SearchUser -from search_module import SearchInstitution +from search_module import SearchUser, SearchInstitution, SearchEvent __all__ = ['SearchHandler'] SEARCH_TYPES = { 'institution': SearchInstitution, - 'user': SearchUser + 'user': SearchUser, + 'event': SearchEvent } diff --git a/backend/handlers/user_handler.py b/backend/handlers/user_handler.py index 67f950666..59bbcbc6b 100644 --- a/backend/handlers/user_handler.py +++ b/backend/handlers/user_handler.py @@ -11,6 +11,7 @@ from models import InstitutionProfile from service_messages import send_message_notification from util import JsonPatch +from service_entities import enqueue_task from . import BaseHandler @@ -61,6 +62,12 @@ def notify_admins(user): message=notification_message ) + enqueue_task('send-push-notification', { + 'receivers': [admin_key.urlsafe()], + 'type': 'DELETED_USER', + 'entity': user.key.urlsafe() + }) + class UserHandler(BaseHandler): """User Handler.""" diff --git a/backend/handlers/user_institutions_handler.py b/backend/handlers/user_institutions_handler.py index 6c3991f3a..0d6b86b86 100644 --- a/backend/handlers/user_institutions_handler.py +++ b/backend/handlers/user_institutions_handler.py @@ -10,6 +10,7 @@ from send_email_hierarchy import LeaveInstitutionEmailSender from service_messages import send_message_notification from util import get_subject +from service_entities import enqueue_task from . import BaseHandler @@ -58,4 +59,10 @@ def delete(self, user, institution_key): notification_type='LEFT_INSTITUTION', entity_key=institution.key.urlsafe(), message=notification_message - ) \ No newline at end of file + ) + + enqueue_task('send-push-notification', { + 'type': 'LEFT_INSTITUTION', + 'receivers': [admin.key.urlsafe()], + 'entity': user.key.urlsafe() + }) \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 4bbdb7f86..ba57de38c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -45,6 +45,9 @@ from handlers import InviteHandler from handlers import InstitutionParentHandler from handlers import InstitutionChildrenHandler +from handlers import EventFollowersHandler +from handlers import FeatureToggleHandler +from handlers import CurrentStateEmailRequestHandler methods = set(webapp2.WSGIApplication.allowed_methods) methods.add('PATCH') @@ -63,6 +66,7 @@ ("/api/requests/(.*)/institution", InstitutionRequestHandler), ("/api/requests/(.*)/institution_parent", InstitutionParentRequestHandler), ("/api/requests/(.*)/institution_children", InstitutionChildrenRequestHandler), + ("/api/events/(.*)/followers", EventFollowersHandler), ("/api/events/(.*)", EventHandler), ("/api/events.*", EventCollectionHandler), ("/api/institutions", InstitutionCollectionHandler), @@ -96,6 +100,9 @@ ("/api/user/institutions/(.*)", UserHandler), ("/api/user/timeline.*", UserTimelineHandler), ("/api/search/institution", SearchHandler), + ("/api/search/event", SearchHandler), + ("/api/feature-toggle.*", FeatureToggleHandler), + ("/api/email/current-state", CurrentStateEmailRequestHandler), ("/login", LoginHandler), ("/logout", LogoutHandler), ("/api/.*", ErroHandler) diff --git a/backend/models/__init__.py b/backend/models/__init__.py index aed79fcab..7cbe1f8b0 100644 --- a/backend/models/__init__.py +++ b/backend/models/__init__.py @@ -18,6 +18,7 @@ from .post import * from .survey_post import * from .factory_post import * +from .feature import * models = [ @@ -25,7 +26,7 @@ invite_institution_children, invite_institution_parent, invite_user, request, request_user, request_institution_parent, request_institution_children, invite_user_adm, request_institution, factory_invites, post, - survey_post, factory_post + survey_post, factory_post, feature ] __all__ = [prop for model in models for prop in model.__all__] diff --git a/backend/models/event.py b/backend/models/event.py index 5c7679ad2..496f729d3 100644 --- a/backend/models/event.py +++ b/backend/models/event.py @@ -4,6 +4,9 @@ from google.appengine.ext import ndb from custom_exceptions import FieldException from models import Address +from search_module import SearchEvent +from custom_exceptions import NotAllowedException +from service_messages import create_message __all__ = ['Event'] @@ -78,6 +81,8 @@ class Event(ndb.Model): # Local of the event local = ndb.StringProperty(required=True) + followers = ndb.KeyProperty(kind="User", repeated=True) + def isValid(self, is_patch=False): """Check if is valid event.""" date_now = datetime.today() @@ -127,6 +132,7 @@ def create(data, author, institution): event.end_time = datetime.strptime( data.get('end_time'), "%Y-%m-%dT%H:%M:%S") event.address = Address.create(data.get('address')) + event.followers.append(author.key) event.isValid() @@ -161,9 +167,15 @@ def make(event): 'author_key': event.author_key.urlsafe(), 'institution_key': event.institution_key.urlsafe(), 'key': event.key.urlsafe(), - 'institution_acronym': event.institution_acronym + 'institution_acronym': event.institution_acronym, + 'followers': [key.urlsafe() for key in event.followers] } + def _post_put_hook(self, future): + """This method is called after each Event.put().""" + search_event = SearchEvent() + search_event.createDocument(future.get_result().get()) + def __setattr__(self, attr, value): """ Method of set attributes. @@ -177,3 +189,46 @@ def __setattr__(self, attr, value): if is_attr_data and not is_value_datetime: value = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S") super(Event, self).__setattr__(attr, value) + + def add_follower(self, user): + """Add a subscriber.""" + is_active = user.state == 'active' + is_not_a_follower = not user.key in self.followers + + if is_active and is_not_a_follower: + self.followers.append(user.key) + self.put() + else: + raise NotAllowedException("%s" %(not is_active and "The user is not active" + or not is_not_a_follower and "The user is a follower yet")) + + + def remove_follower(self, user): + """Remove a subscriber.""" + is_a_follower = user.key in self.followers + is_not_the_author = self.author_key != user.key + + if is_a_follower and is_not_the_author: + self.followers.remove(user.key) + self.put() + else: + raise NotAllowedException("%s" %(not is_a_follower and 'The user is not a follower' + or not is_not_the_author and "The user is the author")) + + def create_notification_message(self, user_key, current_institution_key, sender_institution_key=None): + """ Create message that will be used in notification. + user_key -- The user key that made the action. + current_institution_key -- The institution that user was in the moment that made the action. + sender_institution_key -- The institution by which the post was created, + if it hasn't been defined yet, the sender institution should be the current institution. + """ + return create_message( + sender_key= user_key, + current_institution_key=current_institution_key, + sender_institution_key=sender_institution_key or current_institution_key + ) + + def __getitem__(self, key): + if key in self.to_dict(): + return self.to_dict()[key] + super(Event, self).__getitem__(attr, value) diff --git a/backend/models/feature.py b/backend/models/feature.py new file mode 100644 index 000000000..118b65d52 --- /dev/null +++ b/backend/models/feature.py @@ -0,0 +1,87 @@ +"""Feature model.""" +import json +from google.appengine.ext import ndb + +__all__ = ['Feature'] + +class Feature(ndb.Model): + """ + Model of Feature. + """ + + name = ndb.StringProperty() + enable_mobile = ndb.StringProperty( + choices=set(["SUPER_USER", "ADMIN", "ALL", "DISABLED"])) + enable_desktop = ndb.StringProperty( + choices=set(["SUPER_USER", "ADMIN", "ALL", "DISABLED"])) + translation = ndb.JsonProperty(default="{}") + + @staticmethod + @ndb.transactional(xg=True) + def create(name, translation_dict, enable_mobile="ALL", enable_desktop="ALL"): + """ + Method to create new feature. + + Params: + name -- Name of the new feature + enable_mobile -- (Optional) User group to which the feature is enabled in the mobile version. If not received will be enabled for everyone. + enable_desktop -- (Optional) User group to which the feature is enabled in the desktop version. If not received will be enabled for everyone. + """ + + feature = Feature(id=name, name=name, enable_desktop=enable_desktop, enable_mobile=enable_mobile) + feature.translation = json.dumps(translation_dict) + feature.put() + return feature + + @staticmethod + def set_visibility(feature_dict): + """ + Method to enable or disable feature. + + Params: + features_dict -- dictionary containing the properties of the feature model to be modified. + """ + + feature = Feature.get_feature(feature_dict.get('name')) + feature.enable_desktop = feature_dict['enable_desktop'] + feature.enable_mobile = feature_dict['enable_mobile'] + feature.put() + return feature + + @staticmethod + def get_all_features(): + """ + Method to get all stored features. + """ + + features = Feature.query().fetch() + return features + + @staticmethod + def get_feature(feature_name): + """ + Method to get feature by name. + + Params: + feature_name -- name of the requested feature + """ + + feature = Feature.get_by_id(feature_name) + + if feature: + return feature + else: + raise Exception("Feature not found!") + + def make(self, language="pt-br"): + """ + Method to make feature. + """ + make_obj = { + 'name': self.name, + 'enable_mobile': self.enable_mobile, + 'enable_desktop': self.enable_desktop, + 'translation': json.loads(self.translation).get(language) + } + + return make_obj diff --git a/backend/models/invite.py b/backend/models/invite.py index 7632fa341..702533433 100644 --- a/backend/models/invite.py +++ b/backend/models/invite.py @@ -6,7 +6,8 @@ from service_messages import create_message from send_email_hierarchy import EmailSender from . import User -from util import get_subject +from util import get_subject +from service_entities import enqueue_task __all__ = ['Invite'] @@ -125,6 +126,12 @@ def send_notification(self, current_institution, sender_key=None, receiver_key=N message=notification_message ) + enqueue_task('send-push-notification', { + 'receivers': [receiver_key.urlsafe()], + 'type': 'INVITE', + 'entity': entity_key + }) + def make(self): """Create personalized json of invite.""" institution_admin = self.institution_key.get() diff --git a/backend/models/post.py b/backend/models/post.py index f082a8378..58b943d26 100644 --- a/backend/models/post.py +++ b/backend/models/post.py @@ -370,7 +370,11 @@ def create_notification_message(self, user_key, current_institution_key, sender_ current_institution_key=current_institution_key, sender_institution_key=sender_institution_key or current_institution_key ) - + + def __getitem__(self, key): + if key in self.to_dict(): + return self.to_dict()[key] + super(Post, self).__getitem__(attr, value) @staticmethod def is_hidden(post): diff --git a/backend/models/user.py b/backend/models/user.py index b357ace59..c01a4d796 100644 --- a/backend/models/user.py +++ b/backend/models/user.py @@ -38,7 +38,9 @@ def make(self): profile['branch_line'] = self.branch_line profile['institution'] = { 'name': institution.name, - 'photo_url': institution.photo_url + 'photo_url': institution.photo_url, + 'acronym': institution.acronym, + 'key': institution.key.urlsafe() } profile['color'] = self.color or 'teal' diff --git a/backend/push_notification/push_notification_service.py b/backend/push_notification/push_notification_service.py index bf035b1f8..65e606813 100644 --- a/backend/push_notification/push_notification_service.py +++ b/backend/push_notification/push_notification_service.py @@ -28,6 +28,17 @@ class NotificationType(Enum): invite_user = 'USER' invite_user_adm = 'USER_ADM' link = 'LINK' + delete_member = 'DELETE_MEMBER' + remove_institution_link = 'REMOVE_INSTITUTION_LINK' + create_post = 'CREATE_POST' + delete_post = 'DELETE_POST' + reply_comment = 'REPLY_COMMENT' + deleted_user = 'DELETED_USER' + left_institution = 'LEFT_INSTITUTION' + invite = 'INVITE' + deleted_institution = 'DELETED_INSTITUTION' + deleted_event = 'DELETED_EVENT' + updated_event = 'UPDATED_EVENT' class NotificationProperties(object): """This class has several private @@ -53,7 +64,18 @@ def __init__(self, _type, entity): NotificationType.comment: self.__get_comment_props, NotificationType.invite_user: self.__get_invite_user_props, NotificationType.invite_user_adm: self.__get_invite_user_adm_props, - NotificationType.link: self.__get_link_props + NotificationType.link: self.__get_link_props, + NotificationType.delete_member: self.__get_delete_member_props, + NotificationType.remove_institution_link: self.__get_remove_inst_link_props, + NotificationType.create_post: self.__get_create_post_props, + NotificationType.delete_post: self.__get_delete_post_props, + NotificationType.reply_comment: self.__get_reply_comment_props, + NotificationType.deleted_user: self.__get_deleted_user_props, + NotificationType.left_institution: self.__get_left_institution_props, + NotificationType.invite: self.__get_invite_props, + NotificationType.deleted_institution: self.__get_deleted_institution_props, + NotificationType.deleted_event: self.__get_deleted_event_props, + NotificationType.updated_event: self.__get_updated_event_props } self.entity = entity self.notification_method = types[_type] @@ -78,8 +100,9 @@ def __get_like_props(self): return { 'title': 'Publicação curtida', - 'body': 'Uma publicação de seu interesse foi curtida', - 'click_action': url + 'body_message': 'Uma publicação de seu interesse foi curtida', + 'click_action': url, + 'type': 'LIKE_POST' } def __get_comment_props(self): @@ -95,8 +118,9 @@ def __get_comment_props(self): return { 'title': 'Publicação comentada', - 'body': 'Uma publicação do seu interesse foi comentada', - 'click_action': url + 'body_message': 'Uma publicação do seu interesse foi comentada', + 'click_action': url, + 'type': 'COMMENT' } def __get_invite_user_props(self): @@ -107,8 +131,9 @@ def __get_invite_user_props(self): return { 'title': 'Novo convite', - 'body': 'Você recebeu um novo convite para ser membro de uma instituição', - 'click_action': url + 'body_message': 'Você recebeu um novo convite para ser membro de uma instituição', + 'click_action': url, + 'type': 'USER' } def __get_invite_user_adm_props(self): @@ -119,8 +144,9 @@ def __get_invite_user_adm_props(self): return { 'title': 'Novo convite', - 'body': 'Você recebeu um novo convite para ser administrador de uma instituição', - 'click_action': url + 'body_message': 'Você recebeu um novo convite para ser administrador de uma instituição', + 'click_action': url, + 'type': 'USER_ADM' } def __get_link_props(self): @@ -131,6 +157,107 @@ def __get_link_props(self): return { 'title': 'Solicitação de vínculo', - 'body': 'Uma instituição que você administra recebeu uma nova solicitação de vínculo', - 'click_action': url + 'body_message': 'Uma instituição que você administra recebeu uma nova solicitação de vínculo', + 'click_action': url, + 'type': 'LINK' + } + + def __get_delete_member_props(self): + url = '/institution/%s/home' %self.entity.key.urlsafe() + + return { + 'title': 'Remoção de vínculo', + 'body_message': 'Você foi removido da instituição %s' %self.entity.name, + 'click_action': url, + 'type': 'DELETE_MEMBER' + } + + def __get_remove_inst_link_props(self): + url = '/institution/%s/inviteInstitution' %self.entity.key.urlsafe() + + return { + 'title': 'Remoção de vínculo', + 'body_message': 'A instituição %s teve um de seus vínculos removidos' %self.entity.name, + 'click_action': url, + 'type': 'REMOVE_INSTITUTION_LINK' + } + + def __get_create_post_props(self): + url = '/posts/%s' %self.entity.key.urlsafe() + + return { + 'title': 'Novo post criado', + 'body_message': '%s criou um novo post' %self.entity.author.urlsafe(), + 'click_action': url, + 'type': 'CREATE_POST' + } + + def __get_delete_post_props(self): + url = '/' + admin_name = self.entity.institution.get().admin.get().name + + return { + 'title': 'Post deletado', + 'body_message': '%s deletou seu post' %admin_name, + 'click_action': url, + 'type': 'DELETE_POST' + } + + def __get_reply_comment_props(self): + url = '/posts/%s' %self.entity.key.urlsafe() + + return { + 'title': 'Novo comentário', + 'body_message': 'Seu comentário tem uma nova resposta', + 'click_action': url, + 'type': 'REPLY_COMMENT' + } + + def __get_deleted_user_props(self): + return { + 'title': 'Usuário inativo', + 'body_message': '%s não está mais ativo na plataforma' %self.entity.name, + 'click_action': '/', + 'type': 'DELETED_USER' + } + + def __get_left_institution_props(self): + return { + 'title': 'Remoção de vínculo de membro', + 'body_message': '%s removeu o vínculo com uma das instituições que você administra' %self.entity.name, + 'click_action': '/', + 'type': 'LEFT_INSTITUTION' + } + + def __get_invite_props(self): + url = '%s/new_invite' %self.entity.key.urlsafe() + return { + 'title': 'Novo convite', + 'body_message': 'Você tem um novo convite', + 'click_action': url, + 'type': 'INVITE' + } + + def __get_deleted_institution_props(self): + return { + 'title': 'Instituição removida', + 'body_message': 'A instituição %s foi removida' %self.entity.name, + 'click_action': '/', + 'type':'DELETED_INSTITUTION' + } + + def __get_deleted_event_props(self): + return { + 'title': 'Evento removido', + 'body_message': 'O evento %s foi removido' %self.entity.title, + 'click_action': '/', + 'type': 'DELETED_EVENT' + } + + def __get_updated_event_props(self): + return { + 'title': 'Evento editado', + 'body_message': 'O evento %s foi editado' %self.entity.title, + 'click_action': '/event/%s/details' %self.entity.key.urlsafe(), + 'type': 'UPDATED_EVENT' } diff --git a/backend/search_module/__init__.py b/backend/search_module/__init__.py index 6febea5ad..4a2719c79 100644 --- a/backend/search_module/__init__.py +++ b/backend/search_module/__init__.py @@ -2,8 +2,8 @@ from .search_document import * from .search_institution import * from .search_user import * +from .search_event import * - -search_modules = [search_document, search_institution, search_user] +search_modules = [search_document, search_institution, search_user, search_event] __all__ = [prop for search_module in search_modules for prop in search_module.__all__] diff --git a/backend/search_module/search_event.py b/backend/search_module/search_event.py new file mode 100644 index 000000000..74a407077 --- /dev/null +++ b/backend/search_module/search_event.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +"""Search Event.""" + +from google.appengine.api import search +from . import SearchDocument +from utils import text_normalize +import json +from datetime import timedelta + +__all__ = ['SearchEvent'] + +def event_has_changes(fields, entity): + """It returns True when there is a change + to make in entity's document. + """ + address = entity.address + + for field in fields: + if hasattr(entity, field.name) and field.value != getattr(entity, field.name): + return True + elif hasattr(address, field.name) and field.value != getattr(address, field.name): + return True + + return False + +def get_date_string(event_date): + """It fix the utc for Brazil and returns only the date.""" + return (event_date - timedelta(hours=3)).isoformat().split("T")[0] + +class SearchEvent(SearchDocument): + """Search event's model.""" + + def __init__(self): + """Init method.""" + self.index_name = 'event' + + def createDocument(self, event): + """Create a document. + + Keyword arguments: + event -- It wrapps the attributes that will be used in document. + All of them are self descriptive and + relationed to the event. + """ + index = search.Index(name=self.index_name) + doc = index.get(event.key.urlsafe()) + if doc is None or doc is type(None): + + content = { + 'id': event.key.urlsafe(), + 'state': event.state, + 'title': event.title, + 'institution_name': event.institution_name, + 'institution_key': event.institution_key.urlsafe(), + 'photo_url': event.photo_url, + 'institution_acronym': event.institution_acronym, + 'start_time': event.start_time.isoformat(), + 'date': get_date_string(event.start_time), + 'address': event.address and json.dumps(dict(event.address)), + 'country': event.address and event.address.country, + 'federal_state': event.address and event.address.federal_state, + 'city': event.address and event.address.city + } + + # Make the structure of the document by setting the fields and its id. + document = search.Document( + # The document's id is the same of the event's one, + # what makes the search easier. + doc_id=content['id'], + fields=[ + search.TextField(name='state', value=content['state']), + search.TextField(name='title', value=content['title']), + search.TextField(name='institution_name', value=content['institution_name']), + search.TextField(name='institution_key', value=content['institution_key']), + search.TextField(name='photo_url', value=content['photo_url']), + search.TextField(name='institution_acronym', value=content['institution_acronym']), + search.TextField(name='start_time', value=content['start_time']), + search.TextField(name='date', value=content['date']), + search.TextField(name='address', value=content['address']), + search.TextField(name='country', value=content['country']), + search.TextField(name='federal_state', value=content['federal_state']), + search.TextField(name='city', value=content['city']) + ] + ) + self.saveDocument(document) + else: + self.updateDocument(event) + + def getDocuments(self, value, state): + """Retrieve the documents and return them processed.""" + query_string = self.makeQueryStr(value, state) + index = search.Index(self.index_name) + query_options = search.QueryOptions( + returned_fields=['state', 'title', 'institution_key', 'photo_url', 'institution_name', + 'institution_acronym', 'start_time', 'address'] + ) + query = search.Query( + query_string=query_string, options=query_options) + documents = index.search(query) + return self.processDocuments(documents) + + def makeQueryStr(self, value, state): + """Make the query string. + + Keyword arguments: + value -- value to be searched + state -- represents the current event's state. + """ + state_string = self.create_state_string(state) + fields_values_string = self.create_field_values_string(value) + + query_string = "(%s) AND %s" % (fields_values_string, state_string) if fields_values_string else state_string + return query_string + + def create_state_string(self, state): + """Create a string formed by state.""" + states = state.split(",") + state_string = "" + for i in xrange(0, len(states), 1): + if(i == 0): + state_string += states[i] + else: + state_string += " OR " + states[i] + + state_string = "state: %s" % state_string + return state_string + + def create_field_values_string(self, value): + """Create a string formed by fields and values. + + If value is empty the method will return an empty string + which means that the query will be only by the state + and the fields won't be considered. + """ + # add a new field here + fields = ['state', 'institution_name', 'date', + 'institution_acronym', 'country', 'federal_state', 'city'] + fields_values = [] + + if value: + for field in fields: + field_value = '%s: "%s"' % (field, value) + fields_values.append(field_value) + + fields_values_string = " OR ".join(fields_values) if fields_values else "" + return text_normalize(fields_values_string) + + def updateDocument(self, entity, has_changes=event_has_changes): + """Update a Document. + + When an entity changes its fields, this function + updates the previous document. + """ + super(SearchEvent, self).updateDocument(entity, has_changes) diff --git a/backend/search_module/search_institution.py b/backend/search_module/search_institution.py index 123591174..4337affc7 100644 --- a/backend/search_module/search_institution.py +++ b/backend/search_module/search_institution.py @@ -4,6 +4,7 @@ from google.appengine.api import search from . import SearchDocument from utils import text_normalize +import json __all__ = ['SearchInstitution'] @@ -42,7 +43,6 @@ def createDocument(self, institution): admin = institution.email if institution.admin: admin = institution.admin.get().email[0] - content = { 'id': institution.key.urlsafe(), 'name': institution.name, @@ -53,7 +53,10 @@ def createDocument(self, institution): 'actuation_area': institution.actuation_area, 'legal_nature': institution.legal_nature, 'federal_state': institution.address and institution.address.federal_state, - 'description': institution.description + 'description': institution.description, + 'creation_date': institution.creation_date.isoformat(), + 'address': institution.address and json.dumps(dict(institution.address)), + 'photo_url': institution.photo_url } # Make the structure of the document by setting the fields and its id. document = search.Document( @@ -71,7 +74,10 @@ def createDocument(self, institution): search.TextField(name='legal_nature', value=content['legal_nature']), search.TextField(name='federal_state', value=content['federal_state']), - search.TextField(name='description', value=content['description']) + search.TextField(name='description', value=content['description']), + search.TextField(name='creation_date', value=content['creation_date']), + search.TextField(name='address', value=content['address']), + search.TextField(name='photo_url', value=content['photo_url']) ] ) self.saveDocument(document) @@ -84,7 +90,8 @@ def getDocuments(self, value, state): index = search.Index(self.index_name) query_options = search.QueryOptions( returned_fields=['name', 'state', 'email', 'admin', 'acronym', - 'actuation_area', 'legal_nature', 'federal_state', 'description'] + 'actuation_area', 'legal_nature', 'federal_state', + 'description', 'creation_date', 'address', 'photo_url'] ) query = search.Query( query_string=query_string, options=query_options) diff --git a/backend/send_email_hierarchy/__init__.py b/backend/send_email_hierarchy/__init__.py index 910a0cd11..3a2a4db30 100644 --- a/backend/send_email_hierarchy/__init__.py +++ b/backend/send_email_hierarchy/__init__.py @@ -10,13 +10,14 @@ from .request_link_email_sender import * from .request_user_email_sender import * from .transfer_admin_email_sender import * - +from .request_state_email_sender import * email_modules = [ email_sender, request_institution_email_sender, invite_institution_email_sender, invite_user_email_sender, leave_institution_email_sender, remove_institution_email_sender, remove_member_email_sender, - request_link_email_sender, request_user_email_sender, transfer_admin_email_sender + request_link_email_sender, request_user_email_sender, transfer_admin_email_sender, + request_state_email_sender ] __all__ = [prop for email_module in email_modules for prop in email_module.__all__] \ No newline at end of file diff --git a/backend/send_email_hierarchy/request_state_email_sender.py b/backend/send_email_hierarchy/request_state_email_sender.py new file mode 100644 index 000000000..e2cd6f858 --- /dev/null +++ b/backend/send_email_hierarchy/request_state_email_sender.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +"""Request state email sender.""" + +from . import EmailSender + +__all__ = ['RequestStateEmailSender'] + + +class RequestStateEmailSender(EmailSender): + """Entity responsible to send state link email.""" + + def __init__(self, **kwargs): + """The class constructor. + + It initializes the object with its html and its specific properties. + """ + super(RequestStateEmailSender, self).__init__(**kwargs) + self.subject = "Link para preenchimento de formulario" + self.html = "request_state_email.html" + + def send_email(self): + """It enqueue a sending email task with the json that will fill the entity's html. + + For that, it call its super with email_json property. + """ + email_json = { + 'state_link': self.__get_state_link() + } + super(RequestStateEmailSender, self).send_email(email_json) + + def __get_state_link(self): + return self.__get_data()['state-link'] + + def __get_data(self): + return self.body['data'] diff --git a/backend/service_messages.py b/backend/service_messages.py index 44221f6ff..ce16038de 100644 --- a/backend/service_messages.py +++ b/backend/service_messages.py @@ -63,7 +63,7 @@ def create_entity(entity_key): entity = { "key": entity_key } - return json.dumps(entity) + return entity def send_message_notification(receiver_key, notification_type, entity_key, message, entity=None): @@ -86,7 +86,7 @@ def send_message_notification(receiver_key, notification_type, entity_key, messa 'receiver_key': receiver_key, 'message': message, 'notification_type': notification_type, - 'entity': entity + 'entity': json.dumps(entity) } ) \ No newline at end of file diff --git a/backend/templates/request_state_email.html b/backend/templates/request_state_email.html new file mode 100644 index 000000000..a580a362b --- /dev/null +++ b/backend/templates/request_state_email.html @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ + + + + +
+
+
+
+
+
+ +
+
+
+ AQUI ESTÁ O LINK QUE VOCÊ SOLICITOU +
+
+
+ + VOCÊ SOLICITOU O LINK DE UM FORMULARIO DA PLATAFORMA PARA PREENCHE-LO DEPOIS E AQUI ESTÁ ELE. CLIQUE NO BOTÃO ABAIXO PARA ACESSA-LO. + +
+ +
+
+
+
+
+
+ + + + + +
+ + +
+ + + + + +
+
+
+
+ + +
+
+ +
+
+ +
+
+ + Copyright © 2017 Plataforma CIS - Ministério da Saúde. + +
+
+ + Todos os direitos reservados. + +
+
+
+
+
+
+
+ + + diff --git a/backend/test/event_handlers_tests/event_followers_handler_test.py b/backend/test/event_handlers_tests/event_followers_handler_test.py new file mode 100644 index 000000000..e9ee6935e --- /dev/null +++ b/backend/test/event_handlers_tests/event_followers_handler_test.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +"""Event Followers handler test.""" + +from ..test_base_handler import TestBaseHandler +from models import User +from models import Institution +from models import Event +from handlers import EventFollowersHandler +from mock import patch + +import json +from .. import mocks + + +class EventFollowersHandlerTest(TestBaseHandler): + """Test Event Followers Handler.""" + + @classmethod + def setUp(cls): + """Provide the base for the tests.""" + super(EventFollowersHandlerTest, cls).setUp() + methods = set(cls.webapp2.WSGIApplication.allowed_methods) + methods.add('PATCH') + cls.webapp2.WSGIApplication.allowed_methods = frozenset(methods) + app = cls.webapp2.WSGIApplication( + [("/api/events/(.*)/followers", EventFollowersHandler) + ], debug=True) + cls.testapp = cls.webtest.TestApp(app) + + """Init the models.""" + cls.user = mocks.create_user('user@gmail.com') + cls.another_user = mocks.create_user('another@gmail.com') + cls.another_user.state = 'active' + cls.another_user.put() + + cls.institution = mocks.create_institution() + cls.institution.members = [cls.user.key] + cls.institution.followers = [cls.user.key] + cls.institution.admin = cls.user.key + cls.institution.put() + + cls.user.add_institution(cls.institution.key) + cls.user.follows = [cls.institution.key] + cls.user.put() + + cls.event = mocks.create_event(cls.user, cls.institution) + + @patch('util.login_service.verify_token', return_value={'email': 'another@gmail.com'}) + def test_post(self, verify_token): + """.""" + self.assertEqual(len(self.event.followers), 1) + + self.testapp.post("/api/events/%s/followers" %self.event.key.urlsafe()) + + self.event = self.event.key.get() + + self.assertEqual(len(self.event.followers), 2) + + @patch('util.login_service.verify_token', return_value={'email': 'another@gmail.com'}) + def test_post_with_unpublished_event(self, verify_token): + """.""" + self.assertEqual(len(self.event.followers), 1) + self.event.state = 'draft' + self.event.put() + + with self.assertRaises(Exception) as ex: + self.testapp.post("/api/events/%s/followers" %self.event.key.urlsafe()) + + exception_message = self.get_message_exception(ex.exception.message) + self.assertEqual(exception_message, "Error! The event is not published") + + @patch('util.login_service.verify_token', return_value={'email': 'another@gmail.com'}) + def test_delete_a_not_follower(self, verify_token): + """.""" + self.assertEqual(len(self.event.followers), 1) + + with self.assertRaises(Exception) as ex: + self.testapp.delete("/api/events/%s/followers" %self.event.key.urlsafe()) + + exception_message = self.get_message_exception(ex.exception.message) + self.assertEqual(exception_message, "Error! The user is not a follower") + + @patch('util.login_service.verify_token', return_value={'email': 'another@gmail.com'}) + def test_delete_with_a_deleted_event(self, verify_token): + """.""" + self.assertEqual(len(self.event.followers), 1) + self.event.state = 'deleted' + self.event.put() + + with self.assertRaises(Exception) as ex: + self.testapp.delete("/api/events/%s/followers" %self.event.key.urlsafe()) + + exception_message = self.get_message_exception(ex.exception.message) + self.assertEqual(exception_message, "Error! The event is not published") + + @patch('util.login_service.verify_token', return_value={'email': 'another@gmail.com'}) + def test_delete(self, verify_token): + """.""" + self.assertEqual(len(self.event.followers), 1) + + self.testapp.post("/api/events/%s/followers" %self.event.key.urlsafe()) + + self.event = self.event.key.get() + self.assertEqual(len(self.event.followers), 2) + + self.testapp.delete("/api/events/%s/followers" %self.event.key.urlsafe()) + + self.event = self.event.key.get() + self.assertEqual(len(self.event.followers), 1) + + + + def tearDown(cls): + """Deactivate the test.""" + cls.test.deactivate() diff --git a/backend/test/event_handlers_tests/event_handler_test.py b/backend/test/event_handlers_tests/event_handler_test.py index ba8033b6b..2055a211a 100644 --- a/backend/test/event_handlers_tests/event_handler_test.py +++ b/backend/test/event_handlers_tests/event_handler_test.py @@ -6,7 +6,7 @@ from models import Institution from models import Event from handlers.event_handler import EventHandler -from mock import patch +from mock import patch, call import datetime import json @@ -48,14 +48,40 @@ def setUp(cls): # Events cls.event = mocks.create_event(cls.user, cls.institution) + @patch('handlers.event_handler.enqueue_task') @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) - def test_delete_by_author(self, verify_token): + def test_delete_by_author(self, verify_token, enqueue_task): """Test the event_handler's delete method when user is author.""" self.user.add_permissions( ['edit_post', 'remove_post'], self.event.key.urlsafe()) # Call the delete method self.testapp.delete("/api/events/%s" % - self.event.key.urlsafe()) + self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) + + not_params = { + 'receiver_key': self.event.author_key.urlsafe(), + 'sender_key': self.user.key.urlsafe(), + 'entity_key': self.event.key.urlsafe(), + 'entity_type': 'DELETED_EVENT', + 'current_institution': self.institution.key.urlsafe(), + 'sender_institution_key': self.institution.key.urlsafe(), + 'field': 'followers', + 'title': self.event.title + } + + push_not_queue_call_params = { + 'type': 'DELETED_EVENT', + 'receivers': [follower.urlsafe() for follower in self.event.followers], + 'entity': self.event.key.urlsafe() + } + + calls = [ + call('multiple-notification', not_params), + call('send-push-notification', push_not_queue_call_params) + ] + + enqueue_task.assert_has_calls(calls) + # Refresh event self.event = self.event.key.get() # Verify if after delete the state of event is deleted @@ -71,7 +97,7 @@ def test_delete_by_author(self, verify_token): # Call the patch method and assert that it raises an exception with self.assertRaises(Exception): self.testapp.delete("/api/events/%s" % - self.event.key.urlsafe()) + self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) @patch('util.login_service.verify_token', return_value={'email': 'usersd@gmail.com'}) def test_delete_by_admin(self, verify_token): @@ -80,7 +106,7 @@ def test_delete_by_admin(self, verify_token): # because the user doesn't have the permission yet. with self.assertRaises(Exception) as raises_context: self.testapp.delete("/api/events/%s" % - self.event.key.urlsafe()) + self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) message = self.get_message_exception(str(raises_context.exception)) self.assertEquals(message, "Error! The user can not remove this event") @@ -89,7 +115,7 @@ def test_delete_by_admin(self, verify_token): # Call the delete method self.testapp.delete("/api/events/%s" % - self.event.key.urlsafe()) + self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) # Refresh event self.event = self.event.key.get() # Verify if after delete the state of event is deleted @@ -117,7 +143,7 @@ def test_patch(self, verify_token): self.user.add_permission('edit_post', self.event.key.urlsafe()) self.testapp.patch("/api/events/" + self.event.key.urlsafe(), - json_edit) + json_edit, headers={'institution-authorization': self.institution.key.urlsafe()}) self.event = self.event.key.get() self.assertEqual(self.event.title, "Edit Event") @@ -134,7 +160,7 @@ def test_patch(self, verify_token): self.event.key.urlsafe(), [{"op": "replace", "path": "/start_time", "value": '2018-07-27T12:30:15'} - ] + ], headers={'institution-authorization': self.institution.key.urlsafe()} ) # test the case when the end_time is before start_time @@ -143,7 +169,7 @@ def test_patch(self, verify_token): self.event.key.urlsafe(), [{"op": "replace", "path": "/end_time", "value": '2018-07-07T12:30:15'} - ] + ], headers={'institution-authorization': self.institution.key.urlsafe()} ) # Pretend a new authentication @@ -154,11 +180,12 @@ def test_patch(self, verify_token): self.testapp.patch_json("/api/events/%s" % self.event.key.urlsafe(), [{"op": "replace", "path": "/local", - "value": "New Local"}] - ) + "value": "New Local"}], + headers={'institution-authorization': self.institution.key.urlsafe()}) + @patch('handlers.event_handler.enqueue_task') @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) - def test_pacth_datetime(self, verify_token): + def test_pacth_datetime(self, verify_token, enqueue_task): """Test pacth datetimes in event handler.""" json_edit = json.dumps([ {"op": "replace", "path": "/start_time", @@ -169,8 +196,8 @@ def test_pacth_datetime(self, verify_token): self.user.add_permission('edit_post', self.event.key.urlsafe()) self.testapp.patch("/api/events/" + - self.event.key.urlsafe(), - json_edit) + self.event.key.urlsafe(), json_edit, + headers={'institution-authorization': self.institution.key.urlsafe()}) self.event = self.event.key.get() @@ -180,6 +207,30 @@ def test_pacth_datetime(self, verify_token): '2018-07-14T12:30:15') self.assertEqual(self.event.end_time.isoformat(), '2018-07-25T12:30:15') + + not_params = { + 'receiver_key': self.event.author_key.urlsafe(), + 'sender_key': self.user.key.urlsafe(), + 'entity_key': self.event.key.urlsafe(), + 'entity_type': 'UPDATED_EVENT', + 'current_institution': self.institution.key.urlsafe(), + 'sender_institution_key': self.institution.key.urlsafe(), + 'field': 'followers', + 'title': self.event.title + } + + push_not_queue_call_params = { + 'type': 'UPDATED_EVENT', + 'receivers': [follower.urlsafe() for follower in self.event.followers], + 'entity': self.event.key.urlsafe() + } + + calls = [ + call('multiple-notification', not_params), + call('send-push-notification', push_not_queue_call_params) + ] + + enqueue_task.assert_has_calls(calls) @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) def test_patch_on_event_outdated(self, verify_token): @@ -209,7 +260,7 @@ def test_patch_on_event_outdated(self, verify_token): patch = [{"op": "replace", "path": "/"+prop, "value": value}] self.testapp.patch("/api/events/" + self.event.key.urlsafe(), - json.dumps(patch)) + json.dumps(patch), headers={'institution-authorization': self.institution.key.urlsafe()}) self.event = self.event.key.get() self.assertEquals( @@ -222,7 +273,7 @@ def test_get_a_deleted_event(self, verify_token): self.event.put() with self.assertRaises(Exception) as ex: - self.testapp.get('/api/events/%s' %self.event.key.urlsafe()) + self.testapp.get('/api/events/%s' %self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) exception_message = self.get_message_exception(ex.exception.message) self.assertTrue(exception_message == 'Error! The event has been deleted.') @@ -235,7 +286,8 @@ def test_patch_a_deleted_event(self, verify_token): with self.assertRaises(Exception) as ex: patch = [{"op": "replace", "path": "/title", "value": 'other_value'}] - self.testapp.patch('/api/events/%s' % self.event.key.urlsafe(), json.dumps(patch)) + self.testapp.patch('/api/events/%s' % self.event.key.urlsafe(), json.dumps(patch), + headers={'institution-authorization': self.institution.key.urlsafe()}) exception_message = self.get_message_exception(ex.exception.message) self.assertTrue(exception_message == @@ -256,7 +308,7 @@ def test_permissions_in_delete(self, verify_token): self.assertTrue(self.event.state != 'deleted') self.user.add_permissions(['edit_post', 'remove_post'], self.event.key.urlsafe()) - self.testapp.delete("/api/events/%s" %self.event.key.urlsafe()) + self.testapp.delete("/api/events/%s" %self.event.key.urlsafe(), headers={'institution-authorization': self.institution.key.urlsafe()}) self.event = self.event.key.get() self.assertTrue(self.event.state == 'deleted') @@ -266,7 +318,7 @@ def test_patch_without_permission(self, verify_token): with self.assertRaises(Exception) as ex: patch = [{"op": "replace", "path": "/title", "value": 'other_value'}] self.testapp.patch('/api/events/%s' % - self.event.key.urlsafe(), json.dumps(patch)) + self.event.key.urlsafe(), json.dumps(patch), headers={'institution-authorization': self.institution.key.urlsafe()}) exception_message = self.get_message_exception(ex.exception.message) self.assertTrue(exception_message == diff --git a/backend/test/feature_toggle_handler_tests/__init__.py b/backend/test/feature_toggle_handler_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/test/feature_toggle_handler_tests/feature_toggle_handler_test.py b/backend/test/feature_toggle_handler_tests/feature_toggle_handler_test.py new file mode 100644 index 000000000..ad99120c6 --- /dev/null +++ b/backend/test/feature_toggle_handler_tests/feature_toggle_handler_test.py @@ -0,0 +1,99 @@ +"""Feature toggle handler test""" + +import json +from ..test_base_handler import TestBaseHandler +from handlers import FeatureToggleHandler +from models import Feature +from mock import patch +from .. import mocks + + +USER = {'email': 'user@email.com'} + +class FeatureToggleHandlerTest(TestBaseHandler): + """ + Feature Toggle Handler Test. + """ + + @classmethod + def setUp(cls): + """Provide the base for the tests.""" + super(FeatureToggleHandlerTest, cls).setUp() + app = cls.webapp2.WSGIApplication( + [("/api/feature-toggles.*", + FeatureToggleHandler) + ], debug=True) + cls.testapp = cls.webtest.TestApp(app) + + cls.feature = Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + cls.other_feature = Feature.create('feature-test-other', {'pt-br': 'Feature Teste'}) + + + @patch('util.login_service.verify_token', return_value=USER) + def test_get_all(self, verify_token): + """Test get all features.""" + + features = self.testapp.get('/api/feature-toggles?lang=pt-br').json + features_make = [self.feature.make(), self.other_feature.make()] + + self.assertEquals(len(features), 2) + self.assertItemsEqual(features, features_make) + + @patch('util.login_service.verify_token', return_value=USER) + def test_get_by_query(self, verify_token): + """Test get feature with query parameter.""" + feature = self.testapp.get('/api/feature-toggles?name=feature-test&lang=pt-br').json + feature_make = [self.feature.make()] + + self.assertListEqual(feature, feature_make) + + feature = self.testapp.get('/api/feature-toggles?name=feature-test-other&lang=pt-br').json + feature_make = [self.other_feature.make()] + + self.assertListEqual(feature, feature_make) + + with self.assertRaises(Exception) as raises_context: + self.testapp.get('/api/feature-toggles?name=sfjkldh') + + exception_message = self.get_message_exception(str(raises_context.exception)) + + self.assertEquals(exception_message, "Error! Feature not found!") + + @patch('util.login_service.verify_token', return_value=USER) + def test_put(self, verify_token): + """Test put features.""" + + user_admin = mocks.create_user('user@email.com') + user = mocks.create_user() + deciis = mocks.create_institution('DECIIS') + deciis.trusted = True + deciis.add_member(user_admin) + deciis.set_admin(user_admin.key) + user_admin.add_institution(deciis.key) + user_admin.add_institution_admin(deciis.key) + + feature = self.feature.make() + other_feature = self.other_feature.make() + + feature['enable_mobile'] = 'DISABLED' + other_feature['enable_desktop'] = 'DISABLED' + + self.testapp.put_json('/api/feature-toggles', feature) + self.testapp.put_json('/api/feature-toggles', other_feature) + + self.feature = self.feature.key.get() + self.other_feature = self.other_feature.key.get() + + self.assertEquals(self.feature.enable_desktop, 'ALL') + self.assertEquals(self.feature.enable_mobile, 'DISABLED') + self.assertEquals(self.other_feature.enable_desktop, 'DISABLED') + self.assertEquals(self.other_feature.enable_mobile, 'ALL') + + verify_token._mock_return_value = {'email': user.email[0]} + + with self.assertRaises(Exception) as raises_context: + self.testapp.put_json('/api/feature-toggles', feature) + + exception_message = self.get_message_exception(str(raises_context.exception)) + + self.assertEquals(exception_message, 'Error! User not allowed to modify features!') diff --git a/backend/test/institution_handlers_tests/institution_member_handler_test.py b/backend/test/institution_handlers_tests/institution_member_handler_test.py index e4825a0ce..1f085fc91 100644 --- a/backend/test/institution_handlers_tests/institution_member_handler_test.py +++ b/backend/test/institution_handlers_tests/institution_member_handler_test.py @@ -55,11 +55,12 @@ def setUp(cls): cls.second_user.put() # create headers cls.headers = {'Institution-Authorization': cls.institution.key.urlsafe()} - + + @patch('handlers.institution_members_handler.enqueue_task') @patch('handlers.institution_members_handler.send_message_notification') @patch('handlers.institution_members_handler.RemoveMemberEmailSender.send_email') @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) - def test_delete_with_notification(self, verify_token, send_email, send_message_notification): + def test_delete_with_notification(self, verify_token, send_email, send_message_notification, enqueue_task): """Test if a notification is sent when the member is deleted.""" # Set up the second_user self.second_user.institutions = [self.institution.key, self.other_institution.key] @@ -98,11 +99,17 @@ def test_delete_with_notification(self, verify_token, send_email, send_message_n ) # Assert that send_email has been called send_email.assert_called() - + enqueue_task.assert_called_with('send-push-notification', { + 'type': 'DELETE_MEMBER', + 'receivers': [self.second_user.key.urlsafe()], + 'entity': self.institution.key.urlsafe() + }) + + @patch('handlers.institution_members_handler.enqueue_task') @patch('handlers.institution_members_handler.send_message_notification') @patch('handlers.institution_members_handler.RemoveMemberEmailSender.send_email') @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) - def test_delete_member_with_one_institution(self, verify_token, send_email, send_message_notification): + def test_delete_member_with_one_institution(self, verify_token, send_email, send_message_notification, enqueue_task): """Test delete a member that belongs to only one institution.""" # new user third_user = mocks.create_user() @@ -125,6 +132,12 @@ def test_delete_member_with_one_institution(self, verify_token, send_email, send # Assert that send_email has been called send_email.assert_called() + enqueue_task.assert_called_with('send-push-notification', { + 'type': 'DELETE_MEMBER', + 'receivers': [third_user.key.urlsafe()], + 'entity': self.institution.key.urlsafe() + }) + @patch('util.login_service.verify_token', return_value={'email': 'user@gmail.com'}) def test_delete(self, verify_token): """Test delete method with an user that is not admin""" diff --git a/backend/test/institution_handlers_tests/institution_parent_handler_test.py b/backend/test/institution_handlers_tests/institution_parent_handler_test.py index df2bdd8bc..f3d731b96 100644 --- a/backend/test/institution_handlers_tests/institution_parent_handler_test.py +++ b/backend/test/institution_handlers_tests/institution_parent_handler_test.py @@ -3,7 +3,7 @@ from ..test_base_handler import TestBaseHandler from handlers import InstitutionParentHandler -from mock import patch +from mock import patch, call from .. import mocks import json @@ -78,14 +78,24 @@ def test_delete_child_connection(self, verify_token, send_message_notification, message=json.dumps(message) ) - enqueue_task.assert_called_with( - 'remove-admin-permissions', + calls = [ + call('remove-admin-permissions', { 'institution_key': otherinst.key.urlsafe(), 'parent_key': institution.key.urlsafe(), 'notification_id': '01-938483948393' - } - ) + }), + call( + 'send-push-notification', { + 'type': 'REMOVE_INSTITUTION_LINK', + 'receivers': [otherinst.admin.urlsafe()], + 'entity': otherinst.key.urlsafe() + + } + ) + ] + + enqueue_task.assert_has_calls(calls) @patch('util.login_service.verify_token') def test_delete_without_permission(self, verify_token): diff --git a/backend/test/like_handlers_tests/like_post_handler_test.py b/backend/test/like_handlers_tests/like_post_handler_test.py index 52835f71c..52dd044d1 100644 --- a/backend/test/like_handlers_tests/like_post_handler_test.py +++ b/backend/test/like_handlers_tests/like_post_handler_test.py @@ -94,7 +94,8 @@ def test_post(self, verify_token, enqueue_task): 'entity_key': self.post.key.urlsafe(), 'entity_type': 'LIKE_POST', 'current_institution': self.institution.key.urlsafe(), - 'sender_institution_key': self.post.institution.urlsafe() + 'sender_institution_key': self.post.institution.urlsafe(), + 'field': 'subscribers' } push_not_params = { @@ -104,7 +105,7 @@ def test_post(self, verify_token, enqueue_task): } calls = [ - call('post-notification', post_not_params), + call('multiple-notification', post_not_params), call('send-push-notification', push_not_params) ] diff --git a/backend/test/model_test/event_test.py b/backend/test/model_test/event_test.py index 0e02b46b0..4cdead29e 100644 --- a/backend/test/model_test/event_test.py +++ b/backend/test/model_test/event_test.py @@ -29,6 +29,12 @@ def setUp(cls): """Init the models.""" # new User user cls.user = mocks.create_user("test@example.com") + cls.user.state = 'active' + cls.user.put() + + cls.another_user = mocks.create_user("another@gmail.com") + cls.another_user.state = 'active' + cls.another_user.put() # new Institution cls.institution = mocks.create_institution() cls.institution.members = [cls.user.key] @@ -129,3 +135,66 @@ def test_verify_patch(self): "The event basic data can not be changed after it has ended", "The exception message is not equal to the expected one" ) + + def test_add_follower(self): + """Test regular add follower""" + self.assertEqual(len(self.event.followers), 1) + + self.event.add_follower(self.another_user) + + self.assertEqual(len(self.event.followers), 2) + + def test_add_follower_with_an_inactive_user(self): + """Test add an inactive user as a follower""" + self.another_user.state = 'pending' + self.another_user.put() + + self.assertEqual(len(self.event.followers), 1) + + with self.assertRaises(Exception) as ex: + self.event.add_follower(self.another_user) + + self.assertEqual(str(ex.__dict__['exception']), "The user is not active") + self.assertEqual(len(self.event.followers), 1) + + def test_add_an_user_who_is_a_follower_yet(self): + """Test add a user who is a follower""" + self.assertEqual(len(self.event.followers), 1) + + with self.assertRaises(Exception) as ex: + self.event.add_follower(self.user) + + self.assertEqual(str(ex.__dict__['exception']), "The user is a follower yet") + self.assertEqual(len(self.event.followers), 1) + + def test_remove_follower(self): + """Test regular remove follower""" + self.assertEqual(len(self.event.followers), 1) + + self.event.add_follower(self.another_user) + + self.assertEqual(len(self.event.followers), 2) + + self.event.remove_follower(self.another_user) + + self.assertEqual(len(self.event.followers), 1) + + def test_remove_a_user_who_is_not_a_follower(self): + """Test remove a user who is not a follower""" + self.assertEqual(len(self.event.followers), 1) + + with self.assertRaises(Exception) as ex: + self.event.remove_follower(self.another_user) + + self.assertEqual(str(ex.__dict__['exception']), "The user is not a follower") + self.assertEqual(len(self.event.followers), 1) + + def test_remove_a_user_who_is_the_author(self): + """Test remove a user who is the author""" + self.assertEqual(len(self.event.followers), 1) + + with self.assertRaises(Exception) as ex: + self.event.remove_follower(self.user) + + self.assertEqual(str(ex.__dict__['exception']), "The user is the author") + self.assertEqual(len(self.event.followers), 1) \ No newline at end of file diff --git a/backend/test/model_test/feature_test.py b/backend/test/model_test/feature_test.py new file mode 100644 index 000000000..610b814fd --- /dev/null +++ b/backend/test/model_test/feature_test.py @@ -0,0 +1,105 @@ +"""Feature Test.""" + +from ..test_base import TestBase +from models import Feature + + +class FeatureTest(TestBase): + """Feature model test.""" + + @classmethod + def setUp(cls): + """Provide the base for the tests.""" + cls.test = cls.testbed.Testbed() + cls.test.activate() + cls.policy = cls.datastore.PseudoRandomHRConsistencyPolicy( + probability=1) + cls.test.init_datastore_v3_stub(consistency_policy=cls.policy) + cls.test.init_memcache_stub() + + def test_create(self): + """Teste create a new feature.""" + feature = Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + self.assertEqual(feature.name, 'feature-test') + self.assertEqual(feature.enable_desktop, 'ALL') + self.assertEqual(feature.enable_mobile, 'ALL') + + feature = Feature.create('feature-test2', {'pt-br': 'Feature Teste'}, 'DISABLED') + self.assertEqual(feature.name, 'feature-test2') + self.assertEqual(feature.enable_desktop, 'ALL') + self.assertEqual(feature.enable_mobile, 'DISABLED') + + feature = Feature.create('feature-test3', {'pt-br': 'Feature Teste'}, 'DISABLED', 'DISABLED') + self.assertEqual(feature.name, 'feature-test3') + self.assertEqual(feature.enable_desktop, 'DISABLED') + self.assertEqual(feature.enable_mobile, 'DISABLED') + + with self.assertRaises(Exception) as raises_context: + Feature.create('feature-test', {'pt-br': 'Feature Teste'}, 'asjdkhd') + + exception_message = raises_context.exception + self.assertEquals( + str(exception_message), + "Value 'asjdkhd' for property enable_mobile is not an allowed choice" + ) + + def test_set_visibility(self): + """Test set visibility.""" + Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + + feature_dict = { + 'name': 'feature-test', + 'enable_mobile': 'DISABLED', + 'enable_desktop': 'ADMIN' + } + + Feature.set_visibility(feature_dict) + + feature = Feature.get_feature('feature-test') + + self.assertEqual(feature.enable_mobile, 'DISABLED') + self.assertEqual(feature.enable_desktop, 'ADMIN') + + def test_get_all_features(self): + """Test get all features.""" + feature = Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + feature2 = Feature.create('feature-test2', {'pt-br': 'Feature Teste'}) + + features = Feature.get_all_features() + self.assertIn(feature, features) + self.assertIn(feature2, features) + + feature3 = Feature.create('feature-test3', {'pt-br': 'Feature Teste'}) + self.assertNotIn(feature3, features) + + features = Feature.get_all_features() + self.assertIn(feature3, features) + + def test_get_feature(self): + """Test get feature.""" + feature = Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + feature2 = Feature.create('feature-test2', {'pt-br': 'Feature Teste'}) + + self.assertEqual(feature, Feature.get_feature('feature-test')) + self.assertEqual(feature2, Feature.get_feature('feature-test2')) + + with self.assertRaises(Exception) as raises_context: + Feature.get_feature('djsasadj') + + exception_message = raises_context.exception + self.assertEquals( + str(exception_message), + "Feature not found!" + ) + + def test_make(self): + """Test make feature.""" + feature = Feature.create('feature-test', {'pt-br': 'Feature Teste'}) + make = { + 'name': 'feature-test', + 'enable_mobile': 'ALL', + 'enable_desktop': 'ALL', + 'translation': 'Feature Teste' + } + + self.assertEqual(make, feature.make()) diff --git a/backend/test/model_test/institution_profile_test.py b/backend/test/model_test/institution_profile_test.py index 5fe4f4c04..240be271e 100644 --- a/backend/test/model_test/institution_profile_test.py +++ b/backend/test/model_test/institution_profile_test.py @@ -24,6 +24,7 @@ def test_make(self): institution = mocks.create_institution() institution.name = 'institution_name' institution.photo_url = 'photo_url.com' + institution.acronym = 'inst' institution.put() self.data_profile['institution_key'] = institution.key.urlsafe() profile = InstitutionProfile.create(self.data_profile) @@ -37,7 +38,9 @@ def test_make(self): 'branch_line': '888', 'institution': { 'name': 'institution_name'.decode('utf8'), - 'photo_url': 'photo_url.com'.decode('utf8') + 'photo_url': 'photo_url.com'.decode('utf8'), + 'acronym': 'inst', + 'key': institution.key.urlsafe() } } diff --git a/backend/test/post_handlers_tests/post_collection_handler_test.py b/backend/test/post_handlers_tests/post_collection_handler_test.py index 848479e39..6c6af9608 100644 --- a/backend/test/post_handlers_tests/post_collection_handler_test.py +++ b/backend/test/post_handlers_tests/post_collection_handler_test.py @@ -193,8 +193,13 @@ def test_post_sharing(self, verify_token, enqueue_task): 'current_institution': self.institution.key.urlsafe() } ), + call('send-push-notification', { + 'type': 'CREATE_POST', + 'entity': post.get('key'), + 'receivers': [follower.urlsafe() for follower in self.post.institution.get().followers] + }), call( - 'post-notification', + 'multiple-notification', { 'receiver_key': self.post.author.urlsafe(), 'sender_key': self.user.key.urlsafe(), diff --git a/backend/test/post_handlers_tests/post_comment_handler_test.py b/backend/test/post_handlers_tests/post_comment_handler_test.py index 54458ab7b..9af707b29 100644 --- a/backend/test/post_handlers_tests/post_comment_handler_test.py +++ b/backend/test/post_handlers_tests/post_comment_handler_test.py @@ -86,7 +86,8 @@ def test_post(self, verify_token, enqueue_task): 'entity_key': self.user_post.key.urlsafe(), 'entity_type': 'COMMENT', 'current_institution': self.institution.key.urlsafe(), - 'sender_institution_key': self.user_post.institution.urlsafe() + 'sender_institution_key': self.user_post.institution.urlsafe(), + 'field': 'subscribers' } push_not_params = { @@ -96,7 +97,7 @@ def test_post(self, verify_token, enqueue_task): } calls = [ - call('post-notification', post_not_params), + call('multiple-notification', post_not_params), call('send-push-notification', push_not_params) ] diff --git a/backend/test/post_handlers_tests/post_handler_test.py b/backend/test/post_handlers_tests/post_handler_test.py index 040dc2e04..1af51bb50 100644 --- a/backend/test/post_handlers_tests/post_handler_test.py +++ b/backend/test/post_handlers_tests/post_handler_test.py @@ -242,9 +242,10 @@ def test_patch(self, verify_token): exception_message, expected_alert + raises_context_message) + @patch('handlers.post_handler.enqueue_task') @patch('handlers.post_handler.send_message_notification') @patch('util.login_service.verify_token', return_value={'email': 'first_user@gmail.com'}) - def test_delete_with_admin(self, verify_token, mock_method): + def test_delete_with_admin(self, verify_token, mock_method, enqueue_task): """Test delete a post with admin.""" self.first_user.add_permission( "remove_posts", self.institution.key.urlsafe()) @@ -261,6 +262,12 @@ def test_delete_with_admin(self, verify_token, mock_method): mock_method.assert_called() + enqueue_task.assert_called_with('send-push-notification', { + 'type': 'DELETE_POST', + 'entity': self.second_user_post.key.urlsafe(), + 'receivers': [self.second_user_post.author.urlsafe()] + }) + @patch('util.login_service.verify_token', return_value={'email': 'second_user@ccc.ufcg.edu.br'}) def test_delete_without_admin(self, verify_token): """Test delete a post with admin.""" diff --git a/backend/test/post_handlers_tests/reply_comment_handler_test.py b/backend/test/post_handlers_tests/reply_comment_handler_test.py index 3e900aad6..344ec30f4 100644 --- a/backend/test/post_handlers_tests/reply_comment_handler_test.py +++ b/backend/test/post_handlers_tests/reply_comment_handler_test.py @@ -58,10 +58,11 @@ def setUp(cls): cls.user_post = cls.user_post.key.get() cls.user_post.put() - + + @patch('handlers.reply_comment_handler.enqueue_task') @patch('handlers.reply_comment_handler.send_message_notification') @patch('util.login_service.verify_token', return_value={'email': THIRD_USER_EMAIL}) - def test_post(self, verify_token, send_message_notification): + def test_post(self, verify_token, send_message_notification, enqueue_task): """Reply a comment of post""" # Verify size of list other_user_comment = self.user_post.get_comment(self.other_user_comment.id) @@ -123,6 +124,12 @@ def test_post(self, verify_token, send_message_notification): ) ] send_message_notification.assert_has_calls(calls) + + enqueue_task.assert_called_with('send-push-notification', { + 'type': 'REPLY_COMMENT', + 'receivers': [self.other_user.key.urlsafe()], + 'entity': self.user_post.key.urlsafe() + }) @patch('handlers.reply_comment_handler.send_message_notification') @patch('util.login_service.verify_token', return_value={'email': THIRD_USER_EMAIL}) diff --git a/backend/test/services_tests/service_messages_test.py b/backend/test/services_tests/service_messages_test.py index ebe3b9ef1..991ee5854 100644 --- a/backend/test/services_tests/service_messages_test.py +++ b/backend/test/services_tests/service_messages_test.py @@ -55,7 +55,7 @@ def test_create_entity_from_institution(self): self.assertEquals( entity, - json.dumps(expected_entity), + expected_entity, "The created entity should be equal to the expected one" ) @@ -71,12 +71,12 @@ def test_create_entity_from_post(self): self.assertEquals( entity, - json.dumps(expected_entity), + expected_entity, "The created entity should be equal to the expected one" ) - @mock.patch('service_messages.create_entity') + @mock.patch('service_messages.create_entity', return_value={"key": 'opaskdop-OAPKSDPOAK'}) @mock.patch('service_messages.taskqueue.add') def test_send_message_notification(self, taskqueue_add, create_entity): """Test send_message_notification method.""" diff --git a/backend/test/user_handlers_tests/user_handler_test.py b/backend/test/user_handlers_tests/user_handler_test.py index 84854bc08..e981c0d07 100644 --- a/backend/test/user_handlers_tests/user_handler_test.py +++ b/backend/test/user_handlers_tests/user_handler_test.py @@ -94,10 +94,11 @@ def test_get(self, verify_token): user['institutions_admin'], [inst_admin_url], "The institutions_admin is different from the expected one" ) - + + @patch('handlers.user_handler.enqueue_task') @patch('handlers.user_handler.send_message_notification') @patch('util.login_service.verify_token') - def test_delete(self, verify_token, send_notification): + def test_delete(self, verify_token, send_notification, enqueue_task): """Test the user_handler's delete method.""" verify_token._mock_return_value = {'email': self.other_user.email[0]} # check the user properties before delete it @@ -144,6 +145,8 @@ def test_delete(self, verify_token, send_notification): send_notification.assert_called() + enqueue_task.assert_called() + @patch('util.login_service.verify_token') def test_patch(self, verify_token): diff --git a/backend/test/user_handlers_tests/user_institutions_handler_test.py b/backend/test/user_handlers_tests/user_institutions_handler_test.py index 9a4b872ca..c61d51b20 100644 --- a/backend/test/user_handlers_tests/user_institutions_handler_test.py +++ b/backend/test/user_handlers_tests/user_institutions_handler_test.py @@ -20,10 +20,11 @@ def setUp(cls): ], debug=True) cls.testapp = cls.webtest.TestApp(app) initModels(cls) - + + @patch('handlers.user_institutions_handler.enqueue_task') @patch('handlers.user_institutions_handler.LeaveInstitutionEmailSender.send_email') @patch('util.login_service.verify_token', return_value={'email': 'second_user@gmail.com'}) - def test_delete(self, verify_token, send_email): + def test_delete(self, verify_token, send_email, enqueue_task): """Test delete.""" # Assert the initial conditions self.assertTrue(self.second_user.key in self.institution.members) @@ -47,6 +48,12 @@ def test_delete(self, verify_token, send_email): # Assert that send_email has been called send_email.assert_called() + enqueue_task.assert_called_with('send-push-notification', { + 'type': 'LEFT_INSTITUTION', + 'receivers': [self.institution.admin.urlsafe()], + 'entity': self.second_user.key.urlsafe() + }) + def initModels(cls): """Init the tests' common models.""" diff --git a/backend/test/util_modules_tests/push_notification_service_test.py b/backend/test/util_modules_tests/push_notification_service_test.py index 88cfeea04..d79165429 100644 --- a/backend/test/util_modules_tests/push_notification_service_test.py +++ b/backend/test/util_modules_tests/push_notification_service_test.py @@ -20,7 +20,10 @@ def setUp(cls): cls.test.init_memcache_stub() cls.f_user = mocks.create_user() cls.inst = mocks.create_institution() + cls.inst.admin = cls.f_user.key + cls.inst.put() cls.post = mocks.create_post(cls.f_user.key, cls.inst.key) + cls.event = mocks.create_event(cls.f_user, cls.inst) def test_like_post_notification(self): @@ -33,8 +36,8 @@ def test_like_post_notification(self): self.assertEqual(notification_props['title'], 'Publicação curtida', "The notification's title wasn't the expected one") self.assertEqual( - notification_props['body'], 'Uma publicação de seu interesse foi curtida', - "The notification's body wasn't the expected one") + notification_props['body_message'], 'Uma publicação de seu interesse foi curtida', + "The notification's body_message wasn't the expected one") self.assertEqual(notification_props['click_action'], url, "The click_action's url wasn't the expected one") @@ -61,8 +64,8 @@ def test_comment_notification(self): self.assertEqual(notification_props['title'], 'Publicação comentada', "The notification's title wasn't the expected one") self.assertEqual( - notification_props['body'], 'Uma publicação do seu interesse foi comentada', - "The notification's body wasn't the expected one") + notification_props['body_message'], 'Uma publicação do seu interesse foi comentada', + "The notification's body_message wasn't the expected one") self.assertEqual(notification_props['click_action'], url, "The click_action wasn't the expected one") @@ -88,9 +91,9 @@ def test_invite_user_notification(self): self.assertEqual(notification_props['title'], 'Novo convite', "The notification's title wasn't the expected one") - self.assertEqual(notification_props['body'], + self.assertEqual(notification_props['body_message'], 'Você recebeu um novo convite para ser membro de uma instituição', - "The notification's body wasn't the expected one") + "The notification's body_message wasn't the expected one") self.assertEqual(notification_props['click_action'], url, "The click_action wasn't the expected one") @@ -103,8 +106,188 @@ def test_invite_user_adm_notification(self): self.assertEqual(notification_props['title'], 'Novo convite', "The notification's title wasn't the expected one") - self.assertEqual(notification_props['body'], + self.assertEqual(notification_props['body_message'], 'Você recebeu um novo convite para ser administrador de uma instituição', - "The notification's body wasn't the expected one") + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_link_notification(self): + """Test if the properties for LINK + notification are the expected.""" + url = "/institution/%s/inviteInstitution" % self.inst.key.urlsafe() + + notification_props = get_notification_props(NotificationType('LINK'), self.inst) + + self.assertEqual(notification_props['title'], 'Solicitação de vínculo', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'Uma instituição que você administra recebeu uma nova solicitação de vínculo', + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_delete_member_notification(self): + """Test if the properties for DELETE_MEMBER + notification are the expected.""" + url = '/institution/%s/home' %self.inst.key.urlsafe() + + notification_props = get_notification_props(NotificationType('DELETE_MEMBER'), self.inst) + + self.assertEqual(notification_props['title'], 'Remoção de vínculo', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'Você foi removido da instituição %s' %self.inst.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_remove_inst_link_notification(self): + """Test if the properties for REMOVE_INSTITUTION_LINK + notification are the expected.""" + url = '/institution/%s/inviteInstitution' %self.inst.key.urlsafe() + + notification_props = get_notification_props(NotificationType('REMOVE_INSTITUTION_LINK'), self.inst) + + self.assertEqual(notification_props['title'], 'Remoção de vínculo', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'A instituição %s teve um de seus vínculos removidos' %self.inst.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_create_post_notification(self): + """Test if the properties for CREATE_POST + notification are the expected.""" + url = '/posts/%s' %self.post.key.urlsafe() + + notification_props = get_notification_props(NotificationType('CREATE_POST'), self.post) + + self.assertEqual(notification_props['title'], 'Novo post criado', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + '%s criou um novo post' %self.post.author.urlsafe(), + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_delete_post_notification(self): + """Test if the properties for DELETE_POST + notification are the expected.""" + url = "/" + + notification_props = get_notification_props(NotificationType('DELETE_POST'), self.post) + + self.assertEqual(notification_props['title'], 'Post deletado', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + '%s deletou seu post' %self.f_user.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_reply_comment_notification(self): + """Test if the properties for REPLY_COMMENT + notification are the expected.""" + url = '/posts/%s' %self.post.key.urlsafe() + + notification_props = get_notification_props(NotificationType('REPLY_COMMENT'), self.post) + + self.assertEqual(notification_props['title'], 'Novo comentário', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'Seu comentário tem uma nova resposta', + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_deleted_user_notification(self): + """Test if the properties for DELETED_USER + notification are the expected.""" + url = "/" + + notification_props = get_notification_props(NotificationType('DELETED_USER'), self.f_user) + + self.assertEqual(notification_props['title'], 'Usuário inativo', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + '%s não está mais ativo na plataforma' %self.f_user.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_left_institution_notification(self): + """Test if the properties for LEFT_INSTITUTION + notification are the expected.""" + url = "/" + + notification_props = get_notification_props(NotificationType('LEFT_INSTITUTION'), self.f_user) + + self.assertEqual(notification_props['title'], 'Remoção de vínculo de membro', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + '%s removeu o vínculo com uma das instituições que você administra' %self.f_user.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_invite_notification(self): + """Test if the properties for INVITE + notification are the expected.""" + url = '%s/new_invite' %self.inst.key.urlsafe() + + notification_props = get_notification_props(NotificationType('INVITE'), self.inst) + + self.assertEqual(notification_props['title'], 'Novo convite', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'Você tem um novo convite', + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_deleted_institution_notification(self): + """Test if the properties for DELETED_INSTITUTION + notification are the expected.""" + url = "/" + + notification_props = get_notification_props(NotificationType('DELETED_INSTITUTION'), self.inst) + + self.assertEqual(notification_props['title'], 'Instituição removida', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'A instituição %s foi removida' %self.inst.name, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_deleted_event_notification(self): + """Test if the properties for DELETED_EVENT + notification are the expected.""" + url = "/" + + notification_props = get_notification_props(NotificationType('DELETED_EVENT'), self.event) + + self.assertEqual(notification_props['title'], 'Evento removido', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'O evento %s foi removido' %self.event.title, + "The notification's body_message wasn't the expected one") + self.assertEqual(notification_props['click_action'], url, + "The click_action wasn't the expected one") + + def test_updated_event_notification(self): + """Test if the properties for UPDATED_EVENT + notification are the expected.""" + url = '/event/%s/details' %self.event.key.urlsafe() + + notification_props = get_notification_props(NotificationType('UPDATED_EVENT'), self.event) + + self.assertEqual(notification_props['title'], 'Evento editado', + "The notification's title wasn't the expected one") + self.assertEqual(notification_props['body_message'], + 'O evento %s foi editado' %self.event.title, + "The notification's body_message wasn't the expected one") self.assertEqual(notification_props['click_action'], url, "The click_action wasn't the expected one") diff --git a/backend/worker.py b/backend/worker.py index c1f51e25c..1444922a8 100644 --- a/backend/worker.py +++ b/backend/worker.py @@ -256,35 +256,38 @@ def apply_remove_operation(remove_hierarchy, institution, user): apply_remove_operation(remove_hierarchy, institution, user) -class PostNotificationHandler(BaseHandler): +class MultipleNotificationHandler(BaseHandler): """Handler that sends post's notifications to another queue.""" def post(self): """Handle post requests.""" - post_author_key = self.request.get('receiver_key') + author_key = self.request.get('receiver_key') sender_url_key = self.request.get('sender_key') - post_key = self.request.get('entity_key') + entity_key = self.request.get('entity_key') entity_type = self.request.get('entity_type') current_institution_key = ndb.Key(urlsafe=self.request.get('current_institution')) sender_inst_key = self.request.get('sender_institution_key') and ndb.Key(urlsafe=self.request.get('sender_institution_key')) - post = ndb.Key(urlsafe=post_key).get() + field = self.request.get('field') + entity = ndb.Key(urlsafe=entity_key).get() + entity_title = self.request.get('title') or None - notification_message = post.create_notification_message( + notification_message = entity.create_notification_message( ndb.Key(urlsafe=sender_url_key), current_institution_key, sender_inst_key ) - subscribers = [subscriber.urlsafe() for subscriber in post.subscribers] + subscribers = [subscriber.urlsafe() for subscriber in entity[field]] - user_is_author = post_author_key == sender_url_key + user_is_author = author_key == sender_url_key for subscriber in subscribers: subscriber_is_sender = subscriber == sender_url_key if not (user_is_author and subscriber_is_sender) and not subscriber_is_sender: send_message_notification( receiver_key=subscriber, notification_type=entity_type, - entity_key=post_key, - message=notification_message + entity_key=entity_key, + message=notification_message, + entity={'key': entity_key, 'title': entity_title} ) @@ -505,7 +508,7 @@ def save_changes(admin, new_admin, institution): ('/api/queue/send-notification', SendNotificationHandler), ('/api/queue/send-email', SendEmailHandler), ('/api/queue/remove-inst', RemoveInstitutionHandler), - ('/api/queue/post-notification', PostNotificationHandler), + ('/api/queue/multiple-notification', MultipleNotificationHandler), ('/api/queue/email-members', EmailMembersHandler), ('/api/queue/notify-followers', NotifyFollowersHandler), ('/api/queue/add-admin-permissions', AddAdminPermissionsInInstitutionHierarchy), diff --git a/ecis b/ecis index 3de40ca3a..cb5902bc2 100755 --- a/ecis +++ b/ecis @@ -7,6 +7,9 @@ green=$(tput setaf 2) reset=$(tput sgr0) # ---------------------------- +# import generate_config_file and generate_config_file_with_urls functions +source generate_config.sh + SYS_URL='http://localhost:8080' APP_YAML=app.yaml @@ -14,21 +17,20 @@ FRONTEND_YAML=frontend/frontend.yaml 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 -LANDINGPAGE_LOCAL="localhost:8080" -FRONTEND_LOCAL="localhost:8081" -BACKEND_LOCAL="localhost:8082" -SUPPORT_LOCAL="localhost:8083" -WEBCHAT_LOCAL="localhost:8084" +config_files=( + "frontend/config.js" + "support/config.js" + "landing/config.js" + "feature-toggles/config.js" + "webchat/config.js" +); -FRONTEND_CONFIG_FILE="frontend/config.js" -SUPPORT_CONFIG_FILE="support/config.js" -LANDINGPAGE_CONFIG_FILE="landing/config.js" -WEBCHAT_CONFIG_FILE="webchat/config.js" SW_FILE="frontend/sw.js" -git update-index --skip-worktree $FRONTEND_CONFIG_FILE $SUPPORT_CONFIG_FILE $LANDINGPAGE_CONFIG_FILE $WEBCHAT_CONFIG_FILE +git update-index --skip-worktree ${config_files[@]} PY_ENV=backend/py_env @@ -58,87 +60,6 @@ function setup_app_version { catch_error $? "Setup APP VERSION with success" } -function set_service_url { - case "$1" in - local) - echo "http://$2"; - ;; - deploy) - echo "https://$2" - ;; - *) echo "inválid option"; exit 1; - ;; - esac -} - -function set_config_file { - line=$1; - service=$2; - url=$3; - service_name=$4; - - tmpfile=$(mktemp) - sed "$line s|.*| $service: '$url',|" $FRONTEND_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $FRONTEND_CONFIG_FILE - sed "$line s|.*| $service: '$url',|" $SUPPORT_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $SUPPORT_CONFIG_FILE - sed "$line s|.*| $service: '$url',|" $LANDINGPAGE_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $LANDINGPAGE_CONFIG_FILE - sed "$line s|.*| $service: '$url',|" $WEBCHAT_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $WEBCHAT_CONFIG_FILE - - catch_error $? "Frontend will use ${bold}$url${_bold} as $service_name." - catch_error $? "Support will use ${bold}$url${_bold} as $service_name." -} - -function set_backend_url { - url=$(set_service_url $1 $2); - service="BACKEND_URL"; - line=4; - service_name="backend"; - set_config_file $line $service $url $service_name; -} - -function set_landingpage_url { - url=$(set_service_url $1 $2); - service="LANDINGPAGE_URL"; - line=5; - service_name="landing page"; - set_config_file $line $service $url $service_name; -} - -function set_support_url { - url=$(set_service_url $1 $2); - service="SUPPORT_URL"; - line=6; - service_name="support"; - set_config_file $line $service $url $service_name; -} - -function set_frontend_url { - url=$(set_service_url $1 $2); - service="FRONTEND_URL"; - line=7; - service_name="frontend"; - set_config_file $line $service $url $service_name; -} - -function set_webchat_url { - url=$(set_service_url $1 $2); - service="WEBCHAT_URL"; - line=8; - service_name="webchat"; - set_config_file $line $service $url $service_name; -} - -function set_app_version_config { - tmpfile=$(mktemp) - sed "9s|.*| APP_VERSION: '$1'|" $FRONTEND_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $FRONTEND_CONFIG_FILE - catch_error $? "APP VERSION on Frontend $1" - sed "9s|.*| APP_VERSION: '$1'|" $SUPPORT_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $SUPPORT_CONFIG_FILE - catch_error $? "APP VERSION on Support $1" - sed "9s|.*| APP_VERSION: '$1'|" $LANDINGPAGE_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $LANDINGPAGE_CONFIG_FILE - catch_error $? "APP VERSION on LandingPage $1" - sed "9s|.*| APP_VERSION: '$1'|" $WEBCHAT_CONFIG_FILE > "$tmpfile" && mv "$tmpfile" $WEBCHAT_CONFIG_FILE - catch_error $? "APP VERSION on LandingPage $1" -} - function set_cache_suffix_sw { tmpfile=$(mktemp) sed "10s|.*| const CACHE_SUFIX = '$1';|" $SW_FILE > "$tmpfile" && mv "$tmpfile" $SW_FILE @@ -192,13 +113,13 @@ case "$1" in run) APP_VERSION=$(git branch | grep "*" | awk '{print $2}') set_cache_suffix_sw $APP_VERSION - set_app_version_config $APP_VERSION echo "=========== Cleaning Environment ===========" rm -rf $PY_ENV catch_error $? "Removed Pyenv Folder" rm -rf frontend/test/node_modules frontend/test/bower_components + rm -rf feature-toggles/test/node_modules feature-toggles/test/bower_components catch_error $? "Removed node_modules and bower_components" echo "=========== Starting Virtual Environment ===========" @@ -225,11 +146,7 @@ case "$1" in setup_firebase_config development - set_backend_url local $BACKEND_LOCAL - set_landingpage_url local $LANDINGPAGE_LOCAL - set_support_url local $SUPPORT_LOCAL - set_frontend_url local $FRONTEND_LOCAL - set_webchat_url local $WEBCHAT_LOCAL + generate_config_file local $APP_VERSION ${config_files[@]} if [[ -n $2 ]] && [ $2 = "--enable_datastore_emulator" ] ; then gcloud beta emulators datastore start --host-port=0.0.0.0:8586 & @@ -241,7 +158,7 @@ case "$1" in fi $(gcloud beta emulators datastore env-init) - dev_appserver.py $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $WEBCHAT_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) ;; @@ -254,7 +171,7 @@ case "$1" in if [ "$3" == "--clean" ]; then rm -rf node_modules bower_components fi - + if [ ! -e node_modules ]; then yarn add package.json catch_error $? "Node modules installed with success" @@ -279,7 +196,7 @@ case "$1" in echo "=========== Starting Backend Tests ===========" source $PY_ENV/bin/activate setup_app_version "master" - + cd backend echo 'FIREBASE_URL = "FIREBASE_URL"' > firebase_config.py echo 'SERVER_KEY = "SERVER_KEY"' >> firebase_config.py @@ -289,6 +206,25 @@ case "$1" in TEST_NAME=$4 fi python -m unittest discover -v -p $TEST_NAME + ;; + feature) + echo "=========== Starting Feature Toggles Tests Setup ===========" + cd feature-toggles/test + + if [ "$3" == "--clean" ]; then + rm -rf node_modules bower_components + fi + + if [ ! -e node_modules ]; then + yarn + catch_error $? "Node modules installed with success" + else + log_message "Node modules already installed" + fi + + echo "=========== Starting to run Feature Toggles Tests ===========" + karma start --single-run + ;; esac ;; @@ -302,7 +238,6 @@ case "$1" in catch_error $? "Git checked out to tag $APP_VERSION" set_cache_suffix_sw $APP_VERSION - set_app_version_config $APP_VERSION echo "${bold}>> Select the application to deploy:${_bold}" options=("development-cis" "eciis-splab" "Other") @@ -310,15 +245,19 @@ case "$1" in do case $opt in "development-cis") + ENV="dev" APP_NAME="development-cis" SUPPORT_DOMAIN="support-dot-$APP_NAME.appspot.com" FRONTEND_DOMAIN="frontend-dot-$APP_NAME.appspot.com" + FEATURE_DOMAIN="feature-dot-$APP_NAME.appspot.com" break ;; "eciis-splab") + ENV="prod" APP_NAME="eciis-splab" SUPPORT_DOMAIN="support.plataformacis.org" FRONTEND_DOMAIN="frontend.plataformacis.org" + FEATURE_DOMAIN="feature.plataformacis.org" break ;; "Other") @@ -345,9 +284,9 @@ case "$1" in DOMAIN="$APP_NAME.appspot.com" BACKEND_DOMAIN="backend-dot-$DOMAIN" - + ENVIRONMENT="development" - read -p "${bold}Choose which environment to use: (development) ${_bold} " NEW_ENVIRONMENT + read -p "${bold}Choose which environment to use: (development) ${_bold} " NEW_ENVIRONMENT if [ "$NEW_ENVIRONMENT" != "" ]; then ENVIRONMENT=$NEW_ENVIRONMENT fi @@ -360,29 +299,23 @@ case "$1" in if [ ! -z $2 ]; then version=$2 - url=$version"."$BACKEND_DOMAIN - set_backend_url deploy $url - - url=$version"."$DOMAIN - set_landingpage_url deploy $url - - url=$version"."$SUPPORT_DOMAIN - set_support_url deploy $url - - url=$version"."$FRONTEND_DOMAIN - set_frontend_url deploy $url - + urls=( + $version"."$BACKEND_DOMAIN + $version"."$DOMAIN + $version"."$SUPPORT_DOMAIN + $version"."$FRONTEND_DOMAIN + $version"."$FEATURE_DOMAIN + ) + + generate_config_file_with_urls $APP_VERSION ${urls[@]} ${config_files[@]} 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 $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 - set_backend_url deploy $BACKEND_DOMAIN - set_landingpage_url deploy $DOMAIN - set_support_url deploy $SUPPORT_DOMAIN - set_frontend_url deploy $FRONTEND_DOMAIN - gcloud app deploy $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $WORKER_YAML + generate_config_file $ENV $APP_VERSION ${config_files[@]} + gcloud app deploy $APP_YAML $FRONTEND_YAML $BACKEND_YAML $SUPPORT_YAML $FEATURE_YAML $WEBCHAT_YAML $WORKER_YAML fi exit 0 diff --git a/feature-toggles/app.js b/feature-toggles/app.js new file mode 100644 index 000000000..6c67001be --- /dev/null +++ b/feature-toggles/app.js @@ -0,0 +1,113 @@ +(function() { + 'use strict'; + + const app = angular.module('app', [ + 'ngMaterial', + 'ui.router', + 'ngAnimate', + 'ngMessages', + ]); + + + app.config(function($mdIconProvider, $mdThemingProvider, $urlMatcherFactoryProvider, $urlRouterProvider, + $locationProvider, $stateProvider, $httpProvider, STATES) { + + $mdIconProvider.fontSet('md', 'material-icons'); + $mdThemingProvider.theme('docs-dark'); + $mdThemingProvider.theme('input') + .primaryPalette('green'); + $mdThemingProvider.theme('dialogTheme') + .primaryPalette('teal'); + + $urlMatcherFactoryProvider.caseInsensitive(true); + + $stateProvider + .state(STATES.SIGNIN, { + url: "/signin", + views: { + main: { + templateUrl: "app/auth/login.html", + controller: "LoginController as loginCtrl" + } + } + }).state(STATES.MANAGE_FEATURES, { + url: "/", + views: { + main: { + templateUrl: "app/manage/manage-toggles.html", + controller: "ManageTogglesController as manageTogglesCtrl" + } + } + }); + + $urlRouterProvider.otherwise("/"); + + $locationProvider.html5Mode(true); + $httpProvider.interceptors.push('BearerAuthInterceptor'); + + }); + + app.factory('BearerAuthInterceptor', function ($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); + }, + 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("singin"); + } + } else if(rejection.status === 403) { + rejection.data.msg = "Você não tem permissão para realizar esta operação!"; + } else { + $state.go("error", { + "msg": rejection.data.msg || "Desculpa! Ocorreu um erro.", + "status": rejection.status + }); + } + return $q.reject(rejection); + } + }; + }); + + /** + * Auth interceptor to check if the usr is logged in, if not, redirect to login page. + */ + app.run(function authInterceptor(AuthService, STATES, $transitions) { + const ignored_routes = [ + STATES.SIGNIN + ]; + + $transitions.onBefore({ + to: function(state) { + return !(_.includes(ignored_routes, state.name)) && !AuthService.isLoggedIn(); + } + }, function(transition) { + return transition.router.stateService.target(STATES.SIGNIN); + }); + }); +})(); \ No newline at end of file diff --git a/feature-toggles/auth/authService.js b/feature-toggles/auth/authService.js new file mode 100644 index 000000000..681b16f9b --- /dev/null +++ b/feature-toggles/auth/authService.js @@ -0,0 +1,182 @@ +(function() { + 'use strict'; + + const app = angular.module("app"); + + app.service("AuthService", function AuthService($state, $window, UserService, UserFactory, MessageService, STATES) { + const service = this; + + const authObj = firebase.auth(); + let userInfo; + let tokenLoaded = false; + service.resolveTokenPromise; + let loadTokenPromise; + let refreshInterval; + const provider = new firebase.auth.GoogleAuthProvider(); + + /** + * Function to get token of logged user. + * If the first token has not yet been loaded, it returns a promise + * that will be resolved as soon as the token is loaded. + * If the token has already been loaded, it returns the token. + */ + service.getUserToken = async () => { + if (!tokenLoaded && !loadTokenPromise) { + loadTokenPromise = new Promise((resolve) => { + service.resolveTokenPromise = resolve; + }); + } else if (tokenLoaded) { + return userInfo.accessToken; + } + + return loadTokenPromise; + }; + + /** + * Function to get token id of user and update object userInfo + * @param {firebaseUser} user + */ + service._getIdToken = function getIdToken(user) { + const resolvePromise = token => { + if (service.resolveTokenPromise) { + service.resolveTokenPromise(token); + service.resolveTokenPromise = null; + } + + tokenLoaded = true; + }; + + return user.getIdToken(true).then(function(userToken) { + if (userInfo) { + userInfo.accessToken = userToken; + service.save(); + } + + resolvePromise(userToken); + return userToken; + }).catch(() => { + resolvePromise(userInfo.accessToken); + return userInfo.accessToken; + }); + } + + authObj.onAuthStateChanged(function(user) { + const timeToRefresh = 3500000; + if (user) { + service._getIdToken(user); + refreshInterval = setInterval(() => { + service._getIdToken(user); + }, timeToRefresh); + } + }); + + /** + * Store listeners to be executed when user logout is called. + */ + var onLogoutListeners = []; + + Object.defineProperty(service, 'user', { + get: function() { + return userInfo; + } + }); + + service.setupUser = function setupUser(idToken, emailVerified) { + var firebaseUser = { + accessToken : idToken, + emailVerified: emailVerified + }; + + userInfo = firebaseUser; + + return UserService.load().then(function success(userLoaded) { + configUser(userLoaded, firebaseUser); + return userInfo; + }); + }; + + function login(loginMethodPromisse) { + service.isLoadingUser = true; + return authObj.setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(function() { + return loginMethodPromisse.then(function(response) { + return response.user; + }); + }).then(function(user) { + return user.getIdToken(true).then(function(idToken) { + return service.setupUser(idToken, user.emailVerified).then(function success(userInfo) { + return userInfo; + }); + }); + }).finally(() => { + service.isLoadingUser = false; + if (!userInfo.hasPermission('analyze_request_inst')) { + service.logout(); + MessageService.showErrorToast("Você não possui permissão para acessar esta página."); + } + }); + } + + service.loginWithGoogle = function loginWithGoogle() { + return login(authObj.signInWithPopup(provider)); + }; + + service.loginWithEmailAndPassword = function loginWithEmailAndPassword(email, password) { + return login(authObj.signInWithEmailAndPassword(email, password)); + }; + + service.logout = function logout() { + authObj.signOut(); + delete $window.localStorage.userInfo; + userInfo = undefined; + clearInterval(refreshInterval); + + executeLogoutListeners(); + + $state.go(STATES.SIGNIN); + }; + + service.getCurrentUser = function getCurrentUser() { + return userInfo; + }; + + service.isLoggedIn = function isLoggedIn() { + if (userInfo) { + return true; + } + return false; + }; + + service.save = function() { + $window.localStorage.userInfo = JSON.stringify(userInfo); + }; + + service.$onLogout = function $onLogout(callback) { + onLogoutListeners.push(callback); + }; + + /** + * Execute each function stored to be thriggered when user logout + * is called. + */ + function executeLogoutListeners() { + _.each(onLogoutListeners, function(callback) { + callback(); + }); + } + + function configUser(userLoaded, firebaseUser) { + userInfo = new UserFactory.user(userLoaded); + _.extend(userInfo, firebaseUser); + $window.localStorage.userInfo = JSON.stringify(userInfo); + } + + function init() { + if ($window.localStorage.userInfo) { + var parse = JSON.parse($window.localStorage.userInfo); + userInfo = new UserFactory.user(parse); + } + } + + init(); + }); +})(); \ No newline at end of file diff --git a/feature-toggles/auth/login.css b/feature-toggles/auth/login.css new file mode 100644 index 000000000..aa4682dd5 --- /dev/null +++ b/feature-toggles/auth/login.css @@ -0,0 +1,113 @@ +.login-btn { + margin: 0 0 1em auto; + width: 100%; +} + +.login-btn md-icon { + color: white; + margin-right: 0.5em; + text-align: center; +} + +#login-invite-icon { + font-size: 1.3em; + line-height: 24px; + margin-left: 0.3em; +} + +#login-google-icon { + margin-left: 0.5em; +} + +#login-google-icon svg { + height: auto; + width: 1.3em; + line-height: auto; + margin: 0.155em 0.2em; +} + +.login-text { + margin-top: 4px; + text-align: justify; +} + +.login-form { + width: 100%; + margin: 1em 0; +} + +.login-card { + box-shadow: 0 1px 3px 0 rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12); + background-color: white; +} + +.login-card-content { + display: grid; + justify-items: center; + margin: 0; + width: 100%; +} + +.login-content { + height: 100%; + width: 100%; + display: grid; + overflow: auto; +} + +#login-container { + display: grid; + padding: 8px; + justify-content: center; + align-content: center; + color: black; +} + +#form-content { + padding: 0 35px; +} + +.custom-card-logo { + margin: 1em; + width: 90%; +} + +.custom-card-back-btn { + margin: 0 -2.5em 0 0; +} + +@media screen and (max-width: 599px) { + #login-logo { + width: 50%; + margin: 1em 1em 7px 1em; + } + + #login-container { + grid-template-columns: 100%; + } + + #form-content { + padding: 0 16px; + } +} + +@media screen and (min-width: 600px) and (max-width: 1024px) { + #login-container { + grid-template-columns: 29px 65%; + align-items: center; + } +} + +@media screen and (min-width: 1025px) and (max-width: 1366px) { + #login-container { + grid-template-columns: 29px 35%; + align-items: center; + } +} + +@media screen and (min-width: 1367px) { + #login-container { + grid-template-columns: 29px 30%; + align-items: center; + } +} diff --git a/feature-toggles/auth/login.html b/feature-toggles/auth/login.html new file mode 100644 index 000000000..78bc20069 --- /dev/null +++ b/feature-toggles/auth/login.html @@ -0,0 +1,41 @@ +
+
+ + keyboard_arrow_left + + + +
+
\ No newline at end of file diff --git a/feature-toggles/auth/loginController.js b/feature-toggles/auth/loginController.js new file mode 100644 index 000000000..4ff8afe18 --- /dev/null +++ b/feature-toggles/auth/loginController.js @@ -0,0 +1,64 @@ +(function() { + 'use strict'; + const app = angular.module('app'); + + app.controller('LoginController', function(AuthService, $state, + $stateParams, $window, MessageService, STATES) { + const loginCtrl = this; + + loginCtrl.user = {}; + + loginCtrl.isRequestInvite = false; + + var redirectPath = $stateParams.redirect; + + loginCtrl.loginWithGoogle = function loginWithGoogle() { + return AuthService.loginWithGoogle().then(function success() { + loginCtrl._redirectTo(redirectPath); + }).catch(function(error) { + MessageService.showErrorToast(error); + }); + }; + + /** + * Verify if the Auth Service is loading User. + * @returns {boolean} True if it is loading user, false if not. + */ + loginCtrl.isLoadingUser = function () { + return AuthService.isLoadingUser; + }; + + + loginCtrl.loginWithEmailPassword = function loginWithEmailPassword() { + return AuthService.loginWithEmailAndPassword(loginCtrl.user.email, loginCtrl.user.password).then( + function success() { + loginCtrl._redirectTo(redirectPath); + } + ).catch(function(error) { + MessageService.showErrorToast(error); + }); + }; + + loginCtrl.redirect = function success() { + loginCtrl._redirectTo(redirectPath); + }; + + loginCtrl.goToLandingPage = function goToLandingPage() { + $window.open(Config.LANDINGPAGE_URL, '_self'); + }; + + loginCtrl._redirectTo = function redirectTo(path) { + if (path) { + window.location.pathname = path; + } else { + $state.go(STATES.MANAGE_FEATURES); + } + } + + loginCtrl.$onInit = function main() { + if (AuthService.isLoggedIn()) { + $state.go(STATES.MANAGE_FEATURES); + } + }; + }); +})(); \ No newline at end of file diff --git a/feature-toggles/config.js b/feature-toggles/config.js new file mode 100644 index 000000000..336ccee67 --- /dev/null +++ b/feature-toggles/config.js @@ -0,0 +1,10 @@ +"use strict"; + +var Config = { + BACKEND_URL: 'http://localhost:8082', + LANDINGPAGE_URL: 'http://localhost:8080', + SUPPORT_URL: 'http://localhost:8083', + FEATURE_URL: 'http://localhost:8081', + FEATURE_URL: 'http://localhost:8083', + APP_VERSION: 'create-feature-toggles-service' +}; diff --git a/feature-toggles/favicon.ico b/feature-toggles/favicon.ico new file mode 100644 index 000000000..1d395073d Binary files /dev/null and b/feature-toggles/favicon.ico differ diff --git a/feature-toggles/feature.yaml b/feature-toggles/feature.yaml new file mode 100644 index 000000000..813fcd904 --- /dev/null +++ b/feature-toggles/feature.yaml @@ -0,0 +1,17 @@ +runtime: python27 +api_version: 1 +threadsafe: yes +service: feature + +default_expiration: "1s" + +handlers: +- url: /app/(.*) + secure: always + static_files: \1 + upload: (.*) + +- url: /(.*) + secure: always + static_files: index.html + upload: index.html \ No newline at end of file diff --git a/feature-toggles/firebase-config.js b/feature-toggles/firebase-config.js new file mode 100644 index 000000000..b96d245b5 --- /dev/null +++ b/feature-toggles/firebase-config.js @@ -0,0 +1,8 @@ +var FIREBASE_CONFIG = { + apiKey: "AIzaSyBlpZudOyqMsSDIkZcPMmLCBxY5DWkoz14", + authDomain: "development-cis.firebaseapp.com", + databaseURL: "https://development-cis.firebaseio.com", + projectId: "development-cis", + storageBucket: "development-cis.appspot.com", + messagingSenderId: "531467954503" +}; diff --git a/feature-toggles/icons/google-icon.svg b/feature-toggles/icons/google-icon.svg new file mode 100644 index 000000000..800402771 --- /dev/null +++ b/feature-toggles/icons/google-icon.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/feature-toggles/images/logo.png b/feature-toggles/images/logo.png new file mode 100644 index 000000000..24e5bcf1f Binary files /dev/null and b/feature-toggles/images/logo.png differ diff --git a/feature-toggles/images/logowithname.png b/feature-toggles/images/logowithname.png new file mode 100644 index 000000000..f27b23071 Binary files /dev/null and b/feature-toggles/images/logowithname.png differ diff --git a/feature-toggles/index.html b/feature-toggles/index.html new file mode 100644 index 000000000..b0b893bde --- /dev/null +++ b/feature-toggles/index.html @@ -0,0 +1,75 @@ + + + + + + + + Plataforma CIS + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature-toggles/libs/angular-ui-router.js b/feature-toggles/libs/angular-ui-router.js new file mode 100644 index 000000000..4e69b5e20 --- /dev/null +++ b/feature-toggles/libs/angular-ui-router.js @@ -0,0 +1,10075 @@ +/** + * State-based routing for AngularJS 1.x + * NOTICE: This monolithic bundle also bundles the @uirouter/core code. + * This causes it to be incompatible with plugins that depend on @uirouter/core. + * We recommend switching to the ui-router-core.js and ui-router-angularjs.js bundles instead. + * For more information, see https://ui-router.github.io/blog/uirouter-for-angularjs-umd-bundles + * @version v1.0.10 + * @link https://ui-router.github.io + * @license MIT License, http://www.opensource.org/licenses/MIT + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('angular')) : + typeof define === 'function' && define.amd ? define(['exports', 'angular'], factory) : + (factory((global['@uirouter/angularjs'] = {}),global.angular)); +}(this, (function (exports,ng_from_import) { 'use strict'; + +var ng_from_global = angular; +var ng = (ng_from_import && ng_from_import.module) ? ng_from_import : ng_from_global; + +/** + * Higher order functions + * + * These utility functions are exported, but are subject to change without notice. + * + * @module common_hof + */ /** */ +/** + * Returns a new function for [Partial Application](https://en.wikipedia.org/wiki/Partial_application) of the original function. + * + * Given a function with N parameters, returns a new function that supports partial application. + * The new function accepts anywhere from 1 to N parameters. When that function is called with M parameters, + * where M is less than N, it returns a new function that accepts the remaining parameters. It continues to + * accept more parameters until all N parameters have been supplied. + * + * + * This contrived example uses a partially applied function as an predicate, which returns true + * if an object is found in both arrays. + * @example + * ``` + * // returns true if an object is in both of the two arrays + * function inBoth(array1, array2, object) { + * return array1.indexOf(object) !== -1 && + * array2.indexOf(object) !== 1; + * } + * let obj1, obj2, obj3, obj4, obj5, obj6, obj7 + * let foos = [obj1, obj3] + * let bars = [obj3, obj4, obj5] + * + * // A curried "copy" of inBoth + * let curriedInBoth = curry(inBoth); + * // Partially apply both the array1 and array2 + * let inFoosAndBars = curriedInBoth(foos, bars); + * + * // Supply the final argument; since all arguments are + * // supplied, the original inBoth function is then called. + * let obj1InBoth = inFoosAndBars(obj1); // false + * + * // Use the inFoosAndBars as a predicate. + * // Filter, on each iteration, supplies the final argument + * let allObjs = [ obj1, obj2, obj3, obj4, obj5, obj6, obj7 ]; + * let foundInBoth = allObjs.filter(inFoosAndBars); // [ obj3 ] + * + * ``` + * + * Stolen from: http://stackoverflow.com/questions/4394747/javascript-curry-function + * + * @param fn + * @returns {*|function(): (*|any)} + */ +function curry(fn) { + var initial_args = [].slice.apply(arguments, [1]); + var func_args_length = fn.length; + function curried(args) { + if (args.length >= func_args_length) + return fn.apply(null, args); + return function () { + return curried(args.concat([].slice.apply(arguments))); + }; + } + return curried(initial_args); +} +/** + * Given a varargs list of functions, returns a function that composes the argument functions, right-to-left + * given: f(x), g(x), h(x) + * let composed = compose(f,g,h) + * then, composed is: f(g(h(x))) + */ +function compose() { + var args = arguments; + var start = args.length - 1; + return function () { + var i = start, result = args[start].apply(this, arguments); + while (i--) + result = args[i].call(this, result); + return result; + }; +} +/** + * Given a varargs list of functions, returns a function that is composes the argument functions, left-to-right + * given: f(x), g(x), h(x) + * let piped = pipe(f,g,h); + * then, piped is: h(g(f(x))) + */ +function pipe() { + var funcs = []; + for (var _i = 0; _i < arguments.length; _i++) { + funcs[_i] = arguments[_i]; + } + return compose.apply(null, [].slice.call(arguments).reverse()); +} +/** + * Given a property name, returns a function that returns that property from an object + * let obj = { foo: 1, name: "blarg" }; + * let getName = prop("name"); + * getName(obj) === "blarg" + */ +var prop = function (name) { + return function (obj) { return obj && obj[name]; }; +}; +/** + * Given a property name and a value, returns a function that returns a boolean based on whether + * the passed object has a property that matches the value + * let obj = { foo: 1, name: "blarg" }; + * let getName = propEq("name", "blarg"); + * getName(obj) === true + */ +var propEq = curry(function (name, val, obj) { return obj && obj[name] === val; }); +/** + * Given a dotted property name, returns a function that returns a nested property from an object, or undefined + * let obj = { id: 1, nestedObj: { foo: 1, name: "blarg" }, }; + * let getName = prop("nestedObj.name"); + * getName(obj) === "blarg" + * let propNotFound = prop("this.property.doesnt.exist"); + * propNotFound(obj) === undefined + */ +var parse = function (name) { + return pipe.apply(null, name.split(".").map(prop)); +}; +/** + * Given a function that returns a truthy or falsey value, returns a + * function that returns the opposite (falsey or truthy) value given the same inputs + */ +var not = function (fn) { + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return !fn.apply(null, args); + }; +}; +/** + * Given two functions that return truthy or falsey values, returns a function that returns truthy + * if both functions return truthy for the given arguments + */ +function and(fn1, fn2) { + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return fn1.apply(null, args) && fn2.apply(null, args); + }; +} +/** + * Given two functions that return truthy or falsey values, returns a function that returns truthy + * if at least one of the functions returns truthy for the given arguments + */ +function or(fn1, fn2) { + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return fn1.apply(null, args) || fn2.apply(null, args); + }; +} +/** + * Check if all the elements of an array match a predicate function + * + * @param fn1 a predicate function `fn1` + * @returns a function which takes an array and returns true if `fn1` is true for all elements of the array + */ +var all = function (fn1) { + return function (arr) { return arr.reduce(function (b, x) { return b && !!fn1(x); }, true); }; +}; +var any = function (fn1) { + return function (arr) { return arr.reduce(function (b, x) { return b || !!fn1(x); }, false); }; +}; +/** Given a class, returns a Predicate function that returns true if the object is of that class */ +var is = function (ctor) { + return function (obj) { + return (obj != null && obj.constructor === ctor || obj instanceof ctor); + }; +}; +/** Given a value, returns a Predicate function that returns true if another value is === equal to the original value */ +var eq = function (val) { return function (other) { + return val === other; +}; }; +/** Given a value, returns a function which returns the value */ +var val = function (v) { return function () { return v; }; }; +function invoke(fnName, args) { + return function (obj) { + return obj[fnName].apply(obj, args); + }; +} +/** + * Sorta like Pattern Matching (a functional programming conditional construct) + * + * See http://c2.com/cgi/wiki?PatternMatching + * + * This is a conditional construct which allows a series of predicates and output functions + * to be checked and then applied. Each predicate receives the input. If the predicate + * returns truthy, then its matching output function (mapping function) is provided with + * the input and, then the result is returned. + * + * Each combination (2-tuple) of predicate + output function should be placed in an array + * of size 2: [ predicate, mapFn ] + * + * These 2-tuples should be put in an outer array. + * + * @example + * ``` + * + * // Here's a 2-tuple where the first element is the isString predicate + * // and the second element is a function that returns a description of the input + * let firstTuple = [ angular.isString, (input) => `Heres your string ${input}` ]; + * + * // Second tuple: predicate "isNumber", mapfn returns a description + * let secondTuple = [ angular.isNumber, (input) => `(${input}) That's a number!` ]; + * + * let third = [ (input) => input === null, (input) => `Oh, null...` ]; + * + * let fourth = [ (input) => input === undefined, (input) => `notdefined` ]; + * + * let descriptionOf = pattern([ firstTuple, secondTuple, third, fourth ]); + * + * console.log(descriptionOf(undefined)); // 'notdefined' + * console.log(descriptionOf(55)); // '(55) That's a number!' + * console.log(descriptionOf("foo")); // 'Here's your string foo' + * ``` + * + * @param struct A 2D array. Each element of the array should be an array, a 2-tuple, + * with a Predicate and a mapping/output function + * @returns {function(any): *} + */ +function pattern(struct) { + return function (x) { + for (var i = 0; i < struct.length; i++) { + if (struct[i][0](x)) + return struct[i][1](x); + } + }; +} + +/** + * @coreapi + * @module core + */ +/** + * Matches state names using glob-like pattern strings. + * + * Globs can be used in specific APIs including: + * + * - [[StateService.is]] + * - [[StateService.includes]] + * - The first argument to Hook Registration functions like [[TransitionService.onStart]] + * - [[HookMatchCriteria]] and [[HookMatchCriterion]] + * + * A `Glob` string is a pattern which matches state names. + * Nested state names are split into segments (separated by a dot) when processing. + * The state named `foo.bar.baz` is split into three segments ['foo', 'bar', 'baz'] + * + * Globs work according to the following rules: + * + * ### Exact match: + * + * The glob `'A.B'` matches the state named exactly `'A.B'`. + * + * | Glob |Matches states named|Does not match state named| + * |:------------|:--------------------|:---------------------| + * | `'A'` | `'A'` | `'B'` , `'A.C'` | + * | `'A.B'` | `'A.B'` | `'A'` , `'A.B.C'` | + * | `'foo'` | `'foo'` | `'FOO'` , `'foo.bar'`| + * + * ### Single star (`*`) + * + * A single star (`*`) is a wildcard that matches exactly one segment. + * + * | Glob |Matches states named |Does not match state named | + * |:------------|:---------------------|:--------------------------| + * | `'*'` | `'A'` , `'Z'` | `'A.B'` , `'Z.Y.X'` | + * | `'A.*'` | `'A.B'` , `'A.C'` | `'A'` , `'A.B.C'` | + * | `'A.*.*'` | `'A.B.C'` , `'A.X.Y'`| `'A'`, `'A.B'` , `'Z.Y.X'`| + * + * ### Double star (`**`) + * + * A double star (`'**'`) is a wildcard that matches *zero or more segments* + * + * | Glob |Matches states named |Does not match state named | + * |:------------|:----------------------------------------------|:----------------------------------| + * | `'**'` | `'A'` , `'A.B'`, `'Z.Y.X'` | (matches all states) | + * | `'A.**'` | `'A'` , `'A.B'` , `'A.C.X'` | `'Z.Y.X'` | + * | `'**.X'` | `'X'` , `'A.X'` , `'Z.Y.X'` | `'A'` , `'A.login.Z'` | + * | `'A.**.X'` | `'A.X'` , `'A.B.X'` , `'A.B.C.X'` | `'A'` , `'A.B.C'` | + * + */ +var Glob = /** @class */ (function () { + function Glob(text) { + this.text = text; + this.glob = text.split('.'); + var regexpString = this.text.split('.') + .map(function (seg) { + if (seg === '**') + return '(?:|(?:\\.[^.]*)*)'; + if (seg === '*') + return '\\.[^.]*'; + return '\\.' + seg; + }).join(''); + this.regexp = new RegExp("^" + regexpString + "$"); + } + Glob.prototype.matches = function (name) { + return this.regexp.test('.' + name); + }; + /** Returns true if the string has glob-like characters in it */ + Glob.is = function (text) { + return !!/[!,*]+/.exec(text); + }; + /** Returns a glob from the string, or null if the string isn't Glob-like */ + Glob.fromString = function (text) { + return Glob.is(text) ? new Glob(text) : null; + }; + return Glob; +}()); + +/** + * Internal representation of a UI-Router state. + * + * Instances of this class are created when a [[StateDeclaration]] is registered with the [[StateRegistry]]. + * + * A registered [[StateDeclaration]] is augmented with a getter ([[StateDeclaration.$$state]]) which returns the corresponding [[StateObject]] object. + * + * This class prototypally inherits from the corresponding [[StateDeclaration]]. + * Each of its own properties (i.e., `hasOwnProperty`) are built using builders from the [[StateBuilder]]. + */ +var StateObject = /** @class */ (function () { + /** @deprecated use State.create() */ + function StateObject(config) { + return StateObject.create(config || {}); + } + /** + * Create a state object to put the private/internal implementation details onto. + * The object's prototype chain looks like: + * (Internal State Object) -> (Copy of State.prototype) -> (State Declaration object) -> (State Declaration's prototype...) + * + * @param stateDecl the user-supplied State Declaration + * @returns {StateObject} an internal State object + */ + StateObject.create = function (stateDecl) { + stateDecl = StateObject.isStateClass(stateDecl) ? new stateDecl() : stateDecl; + var state = inherit(inherit(stateDecl, StateObject.prototype)); + stateDecl.$$state = function () { return state; }; + state.self = stateDecl; + state.__stateObjectCache = { + nameGlob: Glob.fromString(state.name) // might return null + }; + return state; + }; + /** + * Returns true if the provided parameter is the same state. + * + * Compares the identity of the state against the passed value, which is either an object + * reference to the actual `State` instance, the original definition object passed to + * `$stateProvider.state()`, or the fully-qualified name. + * + * @param ref Can be one of (a) a `State` instance, (b) an object that was passed + * into `$stateProvider.state()`, (c) the fully-qualified name of a state as a string. + * @returns Returns `true` if `ref` matches the current `State` instance. + */ + StateObject.prototype.is = function (ref) { + return this === ref || this.self === ref || this.fqn() === ref; + }; + /** + * @deprecated this does not properly handle dot notation + * @returns Returns a dot-separated name of the state. + */ + StateObject.prototype.fqn = function () { + if (!this.parent || !(this.parent instanceof this.constructor)) + return this.name; + var name = this.parent.fqn(); + return name ? name + "." + this.name : this.name; + }; + /** + * Returns the root node of this state's tree. + * + * @returns The root of this state's tree. + */ + StateObject.prototype.root = function () { + return this.parent && this.parent.root() || this; + }; + /** + * Gets the state's `Param` objects + * + * Gets the list of [[Param]] objects owned by the state. + * If `opts.inherit` is true, it also includes the ancestor states' [[Param]] objects. + * If `opts.matchingKeys` exists, returns only `Param`s whose `id` is a key on the `matchingKeys` object + * + * @param opts options + */ + StateObject.prototype.parameters = function (opts) { + opts = defaults(opts, { inherit: true, matchingKeys: null }); + var inherited = opts.inherit && this.parent && this.parent.parameters() || []; + return inherited.concat(values(this.params)) + .filter(function (param) { return !opts.matchingKeys || opts.matchingKeys.hasOwnProperty(param.id); }); + }; + /** + * Returns a single [[Param]] that is owned by the state + * + * If `opts.inherit` is true, it also searches the ancestor states` [[Param]]s. + * @param id the name of the [[Param]] to return + * @param opts options + */ + StateObject.prototype.parameter = function (id, opts) { + if (opts === void 0) { opts = {}; } + return (this.url && this.url.parameter(id, opts) || + find(values(this.params), propEq('id', id)) || + opts.inherit && this.parent && this.parent.parameter(id)); + }; + StateObject.prototype.toString = function () { + return this.fqn(); + }; + /** Predicate which returns true if the object is an class with @State() decorator */ + StateObject.isStateClass = function (stateDecl) { + return isFunction(stateDecl) && stateDecl['__uiRouterState'] === true; + }; + /** Predicate which returns true if the object is an internal [[StateObject]] object */ + StateObject.isState = function (obj) { + return isObject(obj['__stateObjectCache']); + }; + return StateObject; +}()); + +/** Predicates + * + * These predicates return true/false based on the input. + * Although these functions are exported, they are subject to change without notice. + * + * @module common_predicates + */ +/** */ +var toStr = Object.prototype.toString; +var tis = function (t) { return function (x) { return typeof (x) === t; }; }; +var isUndefined = tis('undefined'); +var isDefined = not(isUndefined); +var isNull = function (o) { return o === null; }; +var isNullOrUndefined = or(isNull, isUndefined); +var isFunction = tis('function'); +var isNumber = tis('number'); +var isString = tis('string'); +var isObject = function (x) { return x !== null && typeof x === 'object'; }; +var isArray = Array.isArray; +var isDate = (function (x) { return toStr.call(x) === '[object Date]'; }); +var isRegExp = (function (x) { return toStr.call(x) === '[object RegExp]'; }); +var isState = StateObject.isState; +/** + * Predicate which checks if a value is injectable + * + * A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array + * where all the elements in the array are Strings, except the last one, which is a Function + */ +function isInjectable(val$$1) { + if (isArray(val$$1) && val$$1.length) { + var head = val$$1.slice(0, -1), tail = val$$1.slice(-1); + return !(head.filter(not(isString)).length || tail.filter(not(isFunction)).length); + } + return isFunction(val$$1); +} +/** + * Predicate which checks if a value looks like a Promise + * + * It is probably a Promise if it's an object, and it has a `then` property which is a Function + */ +var isPromise = and(isObject, pipe(prop('then'), isFunction)); + +var notImplemented = function (fnname) { return function () { + throw new Error(fnname + "(): No coreservices implementation for UI-Router is loaded."); +}; }; +var services = { + $q: undefined, + $injector: undefined, +}; + +/** + * Random utility functions used in the UI-Router code + * + * These functions are exported, but are subject to change without notice. + * + * @preferred + * @module common + */ +/** for typedoc */ +var root = (typeof self === 'object' && self.self === self && self) || + (typeof global === 'object' && global.global === global && global) || undefined; +var angular$1 = root.angular || {}; +var fromJson = angular$1.fromJson || JSON.parse.bind(JSON); +var toJson = angular$1.toJson || JSON.stringify.bind(JSON); +var forEach = angular$1.forEach || _forEach; +var extend = Object.assign || _extend; +var equals = angular$1.equals || _equals; +function identity(x) { return x; } +function noop$1() { } +/** + * Builds proxy functions on the `to` object which pass through to the `from` object. + * + * For each key in `fnNames`, creates a proxy function on the `to` object. + * The proxy function calls the real function on the `from` object. + * + * + * #### Example: + * This example creates an new class instance whose functions are prebound to the new'd object. + * ```js + * class Foo { + * constructor(data) { + * // Binds all functions from Foo.prototype to 'this', + * // then copies them to 'this' + * bindFunctions(Foo.prototype, this, this); + * this.data = data; + * } + * + * log() { + * console.log(this.data); + * } + * } + * + * let myFoo = new Foo([1,2,3]); + * var logit = myFoo.log; + * logit(); // logs [1, 2, 3] from the myFoo 'this' instance + * ``` + * + * #### Example: + * This example creates a bound version of a service function, and copies it to another object + * ``` + * + * var SomeService = { + * this.data = [3, 4, 5]; + * this.log = function() { + * console.log(this.data); + * } + * } + * + * // Constructor fn + * function OtherThing() { + * // Binds all functions from SomeService to SomeService, + * // then copies them to 'this' + * bindFunctions(SomeService, this, SomeService); + * } + * + * let myOtherThing = new OtherThing(); + * myOtherThing.log(); // logs [3, 4, 5] from SomeService's 'this' + * ``` + * + * @param source A function that returns the source object which contains the original functions to be bound + * @param target A function that returns the target object which will receive the bound functions + * @param bind A function that returns the object which the functions will be bound to + * @param fnNames The function names which will be bound (Defaults to all the functions found on the 'from' object) + * @param latebind If true, the binding of the function is delayed until the first time it's invoked + */ +function createProxyFunctions(source, target, bind, fnNames, latebind) { + if (latebind === void 0) { latebind = false; } + var bindFunction = function (fnName) { + return source()[fnName].bind(bind()); + }; + var makeLateRebindFn = function (fnName) { return function lateRebindFunction() { + target[fnName] = bindFunction(fnName); + return target[fnName].apply(null, arguments); + }; }; + fnNames = fnNames || Object.keys(source()); + return fnNames.reduce(function (acc, name) { + acc[name] = latebind ? makeLateRebindFn(name) : bindFunction(name); + return acc; + }, target); +} +/** + * prototypal inheritance helper. + * Creates a new object which has `parent` object as its prototype, and then copies the properties from `extra` onto it + */ +var inherit = function (parent, extra) { + return extend(Object.create(parent), extra); +}; +/** Given an array, returns true if the object is found in the array, (using indexOf) */ +var inArray = curry(_inArray); +function _inArray(array, obj) { + return array.indexOf(obj) !== -1; +} +/** + * Given an array, and an item, if the item is found in the array, it removes it (in-place). + * The same array is returned + */ +var removeFrom = curry(_removeFrom); +function _removeFrom(array, obj) { + var idx = array.indexOf(obj); + if (idx >= 0) + array.splice(idx, 1); + return array; +} +/** pushes a values to an array and returns the value */ +var pushTo = curry(_pushTo); +function _pushTo(arr, val$$1) { + return (arr.push(val$$1), val$$1); +} +/** Given an array of (deregistration) functions, calls all functions and removes each one from the source array */ +var deregAll = function (functions) { + return functions.slice().forEach(function (fn) { + typeof fn === 'function' && fn(); + removeFrom(functions, fn); + }); +}; +/** + * Applies a set of defaults to an options object. The options object is filtered + * to only those properties of the objects in the defaultsList. + * Earlier objects in the defaultsList take precedence when applying defaults. + */ +function defaults(opts) { + var defaultsList = []; + for (var _i = 1; _i < arguments.length; _i++) { + defaultsList[_i - 1] = arguments[_i]; + } + var _defaultsList = defaultsList.concat({}).reverse(); + var defaultVals = extend.apply(null, _defaultsList); + return extend({}, defaultVals, pick(opts || {}, Object.keys(defaultVals))); +} +/** Reduce function that merges each element of the list into a single object, using extend */ +var mergeR = function (memo, item) { return extend(memo, item); }; +/** + * Finds the common ancestor path between two states. + * + * @param {Object} first The first state. + * @param {Object} second The second state. + * @return {Array} Returns an array of state names in descending order, not including the root. + */ +function ancestors(first, second) { + var path = []; + for (var n in first.path) { + if (first.path[n] !== second.path[n]) + break; + path.push(first.path[n]); + } + return path; +} +/** + * Return a copy of the object only containing the whitelisted properties. + * + * #### Example: + * ``` + * var foo = { a: 1, b: 2, c: 3 }; + * var ab = pick(foo, ['a', 'b']); // { a: 1, b: 2 } + * ``` + * @param obj the source object + * @param propNames an Array of strings, which are the whitelisted property names + */ +function pick(obj, propNames) { + var objCopy = {}; + for (var prop_1 in obj) { + if (propNames.indexOf(prop_1) !== -1) { + objCopy[prop_1] = obj[prop_1]; + } + } + return objCopy; +} +/** + * Return a copy of the object omitting the blacklisted properties. + * + * @example + * ``` + * + * var foo = { a: 1, b: 2, c: 3 }; + * var ab = omit(foo, ['a', 'b']); // { c: 3 } + * ``` + * @param obj the source object + * @param propNames an Array of strings, which are the blacklisted property names + */ +function omit(obj, propNames) { + return Object.keys(obj) + .filter(not(inArray(propNames))) + .reduce(function (acc, key) { return (acc[key] = obj[key], acc); }, {}); +} +/** + * Maps an array, or object to a property (by name) + */ +function pluck(collection, propName) { + return map(collection, prop(propName)); +} +/** Filters an Array or an Object's properties based on a predicate */ +function filter(collection, callback) { + var arr = isArray(collection), result = arr ? [] : {}; + var accept = arr ? function (x) { return result.push(x); } : function (x, key) { return result[key] = x; }; + forEach(collection, function (item, i) { + if (callback(item, i)) + accept(item, i); + }); + return result; +} +/** Finds an object from an array, or a property of an object, that matches a predicate */ +function find(collection, callback) { + var result; + forEach(collection, function (item, i) { + if (result) + return; + if (callback(item, i)) + result = item; + }); + return result; +} +/** Given an object, returns a new object, where each property is transformed by the callback function */ +var mapObj = map; +/** Maps an array or object properties using a callback function */ +function map(collection, callback) { + var result = isArray(collection) ? [] : {}; + forEach(collection, function (item, i) { return result[i] = callback(item, i); }); + return result; +} +/** + * Given an object, return its enumerable property values + * + * @example + * ``` + * + * let foo = { a: 1, b: 2, c: 3 } + * let vals = values(foo); // [ 1, 2, 3 ] + * ``` + */ +var values = function (obj) { + return Object.keys(obj).map(function (key) { return obj[key]; }); +}; +/** + * Reduce function that returns true if all of the values are truthy. + * + * @example + * ``` + * + * let vals = [ 1, true, {}, "hello world"]; + * vals.reduce(allTrueR, true); // true + * + * vals.push(0); + * vals.reduce(allTrueR, true); // false + * ``` + */ +var allTrueR = function (memo, elem) { return memo && elem; }; +/** + * Reduce function that returns true if any of the values are truthy. + * + * * @example + * ``` + * + * let vals = [ 0, null, undefined ]; + * vals.reduce(anyTrueR, true); // false + * + * vals.push("hello world"); + * vals.reduce(anyTrueR, true); // true + * ``` + */ +var anyTrueR = function (memo, elem) { return memo || elem; }; +/** + * Reduce function which un-nests a single level of arrays + * @example + * ``` + * + * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; + * input.reduce(unnestR, []) // [ "a", "b", "c", "d", [ "double, "nested" ] ] + * ``` + */ +var unnestR = function (memo, elem) { return memo.concat(elem); }; +/** + * Reduce function which recursively un-nests all arrays + * + * @example + * ``` + * + * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; + * input.reduce(unnestR, []) // [ "a", "b", "c", "d", "double, "nested" ] + * ``` + */ +var flattenR = function (memo, elem) { + return isArray(elem) ? memo.concat(elem.reduce(flattenR, [])) : pushR(memo, elem); +}; +/** + * Reduce function that pushes an object to an array, then returns the array. + * Mostly just for [[flattenR]] and [[uniqR]] + */ +function pushR(arr, obj) { + arr.push(obj); + return arr; +} +/** Reduce function that filters out duplicates */ +var uniqR = function (acc, token) { + return inArray(acc, token) ? acc : pushR(acc, token); +}; +/** + * Return a new array with a single level of arrays unnested. + * + * @example + * ``` + * + * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; + * unnest(input) // [ "a", "b", "c", "d", [ "double, "nested" ] ] + * ``` + */ +var unnest = function (arr) { return arr.reduce(unnestR, []); }; +/** + * Return a completely flattened version of an array. + * + * @example + * ``` + * + * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; + * flatten(input) // [ "a", "b", "c", "d", "double, "nested" ] + * ``` + */ +var flatten = function (arr) { return arr.reduce(flattenR, []); }; +/** + * Given a .filter Predicate, builds a .filter Predicate which throws an error if any elements do not pass. + * @example + * ``` + * + * let isNumber = (obj) => typeof(obj) === 'number'; + * let allNumbers = [ 1, 2, 3, 4, 5 ]; + * allNumbers.filter(assertPredicate(isNumber)); //OK + * + * let oneString = [ 1, 2, 3, 4, "5" ]; + * oneString.filter(assertPredicate(isNumber, "Not all numbers")); // throws Error(""Not all numbers""); + * ``` + */ +var assertPredicate = assertFn; +/** + * Given a .map function, builds a .map function which throws an error if any mapped elements do not pass a truthyness test. + * @example + * ``` + * + * var data = { foo: 1, bar: 2 }; + * + * let keys = [ 'foo', 'bar' ] + * let values = keys.map(assertMap(key => data[key], "Key not found")); + * // values is [1, 2] + * + * let keys = [ 'foo', 'bar', 'baz' ] + * let values = keys.map(assertMap(key => data[key], "Key not found")); + * // throws Error("Key not found") + * ``` + */ +var assertMap = assertFn; +function assertFn(predicateOrMap, errMsg) { + if (errMsg === void 0) { errMsg = "assert failure"; } + return function (obj) { + var result = predicateOrMap(obj); + if (!result) { + throw new Error(isFunction(errMsg) ? errMsg(obj) : errMsg); + } + return result; + }; +} +/** + * Like _.pairs: Given an object, returns an array of key/value pairs + * + * @example + * ``` + * + * pairs({ foo: "FOO", bar: "BAR }) // [ [ "foo", "FOO" ], [ "bar": "BAR" ] ] + * ``` + */ +var pairs = function (obj) { + return Object.keys(obj).map(function (key) { return [key, obj[key]]; }); +}; +/** + * Given two or more parallel arrays, returns an array of tuples where + * each tuple is composed of [ a[i], b[i], ... z[i] ] + * + * @example + * ``` + * + * let foo = [ 0, 2, 4, 6 ]; + * let bar = [ 1, 3, 5, 7 ]; + * let baz = [ 10, 30, 50, 70 ]; + * arrayTuples(foo, bar); // [ [0, 1], [2, 3], [4, 5], [6, 7] ] + * arrayTuples(foo, bar, baz); // [ [0, 1, 10], [2, 3, 30], [4, 5, 50], [6, 7, 70] ] + * ``` + */ +function arrayTuples() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + if (args.length === 0) + return []; + var maxArrayLen = args.reduce(function (min, arr) { return Math.min(arr.length, min); }, 9007199254740991); // aka 2^53 − 1 aka Number.MAX_SAFE_INTEGER + var i, result = []; + for (i = 0; i < maxArrayLen; i++) { + // This is a hot function + // Unroll when there are 1-4 arguments + switch (args.length) { + case 1: + result.push([args[0][i]]); + break; + case 2: + result.push([args[0][i], args[1][i]]); + break; + case 3: + result.push([args[0][i], args[1][i], args[2][i]]); + break; + case 4: + result.push([args[0][i], args[1][i], args[2][i], args[3][i]]); + break; + default: + result.push(args.map(function (array) { return array[i]; })); + break; + } + } + return result; +} +/** + * Reduce function which builds an object from an array of [key, value] pairs. + * + * Each iteration sets the key/val pair on the memo object, then returns the memo for the next iteration. + * + * Each keyValueTuple should be an array with values [ key: string, value: any ] + * + * @example + * ``` + * + * var pairs = [ ["fookey", "fooval"], ["barkey", "barval"] ] + * + * var pairsToObj = pairs.reduce((memo, pair) => applyPairs(memo, pair), {}) + * // pairsToObj == { fookey: "fooval", barkey: "barval" } + * + * // Or, more simply: + * var pairsToObj = pairs.reduce(applyPairs, {}) + * // pairsToObj == { fookey: "fooval", barkey: "barval" } + * ``` + */ +function applyPairs(memo, keyValTuple) { + var key, value; + if (isArray(keyValTuple)) + key = keyValTuple[0], value = keyValTuple[1]; + if (!isString(key)) + throw new Error("invalid parameters to applyPairs"); + memo[key] = value; + return memo; +} +/** Get the last element of an array */ +function tail(arr) { + return arr.length && arr[arr.length - 1] || undefined; +} +/** + * shallow copy from src to dest + */ +function copy(src, dest) { + if (dest) + Object.keys(dest).forEach(function (key) { return delete dest[key]; }); + if (!dest) + dest = {}; + return extend(dest, src); +} +/** Naive forEach implementation works with Objects or Arrays */ +function _forEach(obj, cb, _this) { + if (isArray(obj)) + return obj.forEach(cb, _this); + Object.keys(obj).forEach(function (key) { return cb(obj[key], key); }); +} +function _extend(toObj) { + for (var i = 1; i < arguments.length; i++) { + var obj = arguments[i]; + if (!obj) + continue; + var keys = Object.keys(obj); + for (var j = 0; j < keys.length; j++) { + toObj[keys[j]] = obj[keys[j]]; + } + } + return toObj; +} +function _equals(o1, o2) { + if (o1 === o2) + return true; + if (o1 === null || o2 === null) + return false; + if (o1 !== o1 && o2 !== o2) + return true; // NaN === NaN + var t1 = typeof o1, t2 = typeof o2; + if (t1 !== t2 || t1 !== 'object') + return false; + var tup = [o1, o2]; + if (all(isArray)(tup)) + return _arraysEq(o1, o2); + if (all(isDate)(tup)) + return o1.getTime() === o2.getTime(); + if (all(isRegExp)(tup)) + return o1.toString() === o2.toString(); + if (all(isFunction)(tup)) + return true; // meh + var predicates = [isFunction, isArray, isDate, isRegExp]; + if (predicates.map(any).reduce(function (b, fn) { return b || !!fn(tup); }, false)) + return false; + var key, keys = {}; + for (key in o1) { + if (!_equals(o1[key], o2[key])) + return false; + keys[key] = true; + } + for (key in o2) { + if (!keys[key]) + return false; + } + return true; +} +function _arraysEq(a1, a2) { + if (a1.length !== a2.length) + return false; + return arrayTuples(a1, a2).reduce(function (b, t) { return b && _equals(t[0], t[1]); }, true); +} +// issue #2676 +var silenceUncaughtInPromise = function (promise) { + return promise.catch(function (e) { return 0; }) && promise; +}; +var silentRejection = function (error) { + return silenceUncaughtInPromise(services.$q.reject(error)); +}; + +/** + * @module common + */ /** for typedoc */ +var Queue = /** @class */ (function () { + function Queue(_items, _limit) { + if (_items === void 0) { _items = []; } + if (_limit === void 0) { _limit = null; } + this._items = _items; + this._limit = _limit; + } + Queue.prototype.enqueue = function (item) { + var items = this._items; + items.push(item); + if (this._limit && items.length > this._limit) + items.shift(); + return item; + }; + Queue.prototype.dequeue = function () { + if (this.size()) + return this._items.splice(0, 1)[0]; + }; + Queue.prototype.clear = function () { + var current = this._items; + this._items = []; + return current; + }; + Queue.prototype.size = function () { + return this._items.length; + }; + Queue.prototype.remove = function (item) { + var idx = this._items.indexOf(item); + return idx > -1 && this._items.splice(idx, 1)[0]; + }; + Queue.prototype.peekTail = function () { + return this._items[this._items.length - 1]; + }; + Queue.prototype.peekHead = function () { + if (this.size()) + return this._items[0]; + }; + return Queue; +}()); + +/** + * @coreapi + * @module transition + */ /** for typedoc */ +"use strict"; + +(function (RejectType) { + RejectType[RejectType["SUPERSEDED"] = 2] = "SUPERSEDED"; + RejectType[RejectType["ABORTED"] = 3] = "ABORTED"; + RejectType[RejectType["INVALID"] = 4] = "INVALID"; + RejectType[RejectType["IGNORED"] = 5] = "IGNORED"; + RejectType[RejectType["ERROR"] = 6] = "ERROR"; +})(exports.RejectType || (exports.RejectType = {})); +/** @hidden */ var id = 0; +var Rejection = /** @class */ (function () { + function Rejection(type, message, detail) { + this.$id = id++; + this.type = type; + this.message = message; + this.detail = detail; + } + Rejection.prototype.toString = function () { + var detailString = function (d) { + return d && d.toString !== Object.prototype.toString ? d.toString() : stringify(d); + }; + var detail = detailString(this.detail); + var _a = this, $id = _a.$id, type = _a.type, message = _a.message; + return "Transition Rejection($id: " + $id + " type: " + type + ", message: " + message + ", detail: " + detail + ")"; + }; + Rejection.prototype.toPromise = function () { + return extend(silentRejection(this), { _transitionRejection: this }); + }; + /** Returns true if the obj is a rejected promise created from the `asPromise` factory */ + Rejection.isRejectionPromise = function (obj) { + return obj && (typeof obj.then === 'function') && is(Rejection)(obj._transitionRejection); + }; + /** Returns a Rejection due to transition superseded */ + Rejection.superseded = function (detail, options) { + var message = "The transition has been superseded by a different transition"; + var rejection = new Rejection(exports.RejectType.SUPERSEDED, message, detail); + if (options && options.redirected) { + rejection.redirected = true; + } + return rejection; + }; + /** Returns a Rejection due to redirected transition */ + Rejection.redirected = function (detail) { + return Rejection.superseded(detail, { redirected: true }); + }; + /** Returns a Rejection due to invalid transition */ + Rejection.invalid = function (detail) { + var message = "This transition is invalid"; + return new Rejection(exports.RejectType.INVALID, message, detail); + }; + /** Returns a Rejection due to ignored transition */ + Rejection.ignored = function (detail) { + var message = "The transition was ignored"; + return new Rejection(exports.RejectType.IGNORED, message, detail); + }; + /** Returns a Rejection due to aborted transition */ + Rejection.aborted = function (detail) { + var message = "The transition has been aborted"; + return new Rejection(exports.RejectType.ABORTED, message, detail); + }; + /** Returns a Rejection due to aborted transition */ + Rejection.errored = function (detail) { + var message = "The transition errored"; + return new Rejection(exports.RejectType.ERROR, message, detail); + }; + /** + * Returns a Rejection + * + * Normalizes a value as a Rejection. + * If the value is already a Rejection, returns it. + * Otherwise, wraps and returns the value as a Rejection (Rejection type: ERROR). + * + * @returns `detail` if it is already a `Rejection`, else returns an ERROR Rejection. + */ + Rejection.normalize = function (detail) { + return is(Rejection)(detail) ? detail : Rejection.errored(detail); + }; + return Rejection; +}()); + +/** + * # Transition tracing (debug) + * + * Enable transition tracing to print transition information to the console, + * in order to help debug your application. + * Tracing logs detailed information about each Transition to your console. + * + * To enable tracing, import the [[Trace]] singleton and enable one or more categories. + * + * ### ES6 + * ```js + * import {trace} from "ui-router-ng2"; // or "angular-ui-router" + * trace.enable(1, 5); // TRANSITION and VIEWCONFIG + * ``` + * + * ### CJS + * ```js + * let trace = require("angular-ui-router").trace; // or "ui-router-ng2" + * trace.enable("TRANSITION", "VIEWCONFIG"); + * ``` + * + * ### Globals + * ```js + * let trace = window["angular-ui-router"].trace; // or "ui-router-ng2" + * trace.enable(); // Trace everything (very verbose) + * ``` + * + * ### Angular 1: + * ```js + * app.run($trace => $trace.enable()); + * ``` + * + * @coreapi + * @module trace + */ /** for typedoc */ +/** @hidden */ +function uiViewString(uiview) { + if (!uiview) + return 'ui-view (defunct)'; + var state = uiview.creationContext ? uiview.creationContext.name || '(root)' : '(none)'; + return "[ui-view#" + uiview.id + " " + uiview.$type + ":" + uiview.fqn + " (" + uiview.name + "@" + state + ")]"; +} +/** @hidden */ +var viewConfigString = function (viewConfig) { + var view = viewConfig.viewDecl; + var state = view.$context.name || '(root)'; + return "[View#" + viewConfig.$id + " from '" + state + "' state]: target ui-view: '" + view.$uiViewName + "@" + view.$uiViewContextAnchor + "'"; +}; +/** @hidden */ +function normalizedCat(input) { + return isNumber(input) ? exports.Category[input] : exports.Category[exports.Category[input]]; +} +/** @hidden */ +var consoleLog = Function.prototype.bind.call(console.log, console); +/** @hidden */ +var consoletable = isFunction(console.table) ? console.table.bind(console) : consoleLog.bind(console); +/** + * Trace categories Enum + * + * Enable or disable a category using [[Trace.enable]] or [[Trace.disable]] + * + * `trace.enable(Category.TRANSITION)` + * + * These can also be provided using a matching string, or position ordinal + * + * `trace.enable("TRANSITION")` + * + * `trace.enable(1)` + */ + +(function (Category) { + Category[Category["RESOLVE"] = 0] = "RESOLVE"; + Category[Category["TRANSITION"] = 1] = "TRANSITION"; + Category[Category["HOOK"] = 2] = "HOOK"; + Category[Category["UIVIEW"] = 3] = "UIVIEW"; + Category[Category["VIEWCONFIG"] = 4] = "VIEWCONFIG"; +})(exports.Category || (exports.Category = {})); +/** @hidden */ var _tid = parse("$id"); +/** @hidden */ var _rid = parse("router.$id"); +/** @hidden */ var transLbl = function (trans) { return "Transition #" + _tid(trans) + "-" + _rid(trans); }; +/** + * Prints UI-Router Transition trace information to the console. + */ +var Trace = /** @class */ (function () { + /** @hidden */ + function Trace() { + /** @hidden */ + this._enabled = {}; + this.approximateDigests = 0; + } + /** @hidden */ + Trace.prototype._set = function (enabled, categories) { + var _this = this; + if (!categories.length) { + categories = Object.keys(exports.Category) + .map(function (k) { return parseInt(k, 10); }) + .filter(function (k) { return !isNaN(k); }) + .map(function (key) { return exports.Category[key]; }); + } + categories.map(normalizedCat).forEach(function (category) { return _this._enabled[category] = enabled; }); + }; + Trace.prototype.enable = function () { + var categories = []; + for (var _i = 0; _i < arguments.length; _i++) { + categories[_i] = arguments[_i]; + } + this._set(true, categories); + }; + Trace.prototype.disable = function () { + var categories = []; + for (var _i = 0; _i < arguments.length; _i++) { + categories[_i] = arguments[_i]; + } + this._set(false, categories); + }; + /** + * Retrieves the enabled stateus of a [[Category]] + * + * ```js + * trace.enabled("VIEWCONFIG"); // true or false + * ``` + * + * @returns boolean true if the category is enabled + */ + Trace.prototype.enabled = function (category) { + return !!this._enabled[normalizedCat(category)]; + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceTransitionStart = function (trans) { + if (!this.enabled(exports.Category.TRANSITION)) + return; + console.log(transLbl(trans) + ": Started -> " + stringify(trans)); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceTransitionIgnored = function (trans) { + if (!this.enabled(exports.Category.TRANSITION)) + return; + console.log(transLbl(trans) + ": Ignored <> " + stringify(trans)); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceHookInvocation = function (step, trans, options) { + if (!this.enabled(exports.Category.HOOK)) + return; + var event = parse("traceData.hookType")(options) || "internal", context = parse("traceData.context.state.name")(options) || parse("traceData.context")(options) || "unknown", name = functionToString(step.registeredHook.callback); + console.log(transLbl(trans) + ": Hook -> " + event + " context: " + context + ", " + maxLength(200, name)); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceHookResult = function (hookResult, trans, transitionOptions) { + if (!this.enabled(exports.Category.HOOK)) + return; + console.log(transLbl(trans) + ": <- Hook returned: " + maxLength(200, stringify(hookResult))); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceResolvePath = function (path, when, trans) { + if (!this.enabled(exports.Category.RESOLVE)) + return; + console.log(transLbl(trans) + ": Resolving " + path + " (" + when + ")"); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceResolvableResolved = function (resolvable, trans) { + if (!this.enabled(exports.Category.RESOLVE)) + return; + console.log(transLbl(trans) + ": <- Resolved " + resolvable + " to: " + maxLength(200, stringify(resolvable.data))); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceError = function (reason, trans) { + if (!this.enabled(exports.Category.TRANSITION)) + return; + console.log(transLbl(trans) + ": <- Rejected " + stringify(trans) + ", reason: " + reason); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceSuccess = function (finalState, trans) { + if (!this.enabled(exports.Category.TRANSITION)) + return; + console.log(transLbl(trans) + ": <- Success " + stringify(trans) + ", final state: " + finalState.name); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceUIViewEvent = function (event, viewData, extra) { + if (extra === void 0) { extra = ""; } + if (!this.enabled(exports.Category.UIVIEW)) + return; + console.log("ui-view: " + padString(30, event) + " " + uiViewString(viewData) + extra); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceUIViewConfigUpdated = function (viewData, context) { + if (!this.enabled(exports.Category.UIVIEW)) + return; + this.traceUIViewEvent("Updating", viewData, " with ViewConfig from context='" + context + "'"); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceUIViewFill = function (viewData, html) { + if (!this.enabled(exports.Category.UIVIEW)) + return; + this.traceUIViewEvent("Fill", viewData, " with: " + maxLength(200, html)); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceViewSync = function (pairs) { + if (!this.enabled(exports.Category.VIEWCONFIG)) + return; + var mapping = pairs.map(function (_a) { + var uiViewData = _a[0], config = _a[1]; + var uiView = uiViewData.$type + ":" + uiViewData.fqn; + var view = config && config.viewDecl.$context.name + ": " + config.viewDecl.$name + " (" + config.viewDecl.$type + ")"; + return { 'ui-view fqn': uiView, 'state: view name': view }; + }).sort(function (a, b) { return a['ui-view fqn'].localeCompare(b['ui-view fqn']); }); + consoletable(mapping); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceViewServiceEvent = function (event, viewConfig) { + if (!this.enabled(exports.Category.VIEWCONFIG)) + return; + console.log("VIEWCONFIG: " + event + " " + viewConfigString(viewConfig)); + }; + /** @internalapi called by ui-router code */ + Trace.prototype.traceViewServiceUIViewEvent = function (event, viewData) { + if (!this.enabled(exports.Category.VIEWCONFIG)) + return; + console.log("VIEWCONFIG: " + event + " " + uiViewString(viewData)); + }; + return Trace; +}()); +/** + * The [[Trace]] singleton + * + * #### Example: + * ```js + * import {trace} from "angular-ui-router"; + * trace.enable(1, 5); + * ``` + */ +var trace = new Trace(); + +(function (TransitionHookPhase) { + TransitionHookPhase[TransitionHookPhase["CREATE"] = 0] = "CREATE"; + TransitionHookPhase[TransitionHookPhase["BEFORE"] = 1] = "BEFORE"; + TransitionHookPhase[TransitionHookPhase["RUN"] = 2] = "RUN"; + TransitionHookPhase[TransitionHookPhase["SUCCESS"] = 3] = "SUCCESS"; + TransitionHookPhase[TransitionHookPhase["ERROR"] = 4] = "ERROR"; +})(exports.TransitionHookPhase || (exports.TransitionHookPhase = {})); + +(function (TransitionHookScope) { + TransitionHookScope[TransitionHookScope["TRANSITION"] = 0] = "TRANSITION"; + TransitionHookScope[TransitionHookScope["STATE"] = 1] = "STATE"; +})(exports.TransitionHookScope || (exports.TransitionHookScope = {})); + +/** + * @coreapi + * @module state + */ /** for typedoc */ +/** + * Encapsulate the target (destination) state/params/options of a [[Transition]]. + * + * This class is frequently used to redirect a transition to a new destination. + * + * See: + * + * - [[HookResult]] + * - [[TransitionHookFn]] + * - [[TransitionService.onStart]] + * + * To create a `TargetState`, use [[StateService.target]]. + * + * --- + * + * This class wraps: + * + * 1) an identifier for a state + * 2) a set of parameters + * 3) and transition options + * 4) the registered state object (the [[StateDeclaration]]) + * + * Many UI-Router APIs such as [[StateService.go]] take a [[StateOrName]] argument which can + * either be a *state object* (a [[StateDeclaration]] or [[StateObject]]) or a *state name* (a string). + * The `TargetState` class normalizes those options. + * + * A `TargetState` may be valid (the state being targeted exists in the registry) + * or invalid (the state being targeted is not registered). + */ +var TargetState = /** @class */ (function () { + /** + * The TargetState constructor + * + * Note: Do not construct a `TargetState` manually. + * To create a `TargetState`, use the [[StateService.target]] factory method. + * + * @param _stateRegistry The StateRegistry to use to look up the _definition + * @param _identifier An identifier for a state. + * Either a fully-qualified state name, or the object used to define the state. + * @param _params Parameters for the target state + * @param _options Transition options. + * + * @internalapi + */ + function TargetState(_stateRegistry, _identifier, _params, _options) { + this._stateRegistry = _stateRegistry; + this._identifier = _identifier; + this._identifier = _identifier; + this._params = extend({}, _params || {}); + this._options = extend({}, _options || {}); + this._definition = _stateRegistry.matcher.find(_identifier, this._options.relative); + } + /** The name of the state this object targets */ + TargetState.prototype.name = function () { + return this._definition && this._definition.name || this._identifier; + }; + /** The identifier used when creating this TargetState */ + TargetState.prototype.identifier = function () { + return this._identifier; + }; + /** The target parameter values */ + TargetState.prototype.params = function () { + return this._params; + }; + /** The internal state object (if it was found) */ + TargetState.prototype.$state = function () { + return this._definition; + }; + /** The internal state declaration (if it was found) */ + TargetState.prototype.state = function () { + return this._definition && this._definition.self; + }; + /** The target options */ + TargetState.prototype.options = function () { + return this._options; + }; + /** True if the target state was found */ + TargetState.prototype.exists = function () { + return !!(this._definition && this._definition.self); + }; + /** True if the object is valid */ + TargetState.prototype.valid = function () { + return !this.error(); + }; + /** If the object is invalid, returns the reason why */ + TargetState.prototype.error = function () { + var base = this.options().relative; + if (!this._definition && !!base) { + var stateName = base.name ? base.name : base; + return "Could not resolve '" + this.name() + "' from state '" + stateName + "'"; + } + if (!this._definition) + return "No such state '" + this.name() + "'"; + if (!this._definition.self) + return "State '" + this.name() + "' has an invalid definition"; + }; + TargetState.prototype.toString = function () { + return "'" + this.name() + "'" + stringify(this.params()); + }; + /** + * Returns a copy of this TargetState which targets a different state. + * The new TargetState has the same parameter values and transition options. + * + * @param state The new state that should be targeted + */ + TargetState.prototype.withState = function (state) { + return new TargetState(this._stateRegistry, state, this._params, this._options); + }; + /** + * Returns a copy of this TargetState, using the specified parameter values. + * + * @param params the new parameter values to use + * @param replace When false (default) the new parameter values will be merged with the current values. + * When true the parameter values will be used instead of the current values. + */ + TargetState.prototype.withParams = function (params, replace) { + if (replace === void 0) { replace = false; } + var newParams = replace ? params : extend({}, this._params, params); + return new TargetState(this._stateRegistry, this._identifier, newParams, this._options); + }; + /** + * Returns a copy of this TargetState, using the specified Transition Options. + * + * @param options the new options to use + * @param replace When false (default) the new options will be merged with the current options. + * When true the options will be used instead of the current options. + */ + TargetState.prototype.withOptions = function (options, replace) { + if (replace === void 0) { replace = false; } + var newOpts = replace ? options : extend({}, this._options, options); + return new TargetState(this._stateRegistry, this._identifier, this._params, newOpts); + }; + /** Returns true if the object has a state property that might be a state or state name */ + TargetState.isDef = function (obj) { + return obj && obj.state && (isString(obj.state) || isString(obj.state.name)); + }; + return TargetState; +}()); + +/** + * @coreapi + * @module transition + */ +/** for typedoc */ +var defaultOptions = { + current: noop$1, + transition: null, + traceData: {}, + bind: null, +}; +/** @hidden */ +var TransitionHook = /** @class */ (function () { + function TransitionHook(transition, stateContext, registeredHook, options) { + var _this = this; + this.transition = transition; + this.stateContext = stateContext; + this.registeredHook = registeredHook; + this.options = options; + this.isSuperseded = function () { + return _this.type.hookPhase === exports.TransitionHookPhase.RUN && !_this.options.transition.isActive(); + }; + this.options = defaults(options, defaultOptions); + this.type = registeredHook.eventType; + } + TransitionHook.prototype.logError = function (err) { + this.transition.router.stateService.defaultErrorHandler()(err); + }; + TransitionHook.prototype.invokeHook = function () { + var _this = this; + var hook = this.registeredHook; + if (hook._deregistered) + return; + var notCurrent = this.getNotCurrentRejection(); + if (notCurrent) + return notCurrent; + var options = this.options; + trace.traceHookInvocation(this, this.transition, options); + var invokeCallback = function () { + return hook.callback.call(options.bind, _this.transition, _this.stateContext); + }; + var normalizeErr = function (err) { + return Rejection.normalize(err).toPromise(); + }; + var handleError = function (err) { + return hook.eventType.getErrorHandler(_this)(err); + }; + var handleResult = function (result) { + return hook.eventType.getResultHandler(_this)(result); + }; + try { + var result = invokeCallback(); + if (!this.type.synchronous && isPromise(result)) { + return result.catch(normalizeErr) + .then(handleResult, handleError); + } + else { + return handleResult(result); + } + } + catch (err) { + // If callback throws (synchronously) + return handleError(Rejection.normalize(err)); + } + finally { + if (hook.invokeLimit && ++hook.invokeCount >= hook.invokeLimit) { + hook.deregister(); + } + } + }; + /** + * This method handles the return value of a Transition Hook. + * + * A hook can return false (cancel), a TargetState (redirect), + * or a promise (which may later resolve to false or a redirect) + * + * This also handles "transition superseded" -- when a new transition + * was started while the hook was still running + */ + TransitionHook.prototype.handleHookResult = function (result) { + var _this = this; + var notCurrent = this.getNotCurrentRejection(); + if (notCurrent) + return notCurrent; + // Hook returned a promise + if (isPromise(result)) { + // Wait for the promise, then reprocess with the resulting value + return result.then(function (val$$1) { return _this.handleHookResult(val$$1); }); + } + trace.traceHookResult(result, this.transition, this.options); + // Hook returned false + if (result === false) { + // Abort this Transition + return Rejection.aborted("Hook aborted transition").toPromise(); + } + var isTargetState = is(TargetState); + // hook returned a TargetState + if (isTargetState(result)) { + // Halt the current Transition and redirect (a new Transition) to the TargetState. + return Rejection.redirected(result).toPromise(); + } + }; + /** + * Return a Rejection promise if the transition is no longer current due + * to a stopped router (disposed), or a new transition has started and superseded this one. + */ + TransitionHook.prototype.getNotCurrentRejection = function () { + var router = this.transition.router; + // The router is stopped + if (router._disposed) { + return Rejection.aborted("UIRouter instance #" + router.$id + " has been stopped (disposed)").toPromise(); + } + if (this.transition._aborted) { + return Rejection.aborted().toPromise(); + } + // This transition is no longer current. + // Another transition started while this hook was still running. + if (this.isSuperseded()) { + // Abort this transition + return Rejection.superseded(this.options.current()).toPromise(); + } + }; + TransitionHook.prototype.toString = function () { + var _a = this, options = _a.options, registeredHook = _a.registeredHook; + var event = parse("traceData.hookType")(options) || "internal", context = parse("traceData.context.state.name")(options) || parse("traceData.context")(options) || "unknown", name = fnToString(registeredHook.callback); + return event + " context: " + context + ", " + maxLength(200, name); + }; + /** + * Chains together an array of TransitionHooks. + * + * Given a list of [[TransitionHook]] objects, chains them together. + * Each hook is invoked after the previous one completes. + * + * #### Example: + * ```js + * var hooks: TransitionHook[] = getHooks(); + * let promise: Promise = TransitionHook.chain(hooks); + * + * promise.then(handleSuccess, handleError); + * ``` + * + * @param hooks the list of hooks to chain together + * @param waitFor if provided, the chain is `.then()`'ed off this promise + * @returns a `Promise` for sequentially invoking the hooks (in order) + */ + TransitionHook.chain = function (hooks, waitFor) { + // Chain the next hook off the previous + var createHookChainR = function (prev, nextHook) { + return prev.then(function () { return nextHook.invokeHook(); }); + }; + return hooks.reduce(createHookChainR, waitFor || services.$q.when()); + }; + /** + * Invokes all the provided TransitionHooks, in order. + * Each hook's return value is checked. + * If any hook returns a promise, then the rest of the hooks are chained off that promise, and the promise is returned. + * If no hook returns a promise, then all hooks are processed synchronously. + * + * @param hooks the list of TransitionHooks to invoke + * @param doneCallback a callback that is invoked after all the hooks have successfully completed + * + * @returns a promise for the async result, or the result of the callback + */ + TransitionHook.invokeHooks = function (hooks, doneCallback) { + for (var idx = 0; idx < hooks.length; idx++) { + var hookResult = hooks[idx].invokeHook(); + if (isPromise(hookResult)) { + var remainingHooks = hooks.slice(idx + 1); + return TransitionHook.chain(remainingHooks, hookResult) + .then(doneCallback); + } + } + return doneCallback(); + }; + /** + * Run all TransitionHooks, ignoring their return value. + */ + TransitionHook.runAllHooks = function (hooks) { + hooks.forEach(function (hook) { return hook.invokeHook(); }); + }; + /** + * These GetResultHandler(s) are used by [[invokeHook]] below + * Each HookType chooses a GetResultHandler (See: [[TransitionService._defineCoreEvents]]) + */ + TransitionHook.HANDLE_RESULT = function (hook) { return function (result) { + return hook.handleHookResult(result); + }; }; + /** + * If the result is a promise rejection, log it. + * Otherwise, ignore the result. + */ + TransitionHook.LOG_REJECTED_RESULT = function (hook) { return function (result) { + isPromise(result) && result.catch(function (err) { + return hook.logError(Rejection.normalize(err)); + }); + return undefined; + }; }; + /** + * These GetErrorHandler(s) are used by [[invokeHook]] below + * Each HookType chooses a GetErrorHandler (See: [[TransitionService._defineCoreEvents]]) + */ + TransitionHook.LOG_ERROR = function (hook) { return function (error) { + return hook.logError(error); + }; }; + TransitionHook.REJECT_ERROR = function (hook) { return function (error) { + return silentRejection(error); + }; }; + TransitionHook.THROW_ERROR = function (hook) { return function (error) { + throw error; + }; }; + return TransitionHook; +}()); + +/** + * @coreapi + * @module transition + */ /** for typedoc */ +/** + * Determines if the given state matches the matchCriteria + * + * @hidden + * + * @param state a State Object to test against + * @param criterion + * - If a string, matchState uses the string as a glob-matcher against the state name + * - If an array (of strings), matchState uses each string in the array as a glob-matchers against the state name + * and returns a positive match if any of the globs match. + * - If a function, matchState calls the function with the state and returns true if the function's result is truthy. + * @returns {boolean} + */ +function matchState(state, criterion) { + var toMatch = isString(criterion) ? [criterion] : criterion; + function matchGlobs(_state) { + var globStrings = toMatch; + for (var i = 0; i < globStrings.length; i++) { + var glob = new Glob(globStrings[i]); + if ((glob && glob.matches(_state.name)) || (!glob && globStrings[i] === _state.name)) { + return true; + } + } + return false; + } + var matchFn = (isFunction(toMatch) ? toMatch : matchGlobs); + return !!matchFn(state); +} +/** + * @internalapi + * The registration data for a registered transition hook + */ +var RegisteredHook = /** @class */ (function () { + function RegisteredHook(tranSvc, eventType, callback, matchCriteria, removeHookFromRegistry, options) { + if (options === void 0) { options = {}; } + this.tranSvc = tranSvc; + this.eventType = eventType; + this.callback = callback; + this.matchCriteria = matchCriteria; + this.removeHookFromRegistry = removeHookFromRegistry; + this.invokeCount = 0; + this._deregistered = false; + this.priority = options.priority || 0; + this.bind = options.bind || null; + this.invokeLimit = options.invokeLimit; + } + /** + * Gets the matching [[PathNode]]s + * + * Given an array of [[PathNode]]s, and a [[HookMatchCriterion]], returns an array containing + * the [[PathNode]]s that the criteria matches, or `null` if there were no matching nodes. + * + * Returning `null` is significant to distinguish between the default + * "match-all criterion value" of `true` compared to a `() => true` function, + * when the nodes is an empty array. + * + * This is useful to allow a transition match criteria of `entering: true` + * to still match a transition, even when `entering === []`. Contrast that + * with `entering: (state) => true` which only matches when a state is actually + * being entered. + */ + RegisteredHook.prototype._matchingNodes = function (nodes, criterion) { + if (criterion === true) + return nodes; + var matching = nodes.filter(function (node) { return matchState(node.state, criterion); }); + return matching.length ? matching : null; + }; + /** + * Gets the default match criteria (all `true`) + * + * Returns an object which has all the criteria match paths as keys and `true` as values, i.e.: + * + * ```js + * { + * to: true, + * from: true, + * entering: true, + * exiting: true, + * retained: true, + * } + */ + RegisteredHook.prototype._getDefaultMatchCriteria = function () { + return map(this.tranSvc._pluginapi._getPathTypes(), function () { return true; }); + }; + /** + * Gets matching nodes as [[IMatchingNodes]] + * + * Create a IMatchingNodes object from the TransitionHookTypes that is roughly equivalent to: + * + * ```js + * let matches: IMatchingNodes = { + * to: _matchingNodes([tail(treeChanges.to)], mc.to), + * from: _matchingNodes([tail(treeChanges.from)], mc.from), + * exiting: _matchingNodes(treeChanges.exiting, mc.exiting), + * retained: _matchingNodes(treeChanges.retained, mc.retained), + * entering: _matchingNodes(treeChanges.entering, mc.entering), + * }; + * ``` + */ + RegisteredHook.prototype._getMatchingNodes = function (treeChanges) { + var _this = this; + var criteria = extend(this._getDefaultMatchCriteria(), this.matchCriteria); + var paths = values(this.tranSvc._pluginapi._getPathTypes()); + return paths.reduce(function (mn, pathtype) { + // STATE scope criteria matches against every node in the path. + // TRANSITION scope criteria matches against only the last node in the path + var isStateHook = pathtype.scope === exports.TransitionHookScope.STATE; + var path = treeChanges[pathtype.name] || []; + var nodes = isStateHook ? path : [tail(path)]; + mn[pathtype.name] = _this._matchingNodes(nodes, criteria[pathtype.name]); + return mn; + }, {}); + }; + /** + * Determines if this hook's [[matchCriteria]] match the given [[TreeChanges]] + * + * @returns an IMatchingNodes object, or null. If an IMatchingNodes object is returned, its values + * are the matching [[PathNode]]s for each [[HookMatchCriterion]] (to, from, exiting, retained, entering) + */ + RegisteredHook.prototype.matches = function (treeChanges) { + var matches = this._getMatchingNodes(treeChanges); + // Check if all the criteria matched the TreeChanges object + var allMatched = values(matches).every(identity); + return allMatched ? matches : null; + }; + RegisteredHook.prototype.deregister = function () { + this.removeHookFromRegistry(this); + this._deregistered = true; + }; + return RegisteredHook; +}()); +/** @hidden Return a registration function of the requested type. */ +function makeEvent(registry, transitionService, eventType) { + // Create the object which holds the registered transition hooks. + var _registeredHooks = registry._registeredHooks = (registry._registeredHooks || {}); + var hooks = _registeredHooks[eventType.name] = []; + var removeHookFn = removeFrom(hooks); + // Create hook registration function on the IHookRegistry for the event + registry[eventType.name] = hookRegistrationFn; + function hookRegistrationFn(matchObject, callback, options) { + if (options === void 0) { options = {}; } + var registeredHook = new RegisteredHook(transitionService, eventType, callback, matchObject, removeHookFn, options); + hooks.push(registeredHook); + return registeredHook.deregister.bind(registeredHook); + } + return hookRegistrationFn; +} + +/** + * @coreapi + * @module transition + */ /** for typedoc */ +/** + * This class returns applicable TransitionHooks for a specific Transition instance. + * + * Hooks ([[RegisteredHook]]) may be registered globally, e.g., $transitions.onEnter(...), or locally, e.g. + * myTransition.onEnter(...). The HookBuilder finds matching RegisteredHooks (where the match criteria is + * determined by the type of hook) + * + * The HookBuilder also converts RegisteredHooks objects to TransitionHook objects, which are used to run a Transition. + * + * The HookBuilder constructor is given the $transitions service and a Transition instance. Thus, a HookBuilder + * instance may only be used for one specific Transition object. (side note: the _treeChanges accessor is private + * in the Transition class, so we must also provide the Transition's _treeChanges) + * + */ +var HookBuilder = /** @class */ (function () { + function HookBuilder(transition) { + this.transition = transition; + } + HookBuilder.prototype.buildHooksForPhase = function (phase) { + var _this = this; + var $transitions = this.transition.router.transitionService; + return $transitions._pluginapi._getEvents(phase) + .map(function (type) { return _this.buildHooks(type); }) + .reduce(unnestR, []) + .filter(identity); + }; + /** + * Returns an array of newly built TransitionHook objects. + * + * - Finds all RegisteredHooks registered for the given `hookType` which matched the transition's [[TreeChanges]]. + * - Finds [[PathNode]] (or `PathNode[]`) to use as the TransitionHook context(s) + * - For each of the [[PathNode]]s, creates a TransitionHook + * + * @param hookType the type of the hook registration function, e.g., 'onEnter', 'onFinish'. + */ + HookBuilder.prototype.buildHooks = function (hookType) { + var transition = this.transition; + var treeChanges = transition.treeChanges(); + // Find all the matching registered hooks for a given hook type + var matchingHooks = this.getMatchingHooks(hookType, treeChanges); + if (!matchingHooks) + return []; + var baseHookOptions = { + transition: transition, + current: transition.options().current + }; + var makeTransitionHooks = function (hook) { + // Fetch the Nodes that caused this hook to match. + var matches = hook.matches(treeChanges); + // Select the PathNode[] that will be used as TransitionHook context objects + var matchingNodes = matches[hookType.criteriaMatchPath.name]; + // Return an array of HookTuples + return matchingNodes.map(function (node) { + var _options = extend({ + bind: hook.bind, + traceData: { hookType: hookType.name, context: node } + }, baseHookOptions); + var state = hookType.criteriaMatchPath.scope === exports.TransitionHookScope.STATE ? node.state.self : null; + var transitionHook = new TransitionHook(transition, state, hook, _options); + return { hook: hook, node: node, transitionHook: transitionHook }; + }); + }; + return matchingHooks.map(makeTransitionHooks) + .reduce(unnestR, []) + .sort(tupleSort(hookType.reverseSort)) + .map(function (tuple) { return tuple.transitionHook; }); + }; + /** + * Finds all RegisteredHooks from: + * - The Transition object instance hook registry + * - The TransitionService ($transitions) global hook registry + * + * which matched: + * - the eventType + * - the matchCriteria (to, from, exiting, retained, entering) + * + * @returns an array of matched [[RegisteredHook]]s + */ + HookBuilder.prototype.getMatchingHooks = function (hookType, treeChanges) { + var isCreate = hookType.hookPhase === exports.TransitionHookPhase.CREATE; + // Instance and Global hook registries + var $transitions = this.transition.router.transitionService; + var registries = isCreate ? [$transitions] : [this.transition, $transitions]; + return registries.map(function (reg) { return reg.getHooks(hookType.name); }) // Get named hooks from registries + .filter(assertPredicate(isArray, "broken event named: " + hookType.name)) // Sanity check + .reduce(unnestR, []) // Un-nest RegisteredHook[][] to RegisteredHook[] array + .filter(function (hook) { return hook.matches(treeChanges); }); // Only those satisfying matchCriteria + }; + return HookBuilder; +}()); +/** + * A factory for a sort function for HookTuples. + * + * The sort function first compares the PathNode depth (how deep in the state tree a node is), then compares + * the EventHook priority. + * + * @param reverseDepthSort a boolean, when true, reverses the sort order for the node depth + * @returns a tuple sort function + */ +function tupleSort(reverseDepthSort) { + if (reverseDepthSort === void 0) { reverseDepthSort = false; } + return function nodeDepthThenPriority(l, r) { + var factor = reverseDepthSort ? -1 : 1; + var depthDelta = (l.node.state.path.length - r.node.state.path.length) * factor; + return depthDelta !== 0 ? depthDelta : r.hook.priority - l.hook.priority; + }; +} + +/** + * @coreapi + * @module params + */ +/** */ +/** + * An internal class which implements [[ParamTypeDefinition]]. + * + * A [[ParamTypeDefinition]] is a plain javascript object used to register custom parameter types. + * When a param type definition is registered, an instance of this class is created internally. + * + * This class has naive implementations for all the [[ParamTypeDefinition]] methods. + * + * Used by [[UrlMatcher]] when matching or formatting URLs, or comparing and validating parameter values. + * + * #### Example: + * ```js + * var paramTypeDef = { + * decode: function(val) { return parseInt(val, 10); }, + * encode: function(val) { return val && val.toString(); }, + * equals: function(a, b) { return this.is(a) && a === b; }, + * is: function(val) { return angular.isNumber(val) && isFinite(val) && val % 1 === 0; }, + * pattern: /\d+/ + * } + * + * var paramType = new ParamType(paramTypeDef); + * ``` + * @internalapi + */ +var ParamType = /** @class */ (function () { + /** + * @param def A configuration object which contains the custom type definition. The object's + * properties will override the default methods and/or pattern in `ParamType`'s public interface. + * @returns a new ParamType object + */ + function ParamType(def) { + /** @inheritdoc */ + this.pattern = /.*/; + /** @inheritdoc */ + this.inherit = true; + extend(this, def); + } + // consider these four methods to be "abstract methods" that should be overridden + /** @inheritdoc */ + ParamType.prototype.is = function (val, key) { return true; }; + /** @inheritdoc */ + ParamType.prototype.encode = function (val, key) { return val; }; + /** @inheritdoc */ + ParamType.prototype.decode = function (val, key) { return val; }; + /** @inheritdoc */ + ParamType.prototype.equals = function (a, b) { return a == b; }; + ParamType.prototype.$subPattern = function () { + var sub = this.pattern.toString(); + return sub.substr(1, sub.length - 2); + }; + ParamType.prototype.toString = function () { + return "{ParamType:" + this.name + "}"; + }; + /** Given an encoded string, or a decoded object, returns a decoded object */ + ParamType.prototype.$normalize = function (val) { + return this.is(val) ? val : this.decode(val); + }; + /** + * Wraps an existing custom ParamType as an array of ParamType, depending on 'mode'. + * e.g.: + * - urlmatcher pattern "/path?{queryParam[]:int}" + * - url: "/path?queryParam=1&queryParam=2 + * - $stateParams.queryParam will be [1, 2] + * if `mode` is "auto", then + * - url: "/path?queryParam=1 will create $stateParams.queryParam: 1 + * - url: "/path?queryParam=1&queryParam=2 will create $stateParams.queryParam: [1, 2] + */ + ParamType.prototype.$asArray = function (mode, isSearch) { + if (!mode) + return this; + if (mode === "auto" && !isSearch) + throw new Error("'auto' array mode is for query parameters only"); + return new ArrayType(this, mode); + }; + return ParamType; +}()); +/** + * Wraps up a `ParamType` object to handle array values. + * @internalapi + */ +function ArrayType(type, mode) { + var _this = this; + // Wrap non-array value as array + function arrayWrap(val) { + return isArray(val) ? val : (isDefined(val) ? [val] : []); + } + // Unwrap array value for "auto" mode. Return undefined for empty array. + function arrayUnwrap(val) { + switch (val.length) { + case 0: return undefined; + case 1: return mode === "auto" ? val[0] : val; + default: return val; + } + } + // Wraps type (.is/.encode/.decode) functions to operate on each value of an array + function arrayHandler(callback, allTruthyMode) { + return function handleArray(val) { + if (isArray(val) && val.length === 0) + return val; + var arr = arrayWrap(val); + var result = map(arr, callback); + return (allTruthyMode === true) ? filter(result, function (x) { return !x; }).length === 0 : arrayUnwrap(result); + }; + } + // Wraps type (.equals) functions to operate on each value of an array + function arrayEqualsHandler(callback) { + return function handleArray(val1, val2) { + var left = arrayWrap(val1), right = arrayWrap(val2); + if (left.length !== right.length) + return false; + for (var i = 0; i < left.length; i++) { + if (!callback(left[i], right[i])) + return false; + } + return true; + }; + } + ['encode', 'decode', 'equals', '$normalize'].forEach(function (name) { + var paramTypeFn = type[name].bind(type); + var wrapperFn = name === 'equals' ? arrayEqualsHandler : arrayHandler; + _this[name] = wrapperFn(paramTypeFn); + }); + extend(this, { + dynamic: type.dynamic, + name: type.name, + pattern: type.pattern, + inherit: type.inherit, + is: arrayHandler(type.is.bind(type), true), + $arrayMode: mode + }); +} + +/** + * @coreapi + * @module params + */ /** for typedoc */ +/** @hidden */ var hasOwn = Object.prototype.hasOwnProperty; +/** @hidden */ var isShorthand = function (cfg) { + return ["value", "type", "squash", "array", "dynamic"].filter(hasOwn.bind(cfg || {})).length === 0; +}; +/** @internalapi */ + +(function (DefType) { + DefType[DefType["PATH"] = 0] = "PATH"; + DefType[DefType["SEARCH"] = 1] = "SEARCH"; + DefType[DefType["CONFIG"] = 2] = "CONFIG"; +})(exports.DefType || (exports.DefType = {})); +/** @hidden */ +function unwrapShorthand(cfg) { + cfg = isShorthand(cfg) && { value: cfg } || cfg; + getStaticDefaultValue['__cacheable'] = true; + function getStaticDefaultValue() { + return cfg.value; + } + return extend(cfg, { + $$fn: isInjectable(cfg.value) ? cfg.value : getStaticDefaultValue, + }); +} +/** @hidden */ +function getType(cfg, urlType, location, id, paramTypes) { + if (cfg.type && urlType && urlType.name !== 'string') + throw new Error("Param '" + id + "' has two type configurations."); + if (cfg.type && urlType && urlType.name === 'string' && paramTypes.type(cfg.type)) + return paramTypes.type(cfg.type); + if (urlType) + return urlType; + if (!cfg.type) { + var type = location === exports.DefType.CONFIG ? "any" : + location === exports.DefType.PATH ? "path" : + location === exports.DefType.SEARCH ? "query" : "string"; + return paramTypes.type(type); + } + return cfg.type instanceof ParamType ? cfg.type : paramTypes.type(cfg.type); +} +/** + * @internalapi + * returns false, true, or the squash value to indicate the "default parameter url squash policy". + */ +function getSquashPolicy(config, isOptional, defaultPolicy) { + var squash = config.squash; + if (!isOptional || squash === false) + return false; + if (!isDefined(squash) || squash == null) + return defaultPolicy; + if (squash === true || isString(squash)) + return squash; + throw new Error("Invalid squash policy: '" + squash + "'. Valid policies: false, true, or arbitrary string"); +} +/** @internalapi */ +function getReplace(config, arrayMode, isOptional, squash) { + var replace, configuredKeys, defaultPolicy = [ + { from: "", to: (isOptional || arrayMode ? undefined : "") }, + { from: null, to: (isOptional || arrayMode ? undefined : "") }, + ]; + replace = isArray(config.replace) ? config.replace : []; + if (isString(squash)) + replace.push({ from: squash, to: undefined }); + configuredKeys = map(replace, prop("from")); + return filter(defaultPolicy, function (item) { return configuredKeys.indexOf(item.from) === -1; }).concat(replace); +} +/** @internalapi */ +var Param = /** @class */ (function () { + function Param(id, type, config, location, urlMatcherFactory) { + config = unwrapShorthand(config); + type = getType(config, type, location, id, urlMatcherFactory.paramTypes); + var arrayMode = getArrayMode(); + type = arrayMode ? type.$asArray(arrayMode, location === exports.DefType.SEARCH) : type; + var isOptional = config.value !== undefined || location === exports.DefType.SEARCH; + var dynamic = isDefined(config.dynamic) ? !!config.dynamic : !!type.dynamic; + var raw = isDefined(config.raw) ? !!config.raw : !!type.raw; + var squash = getSquashPolicy(config, isOptional, urlMatcherFactory.defaultSquashPolicy()); + var replace = getReplace(config, arrayMode, isOptional, squash); + var inherit$$1 = isDefined(config.inherit) ? !!config.inherit : !!type.inherit; + // array config: param name (param[]) overrides default settings. explicit config overrides param name. + function getArrayMode() { + var arrayDefaults = { array: (location === exports.DefType.SEARCH ? "auto" : false) }; + var arrayParamNomenclature = id.match(/\[\]$/) ? { array: true } : {}; + return extend(arrayDefaults, arrayParamNomenclature, config).array; + } + extend(this, { id: id, type: type, location: location, isOptional: isOptional, dynamic: dynamic, raw: raw, squash: squash, replace: replace, inherit: inherit$$1, array: arrayMode, config: config }); + } + Param.prototype.isDefaultValue = function (value) { + return this.isOptional && this.type.equals(this.value(), value); + }; + /** + * [Internal] Gets the decoded representation of a value if the value is defined, otherwise, returns the + * default value, which may be the result of an injectable function. + */ + Param.prototype.value = function (value) { + var _this = this; + /** + * [Internal] Get the default value of a parameter, which may be an injectable function. + */ + var getDefaultValue = function () { + if (_this._defaultValueCache) + return _this._defaultValueCache.defaultValue; + if (!services.$injector) + throw new Error("Injectable functions cannot be called at configuration time"); + var defaultValue = services.$injector.invoke(_this.config.$$fn); + if (defaultValue !== null && defaultValue !== undefined && !_this.type.is(defaultValue)) + throw new Error("Default value (" + defaultValue + ") for parameter '" + _this.id + "' is not an instance of ParamType (" + _this.type.name + ")"); + if (_this.config.$$fn['__cacheable']) { + _this._defaultValueCache = { defaultValue: defaultValue }; + } + return defaultValue; + }; + var replaceSpecialValues = function (val$$1) { + for (var _i = 0, _a = _this.replace; _i < _a.length; _i++) { + var tuple = _a[_i]; + if (tuple.from === val$$1) + return tuple.to; + } + return val$$1; + }; + value = replaceSpecialValues(value); + return isUndefined(value) ? getDefaultValue() : this.type.$normalize(value); + }; + Param.prototype.isSearch = function () { + return this.location === exports.DefType.SEARCH; + }; + Param.prototype.validates = function (value) { + // There was no parameter value, but the param is optional + if ((isUndefined(value) || value === null) && this.isOptional) + return true; + // The value was not of the correct ParamType, and could not be decoded to the correct ParamType + var normalized = this.type.$normalize(value); + if (!this.type.is(normalized)) + return false; + // The value was of the correct type, but when encoded, did not match the ParamType's regexp + var encoded = this.type.encode(normalized); + return !(isString(encoded) && !this.type.pattern.exec(encoded)); + }; + Param.prototype.toString = function () { + return "{Param:" + this.id + " " + this.type + " squash: '" + this.squash + "' optional: " + this.isOptional + "}"; + }; + Param.values = function (params, values$$1) { + if (values$$1 === void 0) { values$$1 = {}; } + var paramValues = {}; + for (var _i = 0, params_1 = params; _i < params_1.length; _i++) { + var param = params_1[_i]; + paramValues[param.id] = param.value(values$$1[param.id]); + } + return paramValues; + }; + /** + * Finds [[Param]] objects which have different param values + * + * Filters a list of [[Param]] objects to only those whose parameter values differ in two param value objects + * + * @param params: The list of Param objects to filter + * @param values1: The first set of parameter values + * @param values2: the second set of parameter values + * + * @returns any Param objects whose values were different between values1 and values2 + */ + Param.changed = function (params, values1, values2) { + if (values1 === void 0) { values1 = {}; } + if (values2 === void 0) { values2 = {}; } + return params.filter(function (param) { return !param.type.equals(values1[param.id], values2[param.id]); }); + }; + /** + * Checks if two param value objects are equal (for a set of [[Param]] objects) + * + * @param params The list of [[Param]] objects to check + * @param values1 The first set of param values + * @param values2 The second set of param values + * + * @returns true if the param values in values1 and values2 are equal + */ + Param.equals = function (params, values1, values2) { + if (values1 === void 0) { values1 = {}; } + if (values2 === void 0) { values2 = {}; } + return Param.changed(params, values1, values2).length === 0; + }; + /** Returns true if a the parameter values are valid, according to the Param definitions */ + Param.validates = function (params, values$$1) { + if (values$$1 === void 0) { values$$1 = {}; } + return params.map(function (param) { return param.validates(values$$1[param.id]); }).reduce(allTrueR, true); + }; + return Param; +}()); + +/** @module path */ /** for typedoc */ +/** + * @internalapi + * + * A node in a [[TreeChanges]] path + * + * For a [[TreeChanges]] path, this class holds the stateful information for a single node in the path. + * Each PathNode corresponds to a state being entered, exited, or retained. + * The stateful information includes parameter values and resolve data. + */ +var PathNode = /** @class */ (function () { + function PathNode(stateOrNode) { + if (stateOrNode instanceof PathNode) { + var node = stateOrNode; + this.state = node.state; + this.paramSchema = node.paramSchema.slice(); + this.paramValues = extend({}, node.paramValues); + this.resolvables = node.resolvables.slice(); + this.views = node.views && node.views.slice(); + } + else { + var state = stateOrNode; + this.state = state; + this.paramSchema = state.parameters({ inherit: false }); + this.paramValues = {}; + this.resolvables = state.resolvables.map(function (res) { return res.clone(); }); + } + } + /** Sets [[paramValues]] for the node, from the values of an object hash */ + PathNode.prototype.applyRawParams = function (params) { + var getParamVal = function (paramDef) { return [paramDef.id, paramDef.value(params[paramDef.id])]; }; + this.paramValues = this.paramSchema.reduce(function (memo, pDef) { return applyPairs(memo, getParamVal(pDef)); }, {}); + return this; + }; + /** Gets a specific [[Param]] metadata that belongs to the node */ + PathNode.prototype.parameter = function (name) { + return find(this.paramSchema, propEq("id", name)); + }; + /** + * @returns true if the state and parameter values for another PathNode are + * equal to the state and param values for this PathNode + */ + PathNode.prototype.equals = function (node, paramsFn) { + var diff = this.diff(node, paramsFn); + return diff && diff.length === 0; + }; + /** + * Finds Params with different parameter values on another PathNode. + * + * Given another node (of the same state), finds the parameter values which differ. + * Returns the [[Param]] (schema objects) whose parameter values differ. + * + * Given another node for a different state, returns `false` + * + * @param node The node to compare to + * @param paramsFn A function that returns which parameters should be compared. + * @returns The [[Param]]s which differ, or null if the two nodes are for different states + */ + PathNode.prototype.diff = function (node, paramsFn) { + if (this.state !== node.state) + return false; + var params = paramsFn ? paramsFn(this) : this.paramSchema; + return Param.changed(params, this.paramValues, node.paramValues); + }; + /** Returns a clone of the PathNode */ + PathNode.clone = function (node) { + return new PathNode(node); + }; + return PathNode; +}()); + +/** @module path */ /** for typedoc */ +/** + * This class contains functions which convert TargetStates, Nodes and paths from one type to another. + */ +var PathUtils = /** @class */ (function () { + function PathUtils() { + } + /** Given a PathNode[], create an TargetState */ + PathUtils.makeTargetState = function (registry, path) { + var state = tail(path).state; + return new TargetState(registry, state, path.map(prop("paramValues")).reduce(mergeR, {}), {}); + }; + PathUtils.buildPath = function (targetState) { + var toParams = targetState.params(); + return targetState.$state().path.map(function (state) { return new PathNode(state).applyRawParams(toParams); }); + }; + /** Given a fromPath: PathNode[] and a TargetState, builds a toPath: PathNode[] */ + PathUtils.buildToPath = function (fromPath, targetState) { + var toPath = PathUtils.buildPath(targetState); + if (targetState.options().inherit) { + return PathUtils.inheritParams(fromPath, toPath, Object.keys(targetState.params())); + } + return toPath; + }; + /** + * Creates ViewConfig objects and adds to nodes. + * + * On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state + */ + PathUtils.applyViewConfigs = function ($view, path, states) { + // Only apply the viewConfigs to the nodes for the given states + path.filter(function (node) { return inArray(states, node.state); }).forEach(function (node) { + var viewDecls = values(node.state.views || {}); + var subPath = PathUtils.subPath(path, function (n) { return n === node; }); + var viewConfigs = viewDecls.map(function (view) { return $view.createViewConfig(subPath, view); }); + node.views = viewConfigs.reduce(unnestR, []); + }); + }; + /** + * Given a fromPath and a toPath, returns a new to path which inherits parameters from the fromPath + * + * For a parameter in a node to be inherited from the from path: + * - The toPath's node must have a matching node in the fromPath (by state). + * - The parameter name must not be found in the toKeys parameter array. + * + * Note: the keys provided in toKeys are intended to be those param keys explicitly specified by some + * caller, for instance, $state.transitionTo(..., toParams). If a key was found in toParams, + * it is not inherited from the fromPath. + */ + PathUtils.inheritParams = function (fromPath, toPath, toKeys) { + if (toKeys === void 0) { toKeys = []; } + function nodeParamVals(path, state) { + var node = find(path, propEq('state', state)); + return extend({}, node && node.paramValues); + } + var noInherit = fromPath.map(function (node) { return node.paramSchema; }) + .reduce(unnestR, []) + .filter(function (param) { return !param.inherit; }) + .map(prop('id')); + /** + * Given an [[PathNode]] "toNode", return a new [[PathNode]] with param values inherited from the + * matching node in fromPath. Only inherit keys that aren't found in "toKeys" from the node in "fromPath"" + */ + function makeInheritedParamsNode(toNode) { + // All param values for the node (may include default key/vals, when key was not found in toParams) + var toParamVals = extend({}, toNode && toNode.paramValues); + // limited to only those keys found in toParams + var incomingParamVals = pick(toParamVals, toKeys); + toParamVals = omit(toParamVals, toKeys); + var fromParamVals = omit(nodeParamVals(fromPath, toNode.state) || {}, noInherit); + // extend toParamVals with any fromParamVals, then override any of those those with incomingParamVals + var ownParamVals = extend(toParamVals, fromParamVals, incomingParamVals); + return new PathNode(toNode.state).applyRawParams(ownParamVals); + } + // The param keys specified by the incoming toParams + return toPath.map(makeInheritedParamsNode); + }; + /** + * Computes the tree changes (entering, exiting) between a fromPath and toPath. + */ + PathUtils.treeChanges = function (fromPath, toPath, reloadState) { + var keep = 0, max = Math.min(fromPath.length, toPath.length); + var nodesMatch = function (node1, node2) { + return node1.equals(node2, PathUtils.nonDynamicParams); + }; + while (keep < max && fromPath[keep].state !== reloadState && nodesMatch(fromPath[keep], toPath[keep])) { + keep++; + } + /** Given a retained node, return a new node which uses the to node's param values */ + function applyToParams(retainedNode, idx) { + var cloned = PathNode.clone(retainedNode); + cloned.paramValues = toPath[idx].paramValues; + return cloned; + } + var from, retained, exiting, entering, to; + from = fromPath; + retained = from.slice(0, keep); + exiting = from.slice(keep); + // Create a new retained path (with shallow copies of nodes) which have the params of the toPath mapped + var retainedWithToParams = retained.map(applyToParams); + entering = toPath.slice(keep); + to = (retainedWithToParams).concat(entering); + return { from: from, to: to, retained: retained, exiting: exiting, entering: entering }; + }; + /** + * Returns a new path which is: the subpath of the first path which matches the second path. + * + * The new path starts from root and contains any nodes that match the nodes in the second path. + * It stops before the first non-matching node. + * + * Nodes are compared using their state property and their parameter values. + * If a `paramsFn` is provided, only the [[Param]] returned by the function will be considered when comparing nodes. + * + * @param pathA the first path + * @param pathB the second path + * @param paramsFn a function which returns the parameters to consider when comparing + * + * @returns an array of PathNodes from the first path which match the nodes in the second path + */ + PathUtils.matching = function (pathA, pathB, paramsFn) { + var done = false; + var tuples = arrayTuples(pathA, pathB); + return tuples.reduce(function (matching, _a) { + var nodeA = _a[0], nodeB = _a[1]; + done = done || !nodeA.equals(nodeB, paramsFn); + return done ? matching : matching.concat(nodeA); + }, []); + }; + /** + * Returns true if two paths are identical. + * + * @param pathA + * @param pathB + * @param paramsFn a function which returns the parameters to consider when comparing + * @returns true if the the states and parameter values for both paths are identical + */ + PathUtils.equals = function (pathA, pathB, paramsFn) { + return pathA.length === pathB.length && + PathUtils.matching(pathA, pathB, paramsFn).length === pathA.length; + }; + /** + * Return a subpath of a path, which stops at the first matching node + * + * Given an array of nodes, returns a subset of the array starting from the first node, + * stopping when the first node matches the predicate. + * + * @param path a path of [[PathNode]]s + * @param predicate a [[Predicate]] fn that matches [[PathNode]]s + * @returns a subpath up to the matching node, or undefined if no match is found + */ + PathUtils.subPath = function (path, predicate) { + var node = find(path, predicate); + var elementIdx = path.indexOf(node); + return elementIdx === -1 ? undefined : path.slice(0, elementIdx + 1); + }; + PathUtils.nonDynamicParams = function (node) { + return node.state.parameters({ inherit: false }) + .filter(function (param) { return !param.dynamic; }); + }; + /** Gets the raw parameter values from a path */ + PathUtils.paramValues = function (path) { + return path.reduce(function (acc, node) { return extend(acc, node.paramValues); }, {}); + }; + return PathUtils; +}()); + +/** + * @coreapi + * @module resolve + */ /** for typedoc */ +// TODO: explicitly make this user configurable +var defaultResolvePolicy = { + when: "LAZY", + async: "WAIT" +}; +/** + * The basic building block for the resolve system. + * + * Resolvables encapsulate a state's resolve's resolveFn, the resolveFn's declared dependencies, the wrapped (.promise), + * and the unwrapped-when-complete (.data) result of the resolveFn. + * + * Resolvable.get() either retrieves the Resolvable's existing promise, or else invokes resolve() (which invokes the + * resolveFn) and returns the resulting promise. + * + * Resolvable.get() and Resolvable.resolve() both execute within a context path, which is passed as the first + * parameter to those fns. + */ +var Resolvable = /** @class */ (function () { + function Resolvable(arg1, resolveFn, deps, policy, data) { + this.resolved = false; + this.promise = undefined; + if (arg1 instanceof Resolvable) { + extend(this, arg1); + } + else if (isFunction(resolveFn)) { + if (isNullOrUndefined(arg1)) + throw new Error("new Resolvable(): token argument is required"); + if (!isFunction(resolveFn)) + throw new Error("new Resolvable(): resolveFn argument must be a function"); + this.token = arg1; + this.policy = policy; + this.resolveFn = resolveFn; + this.deps = deps || []; + this.data = data; + this.resolved = data !== undefined; + this.promise = this.resolved ? services.$q.when(this.data) : undefined; + } + else if (isObject(arg1) && arg1.token && isFunction(arg1.resolveFn)) { + var literal = arg1; + return new Resolvable(literal.token, literal.resolveFn, literal.deps, literal.policy, literal.data); + } + } + Resolvable.prototype.getPolicy = function (state) { + var thisPolicy = this.policy || {}; + var statePolicy = state && state.resolvePolicy || {}; + return { + when: thisPolicy.when || statePolicy.when || defaultResolvePolicy.when, + async: thisPolicy.async || statePolicy.async || defaultResolvePolicy.async, + }; + }; + /** + * Asynchronously resolve this Resolvable's data + * + * Given a ResolveContext that this Resolvable is found in: + * Wait for this Resolvable's dependencies, then invoke this Resolvable's function + * and update the Resolvable's state + */ + Resolvable.prototype.resolve = function (resolveContext, trans) { + var _this = this; + var $q = services.$q; + // Gets all dependencies from ResolveContext and wait for them to be resolved + var getResolvableDependencies = function () { + return $q.all(resolveContext.getDependencies(_this).map(function (resolvable) { + return resolvable.get(resolveContext, trans); + })); + }; + // Invokes the resolve function passing the resolved dependencies as arguments + var invokeResolveFn = function (resolvedDeps) { + return _this.resolveFn.apply(null, resolvedDeps); + }; + /** + * For RXWAIT policy: + * + * Given an observable returned from a resolve function: + * - enables .cache() mode (this allows multicast subscribers) + * - then calls toPromise() (this triggers subscribe() and thus fetches) + * - Waits for the promise, then return the cached observable (not the first emitted value). + */ + var waitForRx = function (observable$) { + var cached = observable$.cache(1); + return cached.take(1).toPromise().then(function () { return cached; }); + }; + // If the resolve policy is RXWAIT, wait for the observable to emit something. otherwise pass through. + var node = resolveContext.findNode(this); + var state = node && node.state; + var maybeWaitForRx = this.getPolicy(state).async === "RXWAIT" ? waitForRx : identity; + // After the final value has been resolved, update the state of the Resolvable + var applyResolvedValue = function (resolvedValue) { + _this.data = resolvedValue; + _this.resolved = true; + trace.traceResolvableResolved(_this, trans); + return _this.data; + }; + // Sets the promise property first, then getsResolvableDependencies in the context of the promise chain. Always waits one tick. + return this.promise = $q.when() + .then(getResolvableDependencies) + .then(invokeResolveFn) + .then(maybeWaitForRx) + .then(applyResolvedValue); + }; + /** + * Gets a promise for this Resolvable's data. + * + * Fetches the data and returns a promise. + * Returns the existing promise if it has already been fetched once. + */ + Resolvable.prototype.get = function (resolveContext, trans) { + return this.promise || this.resolve(resolveContext, trans); + }; + Resolvable.prototype.toString = function () { + return "Resolvable(token: " + stringify(this.token) + ", requires: [" + this.deps.map(stringify) + "])"; + }; + Resolvable.prototype.clone = function () { + return new Resolvable(this); + }; + Resolvable.fromData = function (token, data) { + return new Resolvable(token, function () { return data; }, null, null, data); + }; + return Resolvable; +}()); + +/** @internalapi */ +var resolvePolicies = { + when: { + LAZY: "LAZY", + EAGER: "EAGER" + }, + async: { + WAIT: "WAIT", + NOWAIT: "NOWAIT", + RXWAIT: "RXWAIT" + } +}; + +/** @module resolve */ +/** for typedoc */ +var whens = resolvePolicies.when; +var ALL_WHENS = [whens.EAGER, whens.LAZY]; +var EAGER_WHENS = [whens.EAGER]; +var NATIVE_INJECTOR_TOKEN = "Native Injector"; +/** + * Encapsulates Dependency Injection for a path of nodes + * + * UI-Router states are organized as a tree. + * A nested state has a path of ancestors to the root of the tree. + * When a state is being activated, each element in the path is wrapped as a [[PathNode]]. + * A `PathNode` is a stateful object that holds things like parameters and resolvables for the state being activated. + * + * The ResolveContext closes over the [[PathNode]]s, and provides DI for the last node in the path. + */ +var ResolveContext = /** @class */ (function () { + function ResolveContext(_path) { + this._path = _path; + } + /** Gets all the tokens found in the resolve context, de-duplicated */ + ResolveContext.prototype.getTokens = function () { + return this._path.reduce(function (acc, node) { return acc.concat(node.resolvables.map(function (r) { return r.token; })); }, []).reduce(uniqR, []); + }; + /** + * Gets the Resolvable that matches the token + * + * Gets the last Resolvable that matches the token in this context, or undefined. + * Throws an error if it doesn't exist in the ResolveContext + */ + ResolveContext.prototype.getResolvable = function (token) { + var matching = this._path.map(function (node) { return node.resolvables; }) + .reduce(unnestR, []) + .filter(function (r) { return r.token === token; }); + return tail(matching); + }; + /** Returns the [[ResolvePolicy]] for the given [[Resolvable]] */ + ResolveContext.prototype.getPolicy = function (resolvable) { + var node = this.findNode(resolvable); + return resolvable.getPolicy(node.state); + }; + /** + * Returns a ResolveContext that includes a portion of this one + * + * Given a state, this method creates a new ResolveContext from this one. + * The new context starts at the first node (root) and stops at the node for the `state` parameter. + * + * #### Why + * + * When a transition is created, the nodes in the "To Path" are injected from a ResolveContext. + * A ResolveContext closes over a path of [[PathNode]]s and processes the resolvables. + * The "To State" can inject values from its own resolvables, as well as those from all its ancestor state's (node's). + * This method is used to create a narrower context when injecting ancestor nodes. + * + * @example + * `let ABCD = new ResolveContext([A, B, C, D]);` + * + * Given a path `[A, B, C, D]`, where `A`, `B`, `C` and `D` are nodes for states `a`, `b`, `c`, `d`: + * When injecting `D`, `D` should have access to all resolvables from `A`, `B`, `C`, `D`. + * However, `B` should only be able to access resolvables from `A`, `B`. + * + * When resolving for the `B` node, first take the full "To Path" Context `[A,B,C,D]` and limit to the subpath `[A,B]`. + * `let AB = ABCD.subcontext(a)` + */ + ResolveContext.prototype.subContext = function (state) { + return new ResolveContext(PathUtils.subPath(this._path, function (node) { return node.state === state; })); + }; + /** + * Adds Resolvables to the node that matches the state + * + * This adds a [[Resolvable]] (generally one created on the fly; not declared on a [[StateDeclaration.resolve]] block). + * The resolvable is added to the node matching the `state` parameter. + * + * These new resolvables are not automatically fetched. + * The calling code should either fetch them, fetch something that depends on them, + * or rely on [[resolvePath]] being called when some state is being entered. + * + * Note: each resolvable's [[ResolvePolicy]] is merged with the state's policy, and the global default. + * + * @param newResolvables the new Resolvables + * @param state Used to find the node to put the resolvable on + */ + ResolveContext.prototype.addResolvables = function (newResolvables, state) { + var node = find(this._path, propEq('state', state)); + var keys = newResolvables.map(function (r) { return r.token; }); + node.resolvables = node.resolvables.filter(function (r) { return keys.indexOf(r.token) === -1; }).concat(newResolvables); + }; + /** + * Returns a promise for an array of resolved path Element promises + * + * @param when + * @param trans + * @returns {Promise|any} + */ + ResolveContext.prototype.resolvePath = function (when, trans) { + var _this = this; + if (when === void 0) { when = "LAZY"; } + // This option determines which 'when' policy Resolvables we are about to fetch. + var whenOption = inArray(ALL_WHENS, when) ? when : "LAZY"; + // If the caller specified EAGER, only the EAGER Resolvables are fetched. + // if the caller specified LAZY, both EAGER and LAZY Resolvables are fetched.` + var matchedWhens = whenOption === resolvePolicies.when.EAGER ? EAGER_WHENS : ALL_WHENS; + // get the subpath to the state argument, if provided + trace.traceResolvePath(this._path, when, trans); + var matchesPolicy = function (acceptedVals, whenOrAsync) { + return function (resolvable) { + return inArray(acceptedVals, _this.getPolicy(resolvable)[whenOrAsync]); + }; + }; + // Trigger all the (matching) Resolvables in the path + // Reduce all the "WAIT" Resolvables into an array + var promises = this._path.reduce(function (acc, node) { + var nodeResolvables = node.resolvables.filter(matchesPolicy(matchedWhens, 'when')); + var nowait = nodeResolvables.filter(matchesPolicy(['NOWAIT'], 'async')); + var wait = nodeResolvables.filter(not(matchesPolicy(['NOWAIT'], 'async'))); + // For the matching Resolvables, start their async fetch process. + var subContext = _this.subContext(node.state); + var getResult = function (r) { return r.get(subContext, trans) + .then(function (value) { return ({ token: r.token, value: value }); }); }; + nowait.forEach(getResult); + return acc.concat(wait.map(getResult)); + }, []); + // Wait for all the "WAIT" resolvables + return services.$q.all(promises); + }; + ResolveContext.prototype.injector = function () { + return this._injector || (this._injector = new UIInjectorImpl(this)); + }; + ResolveContext.prototype.findNode = function (resolvable) { + return find(this._path, function (node) { return inArray(node.resolvables, resolvable); }); + }; + /** + * Gets the async dependencies of a Resolvable + * + * Given a Resolvable, returns its dependencies as a Resolvable[] + */ + ResolveContext.prototype.getDependencies = function (resolvable) { + var _this = this; + var node = this.findNode(resolvable); + // Find which other resolvables are "visible" to the `resolvable` argument + // subpath stopping at resolvable's node, or the whole path (if the resolvable isn't in the path) + var subPath = PathUtils.subPath(this._path, function (x) { return x === node; }) || this._path; + var availableResolvables = subPath + .reduce(function (acc, _node) { return acc.concat(_node.resolvables); }, []) //all of subpath's resolvables + .filter(function (res) { return res !== resolvable; }); // filter out the `resolvable` argument + var getDependency = function (token) { + var matching = availableResolvables.filter(function (r) { return r.token === token; }); + if (matching.length) + return tail(matching); + var fromInjector = _this.injector().getNative(token); + if (isUndefined(fromInjector)) { + throw new Error("Could not find Dependency Injection token: " + stringify(token)); + } + return new Resolvable(token, function () { return fromInjector; }, [], fromInjector); + }; + return resolvable.deps.map(getDependency); + }; + return ResolveContext; +}()); +var UIInjectorImpl = /** @class */ (function () { + function UIInjectorImpl(context) { + this.context = context; + this.native = this.get(NATIVE_INJECTOR_TOKEN) || services.$injector; + } + UIInjectorImpl.prototype.get = function (token) { + var resolvable = this.context.getResolvable(token); + if (resolvable) { + if (this.context.getPolicy(resolvable).async === 'NOWAIT') { + return resolvable.get(this.context); + } + if (!resolvable.resolved) { + throw new Error("Resolvable async .get() not complete:" + stringify(resolvable.token)); + } + return resolvable.data; + } + return this.getNative(token); + }; + UIInjectorImpl.prototype.getAsync = function (token) { + var resolvable = this.context.getResolvable(token); + if (resolvable) + return resolvable.get(this.context); + return services.$q.when(this.native.get(token)); + }; + UIInjectorImpl.prototype.getNative = function (token) { + return this.native && this.native.get(token); + }; + return UIInjectorImpl; +}()); + +/** + * @coreapi + * @module transition + */ +/** for typedoc */ +/** @hidden */ +var stateSelf = prop("self"); +/** + * Represents a transition between two states. + * + * When navigating to a state, we are transitioning **from** the current state **to** the new state. + * + * This object contains all contextual information about the to/from states, parameters, resolves. + * It has information about all states being entered and exited as a result of the transition. + */ +var Transition = /** @class */ (function () { + /** + * Creates a new Transition object. + * + * If the target state is not valid, an error is thrown. + * + * @internalapi + * + * @param fromPath The path of [[PathNode]]s from which the transition is leaving. The last node in the `fromPath` + * encapsulates the "from state". + * @param targetState The target state and parameters being transitioned to (also, the transition options) + * @param router The [[UIRouter]] instance + */ + function Transition(fromPath, targetState, router) { + var _this = this; + /** @hidden */ + this._deferred = services.$q.defer(); + /** + * This promise is resolved or rejected based on the outcome of the Transition. + * + * When the transition is successful, the promise is resolved + * When the transition is unsuccessful, the promise is rejected with the [[Rejection]] or javascript error + */ + this.promise = this._deferred.promise; + /** @hidden Holds the hook registration functions such as those passed to Transition.onStart() */ + this._registeredHooks = {}; + /** @hidden */ + this._hookBuilder = new HookBuilder(this); + /** Checks if this transition is currently active/running. */ + this.isActive = function () { + return _this.router.globals.transition === _this; + }; + this.router = router; + this._targetState = targetState; + if (!targetState.valid()) { + throw new Error(targetState.error()); + } + // current() is assumed to come from targetState.options, but provide a naive implementation otherwise. + this._options = extend({ current: val(this) }, targetState.options()); + this.$id = router.transitionService._transitionCount++; + var toPath = PathUtils.buildToPath(fromPath, targetState); + this._treeChanges = PathUtils.treeChanges(fromPath, toPath, this._options.reloadState); + this.createTransitionHookRegFns(); + var onCreateHooks = this._hookBuilder.buildHooksForPhase(exports.TransitionHookPhase.CREATE); + TransitionHook.invokeHooks(onCreateHooks, function () { return null; }); + this.applyViewConfigs(router); + } + /** @hidden */ + Transition.prototype.onBefore = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onStart = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onExit = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onRetain = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onEnter = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onFinish = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onSuccess = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + Transition.prototype.onError = function (criteria, callback, options) { return; }; + /** @hidden + * Creates the transition-level hook registration functions + * (which can then be used to register hooks) + */ + Transition.prototype.createTransitionHookRegFns = function () { + var _this = this; + this.router.transitionService._pluginapi._getEvents() + .filter(function (type) { return type.hookPhase !== exports.TransitionHookPhase.CREATE; }) + .forEach(function (type) { return makeEvent(_this, _this.router.transitionService, type); }); + }; + /** @internalapi */ + Transition.prototype.getHooks = function (hookName) { + return this._registeredHooks[hookName]; + }; + Transition.prototype.applyViewConfigs = function (router) { + var enteringStates = this._treeChanges.entering.map(function (node) { return node.state; }); + PathUtils.applyViewConfigs(router.transitionService.$view, this._treeChanges.to, enteringStates); + }; + /** + * @internalapi + * + * @returns the internal from [State] object + */ + Transition.prototype.$from = function () { + return tail(this._treeChanges.from).state; + }; + /** + * @internalapi + * + * @returns the internal to [State] object + */ + Transition.prototype.$to = function () { + return tail(this._treeChanges.to).state; + }; + /** + * Returns the "from state" + * + * Returns the state that the transition is coming *from*. + * + * @returns The state declaration object for the Transition's ("from state"). + */ + Transition.prototype.from = function () { + return this.$from().self; + }; + /** + * Returns the "to state" + * + * Returns the state that the transition is going *to*. + * + * @returns The state declaration object for the Transition's target state ("to state"). + */ + Transition.prototype.to = function () { + return this.$to().self; + }; + /** + * Gets the Target State + * + * A transition's [[TargetState]] encapsulates the [[to]] state, the [[params]], and the [[options]] as a single object. + * + * @returns the [[TargetState]] of this Transition + */ + Transition.prototype.targetState = function () { + return this._targetState; + }; + /** + * Determines whether two transitions are equivalent. + * @deprecated + */ + Transition.prototype.is = function (compare) { + if (compare instanceof Transition) { + // TODO: Also compare parameters + return this.is({ to: compare.$to().name, from: compare.$from().name }); + } + return !((compare.to && !matchState(this.$to(), compare.to)) || + (compare.from && !matchState(this.$from(), compare.from))); + }; + Transition.prototype.params = function (pathname) { + if (pathname === void 0) { pathname = "to"; } + return Object.freeze(this._treeChanges[pathname].map(prop("paramValues")).reduce(mergeR, {})); + }; + /** + * Creates a [[UIInjector]] Dependency Injector + * + * Returns a Dependency Injector for the Transition's target state (to state). + * The injector provides resolve values which the target state has access to. + * + * The `UIInjector` can also provide values from the native root/global injector (ng1/ng2). + * + * #### Example: + * ```js + * .onEnter({ entering: 'myState' }, trans => { + * var myResolveValue = trans.injector().get('myResolve'); + * // Inject a global service from the global/native injector (if it exists) + * var MyService = trans.injector().get('MyService'); + * }) + * ``` + * + * In some cases (such as `onBefore`), you may need access to some resolve data but it has not yet been fetched. + * You can use [[UIInjector.getAsync]] to get a promise for the data. + * #### Example: + * ```js + * .onBefore({}, trans => { + * return trans.injector().getAsync('myResolve').then(myResolveValue => + * return myResolveValue !== 'ABORT'; + * }); + * }); + * ``` + * + * If a `state` is provided, the injector that is returned will be limited to resolve values that the provided state has access to. + * This can be useful if both a parent state `foo` and a child state `foo.bar` have both defined a resolve such as `data`. + * #### Example: + * ```js + * .onEnter({ to: 'foo.bar' }, trans => { + * // returns result of `foo` state's `data` resolve + * // even though `foo.bar` also has a `data` resolve + * var fooData = trans.injector('foo').get('data'); + * }); + * ``` + * + * If you need resolve data from the exiting states, pass `'from'` as `pathName`. + * The resolve data from the `from` path will be returned. + * #### Example: + * ```js + * .onExit({ exiting: 'foo.bar' }, trans => { + * // Gets the resolve value of `data` from the exiting state. + * var fooData = trans.injector(null, 'foo.bar').get('data'); + * }); + * ``` + * + * + * @param state Limits the resolves provided to only the resolves the provided state has access to. + * @param pathName Default: `'to'`: Chooses the path for which to create the injector. Use this to access resolves for `exiting` states. + * + * @returns a [[UIInjector]] + */ + Transition.prototype.injector = function (state, pathName) { + if (pathName === void 0) { pathName = "to"; } + var path = this._treeChanges[pathName]; + if (state) + path = PathUtils.subPath(path, function (node) { return node.state === state || node.state.name === state; }); + return new ResolveContext(path).injector(); + }; + /** + * Gets all available resolve tokens (keys) + * + * This method can be used in conjunction with [[injector]] to inspect the resolve values + * available to the Transition. + * + * This returns all the tokens defined on [[StateDeclaration.resolve]] blocks, for the states + * in the Transition's [[TreeChanges.to]] path. + * + * #### Example: + * This example logs all resolve values + * ```js + * let tokens = trans.getResolveTokens(); + * tokens.forEach(token => console.log(token + " = " + trans.injector().get(token))); + * ``` + * + * #### Example: + * This example creates promises for each resolve value. + * This triggers fetches of resolves (if any have not yet been fetched). + * When all promises have all settled, it logs the resolve values. + * ```js + * let tokens = trans.getResolveTokens(); + * let promise = tokens.map(token => trans.injector().getAsync(token)); + * Promise.all(promises).then(values => console.log("Resolved values: " + values)); + * ``` + * + * Note: Angular 1 users whould use `$q.all()` + * + * @param pathname resolve context's path name (e.g., `to` or `from`) + * + * @returns an array of resolve tokens (keys) + */ + Transition.prototype.getResolveTokens = function (pathname) { + if (pathname === void 0) { pathname = "to"; } + return new ResolveContext(this._treeChanges[pathname]).getTokens(); + }; + /** + * Dynamically adds a new [[Resolvable]] (i.e., [[StateDeclaration.resolve]]) to this transition. + * + * #### Example: + * ```js + * transitionService.onBefore({}, transition => { + * transition.addResolvable({ + * token: 'myResolve', + * deps: ['MyService'], + * resolveFn: myService => myService.getData() + * }); + * }); + * ``` + * + * @param resolvable a [[ResolvableLiteral]] object (or a [[Resolvable]]) + * @param state the state in the "to path" which should receive the new resolve (otherwise, the root state) + */ + Transition.prototype.addResolvable = function (resolvable, state) { + if (state === void 0) { state = ""; } + resolvable = is(Resolvable)(resolvable) ? resolvable : new Resolvable(resolvable); + var stateName = (typeof state === "string") ? state : state.name; + var topath = this._treeChanges.to; + var targetNode = find(topath, function (node) { return node.state.name === stateName; }); + var resolveContext = new ResolveContext(topath); + resolveContext.addResolvables([resolvable], targetNode.state); + }; + /** + * Gets the transition from which this transition was redirected. + * + * If the current transition is a redirect, this method returns the transition that was redirected. + * + * #### Example: + * ```js + * let transitionA = $state.go('A').transition + * transitionA.onStart({}, () => $state.target('B')); + * $transitions.onSuccess({ to: 'B' }, (trans) => { + * trans.to().name === 'B'; // true + * trans.redirectedFrom() === transitionA; // true + * }); + * ``` + * + * @returns The previous Transition, or null if this Transition is not the result of a redirection + */ + Transition.prototype.redirectedFrom = function () { + return this._options.redirectedFrom || null; + }; + /** + * Gets the original transition in a redirect chain + * + * A transition might belong to a long chain of multiple redirects. + * This method walks the [[redirectedFrom]] chain back to the original (first) transition in the chain. + * + * #### Example: + * ```js + * // states + * registry.register({ name: 'A', redirectTo: 'B' }); + * registry.register({ name: 'B', redirectTo: 'C' }); + * registry.register({ name: 'C', redirectTo: 'D' }); + * registry.register({ name: 'D' }); + * + * let transitionA = $state.go('A').transition + * + * $transitions.onSuccess({ to: 'D' }, (trans) => { + * trans.to().name === 'D'; // true + * trans.redirectedFrom().to().name === 'C'; // true + * trans.originalTransition() === transitionA; // true + * trans.originalTransition().to().name === 'A'; // true + * }); + * ``` + * + * @returns The original Transition that started a redirect chain + */ + Transition.prototype.originalTransition = function () { + var rf = this.redirectedFrom(); + return (rf && rf.originalTransition()) || this; + }; + /** + * Get the transition options + * + * @returns the options for this Transition. + */ + Transition.prototype.options = function () { + return this._options; + }; + /** + * Gets the states being entered. + * + * @returns an array of states that will be entered during this transition. + */ + Transition.prototype.entering = function () { + return map(this._treeChanges.entering, prop('state')).map(stateSelf); + }; + /** + * Gets the states being exited. + * + * @returns an array of states that will be exited during this transition. + */ + Transition.prototype.exiting = function () { + return map(this._treeChanges.exiting, prop('state')).map(stateSelf).reverse(); + }; + /** + * Gets the states being retained. + * + * @returns an array of states that are already entered from a previous Transition, that will not be + * exited during this Transition + */ + Transition.prototype.retained = function () { + return map(this._treeChanges.retained, prop('state')).map(stateSelf); + }; + /** + * Get the [[ViewConfig]]s associated with this Transition + * + * Each state can define one or more views (template/controller), which are encapsulated as `ViewConfig` objects. + * This method fetches the `ViewConfigs` for a given path in the Transition (e.g., "to" or "entering"). + * + * @param pathname the name of the path to fetch views for: + * (`'to'`, `'from'`, `'entering'`, `'exiting'`, `'retained'`) + * @param state If provided, only returns the `ViewConfig`s for a single state in the path + * + * @returns a list of ViewConfig objects for the given path. + */ + Transition.prototype.views = function (pathname, state) { + if (pathname === void 0) { pathname = "entering"; } + var path = this._treeChanges[pathname]; + path = !state ? path : path.filter(propEq('state', state)); + return path.map(prop("views")).filter(identity).reduce(unnestR, []); + }; + Transition.prototype.treeChanges = function (pathname) { + return pathname ? this._treeChanges[pathname] : this._treeChanges; + }; + /** + * Creates a new transition that is a redirection of the current one. + * + * This transition can be returned from a [[TransitionService]] hook to + * redirect a transition to a new state and/or set of parameters. + * + * @internalapi + * + * @returns Returns a new [[Transition]] instance. + */ + Transition.prototype.redirect = function (targetState) { + var redirects = 1, trans = this; + while ((trans = trans.redirectedFrom()) != null) { + if (++redirects > 20) + throw new Error("Too many consecutive Transition redirects (20+)"); + } + var redirectOpts = { redirectedFrom: this, source: "redirect" }; + // If the original transition was caused by URL sync, then use { location: 'replace' } + // on the new transition (unless the target state explicitly specifies location: false). + // This causes the original url to be replaced with the url for the redirect target + // so the original url disappears from the browser history. + if (this.options().source === 'url' && targetState.options().location !== false) { + redirectOpts.location = 'replace'; + } + var newOptions = extend({}, this.options(), targetState.options(), redirectOpts); + targetState = targetState.withOptions(newOptions, true); + var newTransition = this.router.transitionService.create(this._treeChanges.from, targetState); + var originalEnteringNodes = this._treeChanges.entering; + var redirectEnteringNodes = newTransition._treeChanges.entering; + // --- Re-use resolve data from original transition --- + // When redirecting from a parent state to a child state where the parent parameter values haven't changed + // (because of the redirect), the resolves fetched by the original transition are still valid in the + // redirected transition. + // + // This allows you to define a redirect on a parent state which depends on an async resolve value. + // You can wait for the resolve, then redirect to a child state based on the result. + // The redirected transition does not have to re-fetch the resolve. + // --------------------------------------------------------- + var nodeIsReloading = function (reloadState) { return function (node) { + return reloadState && node.state.includes[reloadState.name]; + }; }; + // Find any "entering" nodes in the redirect path that match the original path and aren't being reloaded + var matchingEnteringNodes = PathUtils.matching(redirectEnteringNodes, originalEnteringNodes, PathUtils.nonDynamicParams) + .filter(not(nodeIsReloading(targetState.options().reloadState))); + // Use the existing (possibly pre-resolved) resolvables for the matching entering nodes. + matchingEnteringNodes.forEach(function (node, idx) { + node.resolvables = originalEnteringNodes[idx].resolvables; + }); + return newTransition; + }; + /** @hidden If a transition doesn't exit/enter any states, returns any [[Param]] whose value changed */ + Transition.prototype._changedParams = function () { + var tc = this._treeChanges; + /** Return undefined if it's not a "dynamic" transition, for the following reasons */ + // If user explicitly wants a reload + if (this._options.reload) + return undefined; + // If any states are exiting or entering + if (tc.exiting.length || tc.entering.length) + return undefined; + // If to/from path lengths differ + if (tc.to.length !== tc.from.length) + return undefined; + // If the to/from paths are different + var pathsDiffer = arrayTuples(tc.to, tc.from) + .map(function (tuple) { return tuple[0].state !== tuple[1].state; }) + .reduce(anyTrueR, false); + if (pathsDiffer) + return undefined; + // Find any parameter values that differ + var nodeSchemas = tc.to.map(function (node) { return node.paramSchema; }); + var _a = [tc.to, tc.from].map(function (path) { return path.map(function (x) { return x.paramValues; }); }), toValues = _a[0], fromValues = _a[1]; + var tuples = arrayTuples(nodeSchemas, toValues, fromValues); + return tuples.map(function (_a) { + var schema = _a[0], toVals = _a[1], fromVals = _a[2]; + return Param.changed(schema, toVals, fromVals); + }).reduce(unnestR, []); + }; + /** + * Returns true if the transition is dynamic. + * + * A transition is dynamic if no states are entered nor exited, but at least one dynamic parameter has changed. + * + * @returns true if the Transition is dynamic + */ + Transition.prototype.dynamic = function () { + var changes = this._changedParams(); + return !changes ? false : changes.map(function (x) { return x.dynamic; }).reduce(anyTrueR, false); + }; + /** + * Returns true if the transition is ignored. + * + * A transition is ignored if no states are entered nor exited, and no parameter values have changed. + * + * @returns true if the Transition is ignored. + */ + Transition.prototype.ignored = function () { + return !!this._ignoredReason(); + }; + /** @hidden */ + Transition.prototype._ignoredReason = function () { + var pending = this.router.globals.transition; + var reloadState = this._options.reloadState; + var same = function (pathA, pathB) { + if (pathA.length !== pathB.length) + return false; + var matching = PathUtils.matching(pathA, pathB); + return pathA.length === matching.filter(function (node) { return !reloadState || !node.state.includes[reloadState.name]; }).length; + }; + var newTC = this.treeChanges(); + var pendTC = pending && pending.treeChanges(); + if (pendTC && same(pendTC.to, newTC.to) && same(pendTC.exiting, newTC.exiting)) + return "SameAsPending"; + if (newTC.exiting.length === 0 && newTC.entering.length === 0 && same(newTC.from, newTC.to)) + return "SameAsCurrent"; + }; + /** + * Runs the transition + * + * This method is generally called from the [[StateService.transitionTo]] + * + * @internalapi + * + * @returns a promise for a successful transition. + */ + Transition.prototype.run = function () { + var _this = this; + var runAllHooks = TransitionHook.runAllHooks; + // Gets transition hooks array for the given phase + var getHooksFor = function (phase) { + return _this._hookBuilder.buildHooksForPhase(phase); + }; + // When the chain is complete, then resolve or reject the deferred + var transitionSuccess = function () { + trace.traceSuccess(_this.$to(), _this); + _this.success = true; + _this._deferred.resolve(_this.to()); + runAllHooks(getHooksFor(exports.TransitionHookPhase.SUCCESS)); + }; + var transitionError = function (reason) { + trace.traceError(reason, _this); + _this.success = false; + _this._deferred.reject(reason); + _this._error = reason; + runAllHooks(getHooksFor(exports.TransitionHookPhase.ERROR)); + }; + var runTransition = function () { + // Wait to build the RUN hook chain until the BEFORE hooks are done + // This allows a BEFORE hook to dynamically add additional RUN hooks via the Transition object. + var allRunHooks = getHooksFor(exports.TransitionHookPhase.RUN); + var done = function () { return services.$q.when(undefined); }; + return TransitionHook.invokeHooks(allRunHooks, done); + }; + var startTransition = function () { + var globals = _this.router.globals; + globals.lastStartedTransitionId = _this.$id; + globals.transition = _this; + globals.transitionHistory.enqueue(_this); + trace.traceTransitionStart(_this); + return services.$q.when(undefined); + }; + var allBeforeHooks = getHooksFor(exports.TransitionHookPhase.BEFORE); + TransitionHook.invokeHooks(allBeforeHooks, startTransition) + .then(runTransition) + .then(transitionSuccess, transitionError); + return this.promise; + }; + /** + * Checks if the Transition is valid + * + * @returns true if the Transition is valid + */ + Transition.prototype.valid = function () { + return !this.error() || this.success !== undefined; + }; + /** + * Aborts this transition + * + * Imperative API to abort a Transition. + * This only applies to Transitions that are not yet complete. + */ + Transition.prototype.abort = function () { + // Do not set flag if the transition is already complete + if (isUndefined(this.success)) { + this._aborted = true; + } + }; + /** + * The Transition error reason. + * + * If the transition is invalid (and could not be run), returns the reason the transition is invalid. + * If the transition was valid and ran, but was not successful, returns the reason the transition failed. + * + * @returns an error message explaining why the transition is invalid, or the reason the transition failed. + */ + Transition.prototype.error = function () { + var state = this.$to(); + if (state.self.abstract) + return "Cannot transition to abstract state '" + state.name + "'"; + var paramDefs = state.parameters(), values$$1 = this.params(); + var invalidParams = paramDefs.filter(function (param) { return !param.validates(values$$1[param.id]); }); + if (invalidParams.length) { + return "Param values not valid for state '" + state.name + "'. Invalid params: [ " + invalidParams.map(function (param) { return param.id; }).join(', ') + " ]"; + } + if (this.success === false) + return this._error; + }; + /** + * A string representation of the Transition + * + * @returns A string representation of the Transition + */ + Transition.prototype.toString = function () { + var fromStateOrName = this.from(); + var toStateOrName = this.to(); + var avoidEmptyHash = function (params) { + return (params["#"] !== null && params["#"] !== undefined) ? params : omit(params, ["#"]); + }; + // (X) means the to state is invalid. + var id = this.$id, from = isObject(fromStateOrName) ? fromStateOrName.name : fromStateOrName, fromParams = stringify(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))), toValid = this.valid() ? "" : "(X) ", to = isObject(toStateOrName) ? toStateOrName.name : toStateOrName, toParams = stringify(avoidEmptyHash(this.params())); + return "Transition#" + id + "( '" + from + "'" + fromParams + " -> " + toValid + "'" + to + "'" + toParams + " )"; + }; + /** @hidden */ + Transition.diToken = Transition; + return Transition; +}()); + +/** + * Functions that manipulate strings + * + * Although these functions are exported, they are subject to change without notice. + * + * @module common_strings + */ /** */ +/** + * Returns a string shortened to a maximum length + * + * If the string is already less than the `max` length, return the string. + * Else return the string, shortened to `max - 3` and append three dots ("..."). + * + * @param max the maximum length of the string to return + * @param str the input string + */ +function maxLength(max, str) { + if (str.length <= max) + return str; + return str.substr(0, max - 3) + "..."; +} +/** + * Returns a string, with spaces added to the end, up to a desired str length + * + * If the string is already longer than the desired length, return the string. + * Else returns the string, with extra spaces on the end, such that it reaches `length` characters. + * + * @param length the desired length of the string to return + * @param str the input string + */ +function padString(length, str) { + while (str.length < length) + str += " "; + return str; +} +function kebobString(camelCase) { + return camelCase + .replace(/^([A-Z])/, function ($1) { return $1.toLowerCase(); }) // replace first char + .replace(/([A-Z])/g, function ($1) { return "-" + $1.toLowerCase(); }); // replace rest +} +function functionToString(fn) { + var fnStr = fnToString(fn); + var namedFunctionMatch = fnStr.match(/^(function [^ ]+\([^)]*\))/); + var toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr; + var fnName = fn['name'] || ""; + if (fnName && toStr.match(/function \(/)) { + return 'function ' + fnName + toStr.substr(9); + } + return toStr; +} +function fnToString(fn) { + var _fn = isArray(fn) ? fn.slice(-1)[0] : fn; + return _fn && _fn.toString() || "undefined"; +} +var stringifyPatternFn = null; +var stringifyPattern = function (value) { + var isRejection = Rejection.isRejectionPromise; + stringifyPatternFn = stringifyPatternFn || pattern([ + [not(isDefined), val("undefined")], + [isNull, val("null")], + [isPromise, val("[Promise]")], + [isRejection, function (x) { return x._transitionRejection.toString(); }], + [is(Rejection), invoke("toString")], + [is(Transition), invoke("toString")], + [is(Resolvable), invoke("toString")], + [isInjectable, functionToString], + [val(true), identity] + ]); + return stringifyPatternFn(value); +}; +function stringify(o) { + var seen = []; + function format(val$$1) { + if (isObject(val$$1)) { + if (seen.indexOf(val$$1) !== -1) + return '[circular ref]'; + seen.push(val$$1); + } + return stringifyPattern(val$$1); + } + return JSON.stringify(o, function (key, val$$1) { return format(val$$1); }).replace(/\\"/g, '"'); +} +/** Returns a function that splits a string on a character or substring */ +var beforeAfterSubstr = function (char) { return function (str) { + if (!str) + return ["", ""]; + var idx = str.indexOf(char); + if (idx === -1) + return [str, ""]; + return [str.substr(0, idx), str.substr(idx + 1)]; +}; }; +var hostRegex = new RegExp('^(?:[a-z]+:)?//[^/]+/'); +var stripFile = function (str) { return str.replace(/\/[^/]*$/, ''); }; +var splitHash = beforeAfterSubstr("#"); +var splitQuery = beforeAfterSubstr("?"); +var splitEqual = beforeAfterSubstr("="); +var trimHashVal = function (str) { return str ? str.replace(/^#/, "") : ""; }; +/** + * Splits on a delimiter, but returns the delimiters in the array + * + * #### Example: + * ```js + * var splitOnSlashes = splitOnDelim('/'); + * splitOnSlashes("/foo"); // ["/", "foo"] + * splitOnSlashes("/foo/"); // ["/", "foo", "/"] + * ``` + */ +function splitOnDelim(delim) { + var re = new RegExp("(" + delim + ")", "g"); + return function (str) { + return str.split(re).filter(identity); + }; +} + +/** + * Reduce fn that joins neighboring strings + * + * Given an array of strings, returns a new array + * where all neighboring strings have been joined. + * + * #### Example: + * ```js + * let arr = ["foo", "bar", 1, "baz", "", "qux" ]; + * arr.reduce(joinNeighborsR, []) // ["foobar", 1, "bazqux" ] + * ``` + */ +function joinNeighborsR(acc, x) { + if (isString(tail(acc)) && isString(x)) + return acc.slice(0, -1).concat(tail(acc) + x); + return pushR(acc, x); +} + +/** @module common */ /** for typedoc */ + +/** + * @coreapi + * @module params + */ +/** */ +/** + * A registry for parameter types. + * + * This registry manages the built-in (and custom) parameter types. + * + * The built-in parameter types are: + * + * - [[string]] + * - [[path]] + * - [[query]] + * - [[hash]] + * - [[int]] + * - [[bool]] + * - [[date]] + * - [[json]] + * - [[any]] + */ +var ParamTypes = /** @class */ (function () { + /** @internalapi */ + function ParamTypes() { + /** @hidden */ + this.enqueue = true; + /** @hidden */ + this.typeQueue = []; + /** @internalapi */ + this.defaultTypes = pick(ParamTypes.prototype, ["hash", "string", "query", "path", "int", "bool", "date", "json", "any"]); + // Register default types. Store them in the prototype of this.types. + var makeType = function (definition, name) { + return new ParamType(extend({ name: name }, definition)); + }; + this.types = inherit(map(this.defaultTypes, makeType), {}); + } + /** @internalapi */ + ParamTypes.prototype.dispose = function () { + this.types = {}; + }; + /** + * Registers a parameter type + * + * End users should call [[UrlMatcherFactory.type]], which delegates to this method. + */ + ParamTypes.prototype.type = function (name, definition, definitionFn) { + if (!isDefined(definition)) + return this.types[name]; + if (this.types.hasOwnProperty(name)) + throw new Error("A type named '" + name + "' has already been defined."); + this.types[name] = new ParamType(extend({ name: name }, definition)); + if (definitionFn) { + this.typeQueue.push({ name: name, def: definitionFn }); + if (!this.enqueue) + this._flushTypeQueue(); + } + return this; + }; + /** @internalapi */ + ParamTypes.prototype._flushTypeQueue = function () { + while (this.typeQueue.length) { + var type = this.typeQueue.shift(); + if (type.pattern) + throw new Error("You cannot override a type's .pattern at runtime."); + extend(this.types[type.name], services.$injector.invoke(type.def)); + } + }; + return ParamTypes; +}()); +/** @hidden */ +function initDefaultTypes() { + var makeDefaultType = function (def) { + var valToString = function (val$$1) { + return val$$1 != null ? val$$1.toString() : val$$1; + }; + var defaultTypeBase = { + encode: valToString, + decode: valToString, + is: is(String), + pattern: /.*/, + equals: function (a, b) { return a == b; }, + }; + return extend({}, defaultTypeBase, def); + }; + // Default Parameter Type Definitions + extend(ParamTypes.prototype, { + string: makeDefaultType({}), + path: makeDefaultType({ + pattern: /[^/]*/, + }), + query: makeDefaultType({}), + hash: makeDefaultType({ + inherit: false, + }), + int: makeDefaultType({ + decode: function (val$$1) { return parseInt(val$$1, 10); }, + is: function (val$$1) { + return !isNullOrUndefined(val$$1) && this.decode(val$$1.toString()) === val$$1; + }, + pattern: /-?\d+/, + }), + bool: makeDefaultType({ + encode: function (val$$1) { return val$$1 && 1 || 0; }, + decode: function (val$$1) { return parseInt(val$$1, 10) !== 0; }, + is: is(Boolean), + pattern: /0|1/, + }), + date: makeDefaultType({ + encode: function (val$$1) { + return !this.is(val$$1) ? undefined : [ + val$$1.getFullYear(), + ('0' + (val$$1.getMonth() + 1)).slice(-2), + ('0' + val$$1.getDate()).slice(-2), + ].join("-"); + }, + decode: function (val$$1) { + if (this.is(val$$1)) + return val$$1; + var match = this.capture.exec(val$$1); + return match ? new Date(match[1], match[2] - 1, match[3]) : undefined; + }, + is: function (val$$1) { return val$$1 instanceof Date && !isNaN(val$$1.valueOf()); }, + equals: function (l, r) { + return ['getFullYear', 'getMonth', 'getDate'] + .reduce(function (acc, fn) { return acc && l[fn]() === r[fn](); }, true); + }, + pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/, + capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/, + }), + json: makeDefaultType({ + encode: toJson, + decode: fromJson, + is: is(Object), + equals: equals, + pattern: /[^/]*/, + }), + // does not encode/decode + any: makeDefaultType({ + encode: identity, + decode: identity, + is: function () { return true; }, + equals: equals, + }), + }); +} +initDefaultTypes(); + +/** + * @coreapi + * @module params + */ +/** */ +/** @internalapi */ +var StateParams = /** @class */ (function () { + function StateParams(params) { + if (params === void 0) { params = {}; } + extend(this, params); + } + /** + * Merges a set of parameters with all parameters inherited between the common parents of the + * current state and a given destination state. + * + * @param {Object} newParams The set of parameters which will be composited with inherited params. + * @param {Object} $current Internal definition of object representing the current state. + * @param {Object} $to Internal definition of object representing state to transition to. + */ + StateParams.prototype.$inherit = function (newParams, $current, $to) { + var parents = ancestors($current, $to), parentParams, inherited = {}, inheritList = []; + for (var i in parents) { + if (!parents[i] || !parents[i].params) + continue; + parentParams = Object.keys(parents[i].params); + if (!parentParams.length) + continue; + for (var j in parentParams) { + if (inheritList.indexOf(parentParams[j]) >= 0) + continue; + inheritList.push(parentParams[j]); + inherited[parentParams[j]] = this[parentParams[j]]; + } + } + return extend({}, inherited, newParams); + }; + + return StateParams; +}()); + +/** @module path */ /** for typedoc */ + +/** @module resolve */ /** for typedoc */ + +/** @module state */ /** for typedoc */ +var parseUrl = function (url) { + if (!isString(url)) + return false; + var root$$1 = url.charAt(0) === '^'; + return { val: root$$1 ? url.substring(1) : url, root: root$$1 }; +}; +function nameBuilder(state) { + return state.name; +} +function selfBuilder(state) { + state.self.$$state = function () { return state; }; + return state.self; +} +function dataBuilder(state) { + if (state.parent && state.parent.data) { + state.data = state.self.data = inherit(state.parent.data, state.data); + } + return state.data; +} +var getUrlBuilder = function ($urlMatcherFactoryProvider, root$$1) { + return function urlBuilder(state) { + var stateDec = state; + // For future states, i.e., states whose name ends with `.**`, + // match anything that starts with the url prefix + if (stateDec && stateDec.url && stateDec.name && stateDec.name.match(/\.\*\*$/)) { + stateDec.url += "{remainder:any}"; // match any path (.*) + } + var parsed = parseUrl(stateDec.url), parent = state.parent; + var url = !parsed ? stateDec.url : $urlMatcherFactoryProvider.compile(parsed.val, { + params: state.params || {}, + paramMap: function (paramConfig, isSearch) { + if (stateDec.reloadOnSearch === false && isSearch) + paramConfig = extend(paramConfig || {}, { dynamic: true }); + return paramConfig; + } + }); + if (!url) + return null; + if (!$urlMatcherFactoryProvider.isMatcher(url)) + throw new Error("Invalid url '" + url + "' in state '" + state + "'"); + return (parsed && parsed.root) ? url : ((parent && parent.navigable) || root$$1()).url.append(url); + }; +}; +var getNavigableBuilder = function (isRoot) { + return function navigableBuilder(state) { + return !isRoot(state) && state.url ? state : (state.parent ? state.parent.navigable : null); + }; +}; +var getParamsBuilder = function (paramFactory) { + return function paramsBuilder(state) { + var makeConfigParam = function (config, id) { return paramFactory.fromConfig(id, null, config); }; + var urlParams = (state.url && state.url.parameters({ inherit: false })) || []; + var nonUrlParams = values(mapObj(omit(state.params || {}, urlParams.map(prop('id'))), makeConfigParam)); + return urlParams.concat(nonUrlParams).map(function (p) { return [p.id, p]; }).reduce(applyPairs, {}); + }; +}; +function pathBuilder(state) { + return state.parent ? state.parent.path.concat(state) : /*root*/ [state]; +} +function includesBuilder(state) { + var includes = state.parent ? extend({}, state.parent.includes) : {}; + includes[state.name] = true; + return includes; +} +/** + * This is a [[StateBuilder.builder]] function for the `resolve:` block on a [[StateDeclaration]]. + * + * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder + * validates the `resolve` property and converts it to a [[Resolvable]] array. + * + * resolve: input value can be: + * + * { + * // analyzed but not injected + * myFooResolve: function() { return "myFooData"; }, + * + * // function.toString() parsed, "DependencyName" dep as string (not min-safe) + * myBarResolve: function(DependencyName) { return DependencyName.fetchSomethingAsPromise() }, + * + * // Array split; "DependencyName" dep as string + * myBazResolve: [ "DependencyName", function(dep) { return dep.fetchSomethingAsPromise() }, + * + * // Array split; DependencyType dep as token (compared using ===) + * myQuxResolve: [ DependencyType, function(dep) { return dep.fetchSometingAsPromise() }, + * + * // val.$inject used as deps + * // where: + * // corgeResolve.$inject = ["DependencyName"]; + * // function corgeResolve(dep) { dep.fetchSometingAsPromise() } + * // then "DependencyName" dep as string + * myCorgeResolve: corgeResolve, + * + * // inject service by name + * // When a string is found, desugar creating a resolve that injects the named service + * myGraultResolve: "SomeService" + * } + * + * or: + * + * [ + * new Resolvable("myFooResolve", function() { return "myFooData" }), + * new Resolvable("myBarResolve", function(dep) { return dep.fetchSomethingAsPromise() }, [ "DependencyName" ]), + * { provide: "myBazResolve", useFactory: function(dep) { dep.fetchSomethingAsPromise() }, deps: [ "DependencyName" ] } + * ] + */ +function resolvablesBuilder(state) { + /** convert resolve: {} and resolvePolicy: {} objects to an array of tuples */ + var objects2Tuples = function (resolveObj, resolvePolicies) { + return Object.keys(resolveObj || {}).map(function (token) { return ({ token: token, val: resolveObj[token], deps: undefined, policy: resolvePolicies[token] }); }); + }; + /** fetch DI annotations from a function or ng1-style array */ + var annotate = function (fn) { + var $injector = services.$injector; + // ng1 doesn't have an $injector until runtime. + // If the $injector doesn't exist, use "deferred" literal as a + // marker indicating they should be annotated when runtime starts + return fn['$inject'] || ($injector && $injector.annotate(fn, $injector.strictDi)) || "deferred"; + }; + /** true if the object has both `token` and `resolveFn`, and is probably a [[ResolveLiteral]] */ + var isResolveLiteral = function (obj) { return !!(obj.token && obj.resolveFn); }; + /** true if the object looks like a provide literal, or a ng2 Provider */ + var isLikeNg2Provider = function (obj) { return !!((obj.provide || obj.token) && (obj.useValue || obj.useFactory || obj.useExisting || obj.useClass)); }; + /** true if the object looks like a tuple from obj2Tuples */ + var isTupleFromObj = function (obj) { return !!(obj && obj.val && (isString(obj.val) || isArray(obj.val) || isFunction(obj.val))); }; + /** extracts the token from a Provider or provide literal */ + var token = function (p) { return p.provide || p.token; }; + /** Given a literal resolve or provider object, returns a Resolvable */ + var literal2Resolvable = pattern([ + [prop('resolveFn'), function (p) { return new Resolvable(token(p), p.resolveFn, p.deps, p.policy); }], + [prop('useFactory'), function (p) { return new Resolvable(token(p), p.useFactory, (p.deps || p.dependencies), p.policy); }], + [prop('useClass'), function (p) { return new Resolvable(token(p), function () { return new p.useClass(); }, [], p.policy); }], + [prop('useValue'), function (p) { return new Resolvable(token(p), function () { return p.useValue; }, [], p.policy, p.useValue); }], + [prop('useExisting'), function (p) { return new Resolvable(token(p), identity, [p.useExisting], p.policy); }], + ]); + var tuple2Resolvable = pattern([ + [pipe(prop("val"), isString), function (tuple) { return new Resolvable(tuple.token, identity, [tuple.val], tuple.policy); }], + [pipe(prop("val"), isArray), function (tuple) { return new Resolvable(tuple.token, tail(tuple.val), tuple.val.slice(0, -1), tuple.policy); }], + [pipe(prop("val"), isFunction), function (tuple) { return new Resolvable(tuple.token, tuple.val, annotate(tuple.val), tuple.policy); }], + ]); + var item2Resolvable = pattern([ + [is(Resolvable), function (r) { return r; }], + [isResolveLiteral, literal2Resolvable], + [isLikeNg2Provider, literal2Resolvable], + [isTupleFromObj, tuple2Resolvable], + [val(true), function (obj) { throw new Error("Invalid resolve value: " + stringify(obj)); }] + ]); + // If resolveBlock is already an array, use it as-is. + // Otherwise, assume it's an object and convert to an Array of tuples + var decl = state.resolve; + var items = isArray(decl) ? decl : objects2Tuples(decl, state.resolvePolicy || {}); + return items.map(item2Resolvable); +} +/** + * @internalapi A internal global service + * + * StateBuilder is a factory for the internal [[StateObject]] objects. + * + * When you register a state with the [[StateRegistry]], you register a plain old javascript object which + * conforms to the [[StateDeclaration]] interface. This factory takes that object and builds the corresponding + * [[StateObject]] object, which has an API and is used internally. + * + * Custom properties or API may be added to the internal [[StateObject]] object by registering a decorator function + * using the [[builder]] method. + */ +var StateBuilder = /** @class */ (function () { + function StateBuilder(matcher, urlMatcherFactory) { + this.matcher = matcher; + var self = this; + var root$$1 = function () { return matcher.find(""); }; + var isRoot = function (state) { return state.name === ""; }; + function parentBuilder(state) { + if (isRoot(state)) + return null; + return matcher.find(self.parentName(state)) || root$$1(); + } + this.builders = { + name: [nameBuilder], + self: [selfBuilder], + parent: [parentBuilder], + data: [dataBuilder], + // Build a URLMatcher if necessary, either via a relative or absolute URL + url: [getUrlBuilder(urlMatcherFactory, root$$1)], + // Keep track of the closest ancestor state that has a URL (i.e. is navigable) + navigable: [getNavigableBuilder(isRoot)], + params: [getParamsBuilder(urlMatcherFactory.paramFactory)], + // Each framework-specific ui-router implementation should define its own `views` builder + // e.g., src/ng1/statebuilders/views.ts + views: [], + // Keep a full path from the root down to this state as this is needed for state activation. + path: [pathBuilder], + // Speed up $state.includes() as it's used a lot + includes: [includesBuilder], + resolvables: [resolvablesBuilder] + }; + } + /** + * Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`). + * More than one BuilderFunction can be registered for a given property. + * + * The BuilderFunction(s) will be used to define the property on any subsequently built [[StateObject]] objects. + * + * @param name The name of the State property being registered for. + * @param fn The BuilderFunction which will be used to build the State property + * @returns a function which deregisters the BuilderFunction + */ + StateBuilder.prototype.builder = function (name, fn) { + var builders = this.builders; + var array = builders[name] || []; + // Backwards compat: if only one builder exists, return it, else return whole arary. + if (isString(name) && !isDefined(fn)) + return array.length > 1 ? array : array[0]; + if (!isString(name) || !isFunction(fn)) + return; + builders[name] = array; + builders[name].push(fn); + return function () { return builders[name].splice(builders[name].indexOf(fn, 1)) && null; }; + }; + /** + * Builds all of the properties on an essentially blank State object, returning a State object which has all its + * properties and API built. + * + * @param state an uninitialized State object + * @returns the built State object + */ + StateBuilder.prototype.build = function (state) { + var _a = this, matcher = _a.matcher, builders = _a.builders; + var parent = this.parentName(state); + if (parent && !matcher.find(parent, undefined, false)) { + return null; + } + for (var key in builders) { + if (!builders.hasOwnProperty(key)) + continue; + var chain = builders[key].reduce(function (parentFn, step) { return function (_state) { return step(_state, parentFn); }; }, noop$1); + state[key] = chain(state); + } + return state; + }; + StateBuilder.prototype.parentName = function (state) { + // name = 'foo.bar.baz.**' + var name = state.name || ""; + // segments = ['foo', 'bar', 'baz', '.**'] + var segments = name.split('.'); + // segments = ['foo', 'bar', 'baz'] + var lastSegment = segments.pop(); + // segments = ['foo', 'bar'] (ignore .** segment for future states) + if (lastSegment === '**') + segments.pop(); + if (segments.length) { + if (state.parent) { + throw new Error("States that specify the 'parent:' property should not have a '.' in their name (" + name + ")"); + } + // 'foo.bar' + return segments.join("."); + } + if (!state.parent) + return ""; + return isString(state.parent) ? state.parent : state.parent.name; + }; + StateBuilder.prototype.name = function (state) { + var name = state.name; + if (name.indexOf('.') !== -1 || !state.parent) + return name; + var parentName = isString(state.parent) ? state.parent : state.parent.name; + return parentName ? parentName + "." + name : name; + }; + return StateBuilder; +}()); + +/** @module state */ /** for typedoc */ +var StateMatcher = /** @class */ (function () { + function StateMatcher(_states) { + this._states = _states; + } + StateMatcher.prototype.isRelative = function (stateName) { + stateName = stateName || ""; + return stateName.indexOf(".") === 0 || stateName.indexOf("^") === 0; + }; + StateMatcher.prototype.find = function (stateOrName, base, matchGlob) { + if (matchGlob === void 0) { matchGlob = true; } + if (!stateOrName && stateOrName !== "") + return undefined; + var isStr = isString(stateOrName); + var name = isStr ? stateOrName : stateOrName.name; + if (this.isRelative(name)) + name = this.resolvePath(name, base); + var state = this._states[name]; + if (state && (isStr || (!isStr && (state === stateOrName || state.self === stateOrName)))) { + return state; + } + else if (isStr && matchGlob) { + var _states = values(this._states); + var matches = _states.filter(function (state) { + return state.__stateObjectCache.nameGlob && + state.__stateObjectCache.nameGlob.matches(name); + }); + if (matches.length > 1) { + console.log("stateMatcher.find: Found multiple matches for " + name + " using glob: ", matches.map(function (match) { return match.name; })); + } + return matches[0]; + } + return undefined; + }; + StateMatcher.prototype.resolvePath = function (name, base) { + if (!base) + throw new Error("No reference point given for path '" + name + "'"); + var baseState = this.find(base); + var splitName = name.split("."), i = 0, pathLength = splitName.length, current = baseState; + for (; i < pathLength; i++) { + if (splitName[i] === "" && i === 0) { + current = baseState; + continue; + } + if (splitName[i] === "^") { + if (!current.parent) + throw new Error("Path '" + name + "' not valid for state '" + baseState.name + "'"); + current = current.parent; + continue; + } + break; + } + var relName = splitName.slice(i).join("."); + return current.name + (current.name && relName ? "." : "") + relName; + }; + return StateMatcher; +}()); + +/** @module state */ /** for typedoc */ +/** @internalapi */ +var StateQueueManager = /** @class */ (function () { + function StateQueueManager($registry, $urlRouter, states, builder, listeners) { + this.$registry = $registry; + this.$urlRouter = $urlRouter; + this.states = states; + this.builder = builder; + this.listeners = listeners; + this.queue = []; + this.matcher = $registry.matcher; + } + /** @internalapi */ + StateQueueManager.prototype.dispose = function () { + this.queue = []; + }; + StateQueueManager.prototype.register = function (stateDecl) { + var queue = this.queue; + var state = StateObject.create(stateDecl); + var name = state.name; + if (!isString(name)) + throw new Error("State must have a valid name"); + if (this.states.hasOwnProperty(name) || inArray(queue.map(prop('name')), name)) + throw new Error("State '" + name + "' is already defined"); + queue.push(state); + this.flush(); + return state; + }; + StateQueueManager.prototype.flush = function () { + var _this = this; + var _a = this, queue = _a.queue, states = _a.states, builder = _a.builder; + var registered = [], // states that got registered + orphans = [], // states that don't yet have a parent registered + previousQueueLength = {}; // keep track of how long the queue when an orphan was first encountered + var getState = function (name) { + return _this.states.hasOwnProperty(name) && _this.states[name]; + }; + while (queue.length > 0) { + var state = queue.shift(); + var name_1 = state.name; + var result = builder.build(state); + var orphanIdx = orphans.indexOf(state); + if (result) { + var existingState = getState(name_1); + if (existingState && existingState.name === name_1) { + throw new Error("State '" + name_1 + "' is already defined"); + } + var existingFutureState = getState(name_1 + ".**"); + if (existingFutureState) { + // Remove future state of the same name + this.$registry.deregister(existingFutureState); + } + states[name_1] = state; + this.attachRoute(state); + if (orphanIdx >= 0) + orphans.splice(orphanIdx, 1); + registered.push(state); + continue; + } + var prev = previousQueueLength[name_1]; + previousQueueLength[name_1] = queue.length; + if (orphanIdx >= 0 && prev === queue.length) { + // Wait until two consecutive iterations where no additional states were dequeued successfully. + // throw new Error(`Cannot register orphaned state '${name}'`); + queue.push(state); + return states; + } + else if (orphanIdx < 0) { + orphans.push(state); + } + queue.push(state); + } + if (registered.length) { + this.listeners.forEach(function (listener) { return listener("registered", registered.map(function (s) { return s.self; })); }); + } + return states; + }; + StateQueueManager.prototype.attachRoute = function (state) { + if (state.abstract || !state.url) + return; + this.$urlRouter.rule(this.$urlRouter.urlRuleFactory.create(state)); + }; + return StateQueueManager; +}()); + +/** + * @coreapi + * @module state + */ /** for typedoc */ +var StateRegistry = /** @class */ (function () { + /** @internalapi */ + function StateRegistry(_router) { + this._router = _router; + this.states = {}; + this.listeners = []; + this.matcher = new StateMatcher(this.states); + this.builder = new StateBuilder(this.matcher, _router.urlMatcherFactory); + this.stateQueue = new StateQueueManager(this, _router.urlRouter, this.states, this.builder, this.listeners); + this._registerRoot(); + } + /** @internalapi */ + StateRegistry.prototype._registerRoot = function () { + var rootStateDef = { + name: '', + url: '^', + views: null, + params: { + '#': { value: null, type: 'hash', dynamic: true } + }, + abstract: true + }; + var _root = this._root = this.stateQueue.register(rootStateDef); + _root.navigable = null; + }; + /** @internalapi */ + StateRegistry.prototype.dispose = function () { + var _this = this; + this.stateQueue.dispose(); + this.listeners = []; + this.get().forEach(function (state) { return _this.get(state) && _this.deregister(state); }); + }; + /** + * Listen for a State Registry events + * + * Adds a callback that is invoked when states are registered or deregistered with the StateRegistry. + * + * #### Example: + * ```js + * let allStates = registry.get(); + * + * // Later, invoke deregisterFn() to remove the listener + * let deregisterFn = registry.onStatesChanged((event, states) => { + * switch(event) { + * case: 'registered': + * states.forEach(state => allStates.push(state)); + * break; + * case: 'deregistered': + * states.forEach(state => { + * let idx = allStates.indexOf(state); + * if (idx !== -1) allStates.splice(idx, 1); + * }); + * break; + * } + * }); + * ``` + * + * @param listener a callback function invoked when the registered states changes. + * The function receives two parameters, `event` and `state`. + * See [[StateRegistryListener]] + * @return a function that deregisters the listener + */ + StateRegistry.prototype.onStatesChanged = function (listener) { + this.listeners.push(listener); + return function deregisterListener() { + removeFrom(this.listeners)(listener); + }.bind(this); + }; + /** + * Gets the implicit root state + * + * Gets the root of the state tree. + * The root state is implicitly created by UI-Router. + * Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]] + * + * @return the root [[StateObject]] + */ + StateRegistry.prototype.root = function () { + return this._root; + }; + /** + * Adds a state to the registry + * + * Registers a [[StateDeclaration]] or queues it for registration. + * + * Note: a state will be queued if the state's parent isn't yet registered. + * + * @param stateDefinition the definition of the state to register. + * @returns the internal [[StateObject]] object. + * If the state was successfully registered, then the object is fully built (See: [[StateBuilder]]). + * If the state was only queued, then the object is not fully built. + */ + StateRegistry.prototype.register = function (stateDefinition) { + return this.stateQueue.register(stateDefinition); + }; + /** @hidden */ + StateRegistry.prototype._deregisterTree = function (state) { + var _this = this; + var all$$1 = this.get().map(function (s) { return s.$$state(); }); + var getChildren = function (states) { + var children = all$$1.filter(function (s) { return states.indexOf(s.parent) !== -1; }); + return children.length === 0 ? children : children.concat(getChildren(children)); + }; + var children = getChildren([state]); + var deregistered = [state].concat(children).reverse(); + deregistered.forEach(function (state) { + var $ur = _this._router.urlRouter; + // Remove URL rule + $ur.rules().filter(propEq("state", state)).forEach($ur.removeRule.bind($ur)); + // Remove state from registry + delete _this.states[state.name]; + }); + return deregistered; + }; + /** + * Removes a state from the registry + * + * This removes a state from the registry. + * If the state has children, they are are also removed from the registry. + * + * @param stateOrName the state's name or object representation + * @returns {StateObject[]} a list of removed states + */ + StateRegistry.prototype.deregister = function (stateOrName) { + var _state = this.get(stateOrName); + if (!_state) + throw new Error("Can't deregister state; not found: " + stateOrName); + var deregisteredStates = this._deregisterTree(_state.$$state()); + this.listeners.forEach(function (listener) { return listener("deregistered", deregisteredStates.map(function (s) { return s.self; })); }); + return deregisteredStates; + }; + StateRegistry.prototype.get = function (stateOrName, base) { + var _this = this; + if (arguments.length === 0) + return Object.keys(this.states).map(function (name) { return _this.states[name].self; }); + var found = this.matcher.find(stateOrName, base); + return found && found.self || null; + }; + StateRegistry.prototype.decorator = function (name, func) { + return this.builder.builder(name, func); + }; + return StateRegistry; +}()); + +/** + * @coreapi + * @module url + */ +/** for typedoc */ +/** @hidden */ +function quoteRegExp(string, param) { + var surroundPattern = ['', ''], result = string.replace(/[\\\[\]\^$*+?.()|{}]/g, "\\$&"); + if (!param) + return result; + switch (param.squash) { + case false: + surroundPattern = ['(', ')' + (param.isOptional ? '?' : '')]; + break; + case true: + result = result.replace(/\/$/, ''); + surroundPattern = ['(?:\/(', ')|\/)?']; + break; + default: + surroundPattern = ["(" + param.squash + "|", ')?']; + break; + } + return result + surroundPattern[0] + param.type.pattern.source + surroundPattern[1]; +} +/** @hidden */ +var memoizeTo = function (obj, prop$$1, fn) { + return obj[prop$$1] = obj[prop$$1] || fn(); +}; +/** @hidden */ +var splitOnSlash = splitOnDelim('/'); +/** + * Matches URLs against patterns. + * + * Matches URLs against patterns and extracts named parameters from the path or the search + * part of the URL. + * + * A URL pattern consists of a path pattern, optionally followed by '?' and a list of search (query) + * parameters. Multiple search parameter names are separated by '&'. Search parameters + * do not influence whether or not a URL is matched, but their values are passed through into + * the matched parameters returned by [[UrlMatcher.exec]]. + * + * - *Path parameters* are defined using curly brace placeholders (`/somepath/{param}`) + * or colon placeholders (`/somePath/:param`). + * + * - *A parameter RegExp* may be defined for a param after a colon + * (`/somePath/{param:[a-zA-Z0-9]+}`) in a curly brace placeholder. + * The regexp must match for the url to be matched. + * Should the regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash. + * + * Note: a RegExp parameter will encode its value using either [[ParamTypes.path]] or [[ParamTypes.query]]. + * + * - *Custom parameter types* may also be specified after a colon (`/somePath/{param:int}`) in curly brace parameters. + * See [[UrlMatcherFactory.type]] for more information. + * + * - *Catch-all parameters* are defined using an asterisk placeholder (`/somepath/*catchallparam`). + * A catch-all * parameter value will contain the remainder of the URL. + * + * --- + * + * Parameter names may contain only word characters (latin letters, digits, and underscore) and + * must be unique within the pattern (across both path and search parameters). + * A path parameter matches any number of characters other than '/'. For catch-all + * placeholders the path parameter matches any number of characters. + * + * Examples: + * + * * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for + * trailing slashes, and patterns have to match the entire path, not just a prefix. + * * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or + * '/user/bob/details'. The second path segment will be captured as the parameter 'id'. + * * `'/user/{id}'` - Same as the previous example, but using curly brace syntax. + * * `'/user/{id:[^/]*}'` - Same as the previous example. + * * `'/user/{id:[0-9a-fA-F]{1,8}}'` - Similar to the previous example, but only matches if the id + * parameter consists of 1 to 8 hex digits. + * * `'/files/{path:.*}'` - Matches any URL starting with '/files/' and captures the rest of the + * path into the parameter 'path'. + * * `'/files/*path'` - ditto. + * * `'/calendar/{start:date}'` - Matches "/calendar/2014-11-12" (because the pattern defined + * in the built-in `date` ParamType matches `2014-11-12`) and provides a Date object in $stateParams.start + * + */ +var UrlMatcher = /** @class */ (function () { + /** + * @param pattern The pattern to compile into a matcher. + * @param paramTypes The [[ParamTypes]] registry + * @param config A configuration object + * - `caseInsensitive` - `true` if URL matching should be case insensitive, otherwise `false`, the default value (for backward compatibility) is `false`. + * - `strict` - `false` if matching against a URL with a trailing slash should be treated as equivalent to a URL without a trailing slash, the default value is `true`. + */ + function UrlMatcher(pattern$$1, paramTypes, paramFactory, config) { + var _this = this; + this.config = config; + /** @hidden */ + this._cache = { path: [this] }; + /** @hidden */ + this._children = []; + /** @hidden */ + this._params = []; + /** @hidden */ + this._segments = []; + /** @hidden */ + this._compiled = []; + this.pattern = pattern$$1; + this.config = defaults(this.config, { + params: {}, + strict: true, + caseInsensitive: false, + paramMap: identity + }); + // Find all placeholders and create a compiled pattern, using either classic or curly syntax: + // '*' name + // ':' name + // '{' name '}' + // '{' name ':' regexp '}' + // The regular expression is somewhat complicated due to the need to allow curly braces + // inside the regular expression. The placeholder regexp breaks down as follows: + // ([:*])([\w\[\]]+) - classic placeholder ($1 / $2) (search version has - for snake-case) + // \{([\w\[\]]+)(?:\:\s*( ... ))?\} - curly brace placeholder ($3) with optional regexp/type ... ($4) (search version has - for snake-case + // (?: ... | ... | ... )+ - the regexp consists of any number of atoms, an atom being either + // [^{}\\]+ - anything other than curly braces or backslash + // \\. - a backslash escape + // \{(?:[^{}\\]+|\\.)*\} - a matched set of curly braces containing other atoms + var placeholder = /([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, searchPlaceholder = /([:]?)([\w\[\].-]+)|\{([\w\[\].-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, last = 0, m, patterns = []; + var checkParamErrors = function (id) { + if (!UrlMatcher.nameValidator.test(id)) + throw new Error("Invalid parameter name '" + id + "' in pattern '" + pattern$$1 + "'"); + if (find(_this._params, propEq('id', id))) + throw new Error("Duplicate parameter name '" + id + "' in pattern '" + pattern$$1 + "'"); + }; + // Split into static segments separated by path parameter placeholders. + // The number of segments is always 1 more than the number of parameters. + var matchDetails = function (m, isSearch) { + // IE[78] returns '' for unmatched groups instead of null + var id = m[2] || m[3]; + var regexp = isSearch ? m[4] : m[4] || (m[1] === '*' ? '[\\s\\S]*' : null); + var makeRegexpType = function (regexp) { return inherit(paramTypes.type(isSearch ? "query" : "path"), { + pattern: new RegExp(regexp, _this.config.caseInsensitive ? 'i' : undefined) + }); }; + return { + id: id, + regexp: regexp, + cfg: _this.config.params[id], + segment: pattern$$1.substring(last, m.index), + type: !regexp ? null : paramTypes.type(regexp) || makeRegexpType(regexp) + }; + }; + var p, segment; + while ((m = placeholder.exec(pattern$$1))) { + p = matchDetails(m, false); + if (p.segment.indexOf('?') >= 0) + break; // we're into the search part + checkParamErrors(p.id); + this._params.push(paramFactory.fromPath(p.id, p.type, this.config.paramMap(p.cfg, false))); + this._segments.push(p.segment); + patterns.push([p.segment, tail(this._params)]); + last = placeholder.lastIndex; + } + segment = pattern$$1.substring(last); + // Find any search parameter names and remove them from the last segment + var i = segment.indexOf('?'); + if (i >= 0) { + var search = segment.substring(i); + segment = segment.substring(0, i); + if (search.length > 0) { + last = 0; + while ((m = searchPlaceholder.exec(search))) { + p = matchDetails(m, true); + checkParamErrors(p.id); + this._params.push(paramFactory.fromSearch(p.id, p.type, this.config.paramMap(p.cfg, true))); + last = placeholder.lastIndex; + // check if ?& + } + } + } + this._segments.push(segment); + this._compiled = patterns.map(function (pattern$$1) { return quoteRegExp.apply(null, pattern$$1); }).concat(quoteRegExp(segment)); + } + /** + * Creates a new concatenated UrlMatcher + * + * Builds a new UrlMatcher by appending another UrlMatcher to this one. + * + * @param url A `UrlMatcher` instance to append as a child of the current `UrlMatcher`. + */ + UrlMatcher.prototype.append = function (url) { + this._children.push(url); + url._cache = { + path: this._cache.path.concat(url), + parent: this, + pattern: null, + }; + return url; + }; + /** @hidden */ + UrlMatcher.prototype.isRoot = function () { + return this._cache.path[0] === this; + }; + /** Returns the input pattern string */ + UrlMatcher.prototype.toString = function () { + return this.pattern; + }; + /** + * Tests the specified url/path against this matcher. + * + * Tests if the given url matches this matcher's pattern, and returns an object containing the captured + * parameter values. Returns null if the path does not match. + * + * The returned object contains the values + * of any search parameters that are mentioned in the pattern, but their value may be null if + * they are not present in `search`. This means that search parameters are always treated + * as optional. + * + * #### Example: + * ```js + * new UrlMatcher('/user/{id}?q&r').exec('/user/bob', { + * x: '1', q: 'hello' + * }); + * // returns { id: 'bob', q: 'hello', r: null } + * ``` + * + * @param path The URL path to match, e.g. `$location.path()`. + * @param search URL search parameters, e.g. `$location.search()`. + * @param hash URL hash e.g. `$location.hash()`. + * @param options + * + * @returns The captured parameter values. + */ + UrlMatcher.prototype.exec = function (path, search, hash, options) { + var _this = this; + if (search === void 0) { search = {}; } + if (options === void 0) { options = {}; } + var match = memoizeTo(this._cache, 'pattern', function () { + return new RegExp([ + '^', + unnest(_this._cache.path.map(prop('_compiled'))).join(''), + _this.config.strict === false ? '\/?' : '', + '$' + ].join(''), _this.config.caseInsensitive ? 'i' : undefined); + }).exec(path); + if (!match) + return null; + //options = defaults(options, { isolate: false }); + var allParams = this.parameters(), pathParams = allParams.filter(function (param) { return !param.isSearch(); }), searchParams = allParams.filter(function (param) { return param.isSearch(); }), nPathSegments = this._cache.path.map(function (urlm) { return urlm._segments.length - 1; }).reduce(function (a, x) { return a + x; }), values$$1 = {}; + if (nPathSegments !== match.length - 1) + throw new Error("Unbalanced capture group in route '" + this.pattern + "'"); + function decodePathArray(string) { + var reverseString = function (str) { return str.split("").reverse().join(""); }; + var unquoteDashes = function (str) { return str.replace(/\\-/g, "-"); }; + var split = reverseString(string).split(/-(?!\\)/); + var allReversed = map(split, reverseString); + return map(allReversed, unquoteDashes).reverse(); + } + for (var i = 0; i < nPathSegments; i++) { + var param = pathParams[i]; + var value = match[i + 1]; + // if the param value matches a pre-replace pair, replace the value before decoding. + for (var j = 0; j < param.replace.length; j++) { + if (param.replace[j].from === value) + value = param.replace[j].to; + } + if (value && param.array === true) + value = decodePathArray(value); + if (isDefined(value)) + value = param.type.decode(value); + values$$1[param.id] = param.value(value); + } + searchParams.forEach(function (param) { + var value = search[param.id]; + for (var j = 0; j < param.replace.length; j++) { + if (param.replace[j].from === value) + value = param.replace[j].to; + } + if (isDefined(value)) + value = param.type.decode(value); + values$$1[param.id] = param.value(value); + }); + if (hash) + values$$1["#"] = hash; + return values$$1; + }; + /** + * @hidden + * Returns all the [[Param]] objects of all path and search parameters of this pattern in order of appearance. + * + * @returns {Array.} An array of [[Param]] objects. Must be treated as read-only. If the + * pattern has no parameters, an empty array is returned. + */ + UrlMatcher.prototype.parameters = function (opts) { + if (opts === void 0) { opts = {}; } + if (opts.inherit === false) + return this._params; + return unnest(this._cache.path.map(function (matcher) { return matcher._params; })); + }; + /** + * @hidden + * Returns a single parameter from this UrlMatcher by id + * + * @param id + * @param opts + * @returns {T|Param|any|boolean|UrlMatcher|null} + */ + UrlMatcher.prototype.parameter = function (id, opts) { + var _this = this; + if (opts === void 0) { opts = {}; } + var findParam = function () { + for (var _i = 0, _a = _this._params; _i < _a.length; _i++) { + var param = _a[_i]; + if (param.id === id) + return param; + } + }; + var parent = this._cache.parent; + return findParam() || (opts.inherit !== false && parent && parent.parameter(id, opts)) || null; + }; + /** + * Validates the input parameter values against this UrlMatcher + * + * Checks an object hash of parameters to validate their correctness according to the parameter + * types of this `UrlMatcher`. + * + * @param params The object hash of parameters to validate. + * @returns Returns `true` if `params` validates, otherwise `false`. + */ + UrlMatcher.prototype.validates = function (params) { + var validParamVal = function (param, val$$1) { + return !param || param.validates(val$$1); + }; + params = params || {}; + // I'm not sure why this checks only the param keys passed in, and not all the params known to the matcher + var paramSchema = this.parameters().filter(function (paramDef) { return params.hasOwnProperty(paramDef.id); }); + return paramSchema.map(function (paramDef) { return validParamVal(paramDef, params[paramDef.id]); }).reduce(allTrueR, true); + }; + /** + * Given a set of parameter values, creates a URL from this UrlMatcher. + * + * Creates a URL that matches this pattern by substituting the specified values + * for the path and search parameters. + * + * #### Example: + * ```js + * new UrlMatcher('/user/{id}?q').format({ id:'bob', q:'yes' }); + * // returns '/user/bob?q=yes' + * ``` + * + * @param values the values to substitute for the parameters in this pattern. + * @returns the formatted URL (path and optionally search part). + */ + UrlMatcher.prototype.format = function (values$$1) { + if (values$$1 === void 0) { values$$1 = {}; } + // Build the full path of UrlMatchers (including all parent UrlMatchers) + var urlMatchers = this._cache.path; + // Extract all the static segments and Params (processed as ParamDetails) + // into an ordered array + var pathSegmentsAndParams = urlMatchers.map(UrlMatcher.pathSegmentsAndParams) + .reduce(unnestR, []) + .map(function (x) { return isString(x) ? x : getDetails(x); }); + // Extract the query params into a separate array + var queryParams = urlMatchers.map(UrlMatcher.queryParams) + .reduce(unnestR, []) + .map(getDetails); + var isInvalid = function (param) { return param.isValid === false; }; + if (pathSegmentsAndParams.concat(queryParams).filter(isInvalid).length) { + return null; + } + /** + * Given a Param, applies the parameter value, then returns detailed information about it + */ + function getDetails(param) { + // Normalize to typed value + var value = param.value(values$$1[param.id]); + var isValid = param.validates(value); + var isDefaultValue = param.isDefaultValue(value); + // Check if we're in squash mode for the parameter + var squash = isDefaultValue ? param.squash : false; + // Allow the Parameter's Type to encode the value + var encoded = param.type.encode(value); + return { param: param, value: value, isValid: isValid, isDefaultValue: isDefaultValue, squash: squash, encoded: encoded }; + } + // Build up the path-portion from the list of static segments and parameters + var pathString = pathSegmentsAndParams.reduce(function (acc, x) { + // The element is a static segment (a raw string); just append it + if (isString(x)) + return acc + x; + // Otherwise, it's a ParamDetails. + var squash = x.squash, encoded = x.encoded, param = x.param; + // If squash is === true, try to remove a slash from the path + if (squash === true) + return (acc.match(/\/$/)) ? acc.slice(0, -1) : acc; + // If squash is a string, use the string for the param value + if (isString(squash)) + return acc + squash; + if (squash !== false) + return acc; // ? + if (encoded == null) + return acc; + // If this parameter value is an array, encode the value using encodeDashes + if (isArray(encoded)) + return acc + map(encoded, UrlMatcher.encodeDashes).join("-"); + // If the parameter type is "raw", then do not encodeURIComponent + if (param.raw) + return acc + encoded; + // Encode the value + return acc + encodeURIComponent(encoded); + }, ""); + // Build the query string by applying parameter values (array or regular) + // then mapping to key=value, then flattening and joining using "&" + var queryString = queryParams.map(function (paramDetails) { + var param = paramDetails.param, squash = paramDetails.squash, encoded = paramDetails.encoded, isDefaultValue = paramDetails.isDefaultValue; + if (encoded == null || (isDefaultValue && squash !== false)) + return; + if (!isArray(encoded)) + encoded = [encoded]; + if (encoded.length === 0) + return; + if (!param.raw) + encoded = map(encoded, encodeURIComponent); + return encoded.map(function (val$$1) { return param.id + "=" + val$$1; }); + }).filter(identity).reduce(unnestR, []).join("&"); + // Concat the pathstring with the queryString (if exists) and the hashString (if exists) + return pathString + (queryString ? "?" + queryString : "") + (values$$1["#"] ? "#" + values$$1["#"] : ""); + }; + /** @hidden */ + UrlMatcher.encodeDashes = function (str) { + return encodeURIComponent(str).replace(/-/g, function (c) { return "%5C%" + c.charCodeAt(0).toString(16).toUpperCase(); }); + }; + /** @hidden Given a matcher, return an array with the matcher's path segments and path params, in order */ + UrlMatcher.pathSegmentsAndParams = function (matcher) { + var staticSegments = matcher._segments; + var pathParams = matcher._params.filter(function (p) { return p.location === exports.DefType.PATH; }); + return arrayTuples(staticSegments, pathParams.concat(undefined)) + .reduce(unnestR, []) + .filter(function (x) { return x !== "" && isDefined(x); }); + }; + /** @hidden Given a matcher, return an array with the matcher's query params */ + UrlMatcher.queryParams = function (matcher) { + return matcher._params.filter(function (p) { return p.location === exports.DefType.SEARCH; }); + }; + /** + * Compare two UrlMatchers + * + * This comparison function converts a UrlMatcher into static and dynamic path segments. + * Each static path segment is a static string between a path separator (slash character). + * Each dynamic segment is a path parameter. + * + * The comparison function sorts static segments before dynamic ones. + */ + UrlMatcher.compare = function (a, b) { + /** + * Turn a UrlMatcher and all its parent matchers into an array + * of slash literals '/', string literals, and Param objects + * + * This example matcher matches strings like "/foo/:param/tail": + * var matcher = $umf.compile("/foo").append($umf.compile("/:param")).append($umf.compile("/")).append($umf.compile("tail")); + * var result = segments(matcher); // [ '/', 'foo', '/', Param, '/', 'tail' ] + * + * Caches the result as `matcher._cache.segments` + */ + var segments = function (matcher) { + return matcher._cache.segments = matcher._cache.segments || + matcher._cache.path.map(UrlMatcher.pathSegmentsAndParams) + .reduce(unnestR, []) + .reduce(joinNeighborsR, []) + .map(function (x) { return isString(x) ? splitOnSlash(x) : x; }) + .reduce(unnestR, []); + }; + /** + * Gets the sort weight for each segment of a UrlMatcher + * + * Caches the result as `matcher._cache.weights` + */ + var weights = function (matcher) { + return matcher._cache.weights = matcher._cache.weights || + segments(matcher).map(function (segment) { + // Sort slashes first, then static strings, the Params + if (segment === '/') + return 1; + if (isString(segment)) + return 2; + if (segment instanceof Param) + return 3; + }); + }; + /** + * Pads shorter array in-place (mutates) + */ + var padArrays = function (l, r, padVal) { + var len = Math.max(l.length, r.length); + while (l.length < len) + l.push(padVal); + while (r.length < len) + r.push(padVal); + }; + var weightsA = weights(a), weightsB = weights(b); + padArrays(weightsA, weightsB, 0); + var cmp, i, pairs$$1 = arrayTuples(weightsA, weightsB); + for (i = 0; i < pairs$$1.length; i++) { + cmp = pairs$$1[i][0] - pairs$$1[i][1]; + if (cmp !== 0) + return cmp; + } + return 0; + }; + /** @hidden */ + UrlMatcher.nameValidator = /^\w+([-.]+\w+)*(?:\[\])?$/; + return UrlMatcher; +}()); + +/** + * @internalapi + * @module url + */ /** for typedoc */ +/** + * Factory for [[UrlMatcher]] instances. + * + * The factory is available to ng1 services as + * `$urlMatcherFactory` or ng1 providers as `$urlMatcherFactoryProvider`. + */ +var UrlMatcherFactory = /** @class */ (function () { + function UrlMatcherFactory() { + var _this = this; + /** @hidden */ this.paramTypes = new ParamTypes(); + /** @hidden */ this._isCaseInsensitive = false; + /** @hidden */ this._isStrictMode = true; + /** @hidden */ this._defaultSquashPolicy = false; + /** @hidden */ + this._getConfig = function (config) { + return extend({ strict: _this._isStrictMode, caseInsensitive: _this._isCaseInsensitive }, config); + }; + /** @internalapi Creates a new [[Param]] for a given location (DefType) */ + this.paramFactory = { + /** Creates a new [[Param]] from a CONFIG block */ + fromConfig: function (id, type, config) { + return new Param(id, type, config, exports.DefType.CONFIG, _this); + }, + /** Creates a new [[Param]] from a url PATH */ + fromPath: function (id, type, config) { + return new Param(id, type, config, exports.DefType.PATH, _this); + }, + /** Creates a new [[Param]] from a url SEARCH */ + fromSearch: function (id, type, config) { + return new Param(id, type, config, exports.DefType.SEARCH, _this); + }, + }; + extend(this, { UrlMatcher: UrlMatcher, Param: Param }); + } + /** @inheritdoc */ + UrlMatcherFactory.prototype.caseInsensitive = function (value) { + return this._isCaseInsensitive = isDefined(value) ? value : this._isCaseInsensitive; + }; + /** @inheritdoc */ + UrlMatcherFactory.prototype.strictMode = function (value) { + return this._isStrictMode = isDefined(value) ? value : this._isStrictMode; + }; + /** @inheritdoc */ + UrlMatcherFactory.prototype.defaultSquashPolicy = function (value) { + if (isDefined(value) && value !== true && value !== false && !isString(value)) + throw new Error("Invalid squash policy: " + value + ". Valid policies: false, true, arbitrary-string"); + return this._defaultSquashPolicy = isDefined(value) ? value : this._defaultSquashPolicy; + }; + /** + * Creates a [[UrlMatcher]] for the specified pattern. + * + * @param pattern The URL pattern. + * @param config The config object hash. + * @returns The UrlMatcher. + */ + UrlMatcherFactory.prototype.compile = function (pattern, config) { + return new UrlMatcher(pattern, this.paramTypes, this.paramFactory, this._getConfig(config)); + }; + /** + * Returns true if the specified object is a [[UrlMatcher]], or false otherwise. + * + * @param object The object to perform the type check against. + * @returns `true` if the object matches the `UrlMatcher` interface, by + * implementing all the same methods. + */ + UrlMatcherFactory.prototype.isMatcher = function (object) { + // TODO: typeof? + if (!isObject(object)) + return false; + var result = true; + forEach(UrlMatcher.prototype, function (val, name) { + if (isFunction(val)) + result = result && (isDefined(object[name]) && isFunction(object[name])); + }); + return result; + }; + + /** + * Creates and registers a custom [[ParamType]] object + * + * A [[ParamType]] can be used to generate URLs with typed parameters. + * + * @param name The type name. + * @param definition The type definition. See [[ParamTypeDefinition]] for information on the values accepted. + * @param definitionFn A function that is injected before the app runtime starts. + * The result of this function should be a [[ParamTypeDefinition]]. + * The result is merged into the existing `definition`. + * See [[ParamType]] for information on the values accepted. + * + * @returns - if a type was registered: the [[UrlMatcherFactory]] + * - if only the `name` parameter was specified: the currently registered [[ParamType]] object, or undefined + * + * Note: Register custom types *before using them* in a state definition. + * + * See [[ParamTypeDefinition]] for examples + */ + UrlMatcherFactory.prototype.type = function (name, definition, definitionFn) { + var type = this.paramTypes.type(name, definition, definitionFn); + return !isDefined(definition) ? type : this; + }; + + /** @hidden */ + UrlMatcherFactory.prototype.$get = function () { + this.paramTypes.enqueue = false; + this.paramTypes._flushTypeQueue(); + return this; + }; + + /** @internalapi */ + UrlMatcherFactory.prototype.dispose = function () { + this.paramTypes.dispose(); + }; + return UrlMatcherFactory; +}()); + +/** + * @coreapi + * @module url + */ /** */ +/** + * Creates a [[UrlRule]] + * + * Creates a [[UrlRule]] from a: + * + * - `string` + * - [[UrlMatcher]] + * - `RegExp` + * - [[StateObject]] + * @internalapi + */ +var UrlRuleFactory = /** @class */ (function () { + function UrlRuleFactory(router) { + this.router = router; + } + UrlRuleFactory.prototype.compile = function (str) { + return this.router.urlMatcherFactory.compile(str); + }; + UrlRuleFactory.prototype.create = function (what, handler) { + var _this = this; + var makeRule = pattern([ + [isString, function (_what) { return makeRule(_this.compile(_what)); }], + [is(UrlMatcher), function (_what) { return _this.fromUrlMatcher(_what, handler); }], + [isState, function (_what) { return _this.fromState(_what, _this.router); }], + [is(RegExp), function (_what) { return _this.fromRegExp(_what, handler); }], + [isFunction, function (_what) { return new BaseUrlRule(_what, handler); }], + ]); + var rule = makeRule(what); + if (!rule) + throw new Error("invalid 'what' in when()"); + return rule; + }; + /** + * A UrlRule which matches based on a UrlMatcher + * + * The `handler` may be either a `string`, a [[UrlRuleHandlerFn]] or another [[UrlMatcher]] + * + * ## Handler as a function + * + * If `handler` is a function, the function is invoked with: + * + * - matched parameter values ([[RawParams]] from [[UrlMatcher.exec]]) + * - url: the current Url ([[UrlParts]]) + * - router: the router object ([[UIRouter]]) + * + * #### Example: + * ```js + * var urlMatcher = $umf.compile("/foo/:fooId/:barId"); + * var rule = factory.fromUrlMatcher(urlMatcher, match => "/home/" + match.fooId + "/" + match.barId); + * var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' } + * var result = rule.handler(match); // '/home/123/456' + * ``` + * + * ## Handler as UrlMatcher + * + * If `handler` is a UrlMatcher, the handler matcher is used to create the new url. + * The `handler` UrlMatcher is formatted using the matched param from the first matcher. + * The url is replaced with the result. + * + * #### Example: + * ```js + * var urlMatcher = $umf.compile("/foo/:fooId/:barId"); + * var handler = $umf.compile("/home/:fooId/:barId"); + * var rule = factory.fromUrlMatcher(urlMatcher, handler); + * var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' } + * var result = rule.handler(match); // '/home/123/456' + * ``` + */ + UrlRuleFactory.prototype.fromUrlMatcher = function (urlMatcher, handler) { + var _handler = handler; + if (isString(handler)) + handler = this.router.urlMatcherFactory.compile(handler); + if (is(UrlMatcher)(handler)) + _handler = function (match) { return handler.format(match); }; + function match(url) { + var match = urlMatcher.exec(url.path, url.search, url.hash); + return urlMatcher.validates(match) && match; + } + // Prioritize URLs, lowest to highest: + // - Some optional URL parameters, but none matched + // - No optional parameters in URL + // - Some optional parameters, some matched + // - Some optional parameters, all matched + function matchPriority(params) { + var optional = urlMatcher.parameters().filter(function (param) { return param.isOptional; }); + if (!optional.length) + return 0.000001; + var matched = optional.filter(function (param) { return params[param.id]; }); + return matched.length / optional.length; + } + var details = { urlMatcher: urlMatcher, matchPriority: matchPriority, type: "URLMATCHER" }; + return extend(new BaseUrlRule(match, _handler), details); + }; + /** + * A UrlRule which matches a state by its url + * + * #### Example: + * ```js + * var rule = factory.fromState($state.get('foo'), router); + * var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' } + * var result = rule.handler(match); + * // Starts a transition to 'foo' with params: { fooId: '123', barId: '456' } + * ``` + */ + UrlRuleFactory.prototype.fromState = function (state, router) { + /** + * Handles match by transitioning to matched state + * + * First checks if the router should start a new transition. + * A new transition is not required if the current state's URL + * and the new URL are already identical + */ + var handler = function (match) { + var $state = router.stateService; + var globals = router.globals; + if ($state.href(state, match) !== $state.href(globals.current, globals.params)) { + $state.transitionTo(state, match, { inherit: true, source: "url" }); + } + }; + var details = { state: state, type: "STATE" }; + return extend(this.fromUrlMatcher(state.url, handler), details); + }; + /** + * A UrlRule which matches based on a regular expression + * + * The `handler` may be either a [[UrlRuleHandlerFn]] or a string. + * + * ## Handler as a function + * + * If `handler` is a function, the function is invoked with: + * + * - regexp match array (from `regexp`) + * - url: the current Url ([[UrlParts]]) + * - router: the router object ([[UIRouter]]) + * + * #### Example: + * ```js + * var rule = factory.fromRegExp(/^\/foo\/(bar|baz)$/, match => "/home/" + match[1]) + * var match = rule.match('/foo/bar'); // results in [ '/foo/bar', 'bar' ] + * var result = rule.handler(match); // '/home/bar' + * ``` + * + * ## Handler as string + * + * If `handler` is a string, the url is *replaced by the string* when the Rule is invoked. + * The string is first interpolated using `string.replace()` style pattern. + * + * #### Example: + * ```js + * var rule = factory.fromRegExp(/^\/foo\/(bar|baz)$/, "/home/$1") + * var match = rule.match('/foo/bar'); // results in [ '/foo/bar', 'bar' ] + * var result = rule.handler(match); // '/home/bar' + * ``` + */ + UrlRuleFactory.prototype.fromRegExp = function (regexp, handler) { + if (regexp.global || regexp.sticky) + throw new Error("Rule RegExp must not be global or sticky"); + /** + * If handler is a string, the url will be replaced by the string. + * If the string has any String.replace() style variables in it (like `$2`), + * they will be replaced by the captures from [[match]] + */ + var redirectUrlTo = function (match) { + // Interpolates matched values into $1 $2, etc using a String.replace()-style pattern + return handler.replace(/\$(\$|\d{1,2})/, function (m, what) { + return match[what === '$' ? 0 : Number(what)]; + }); + }; + var _handler = isString(handler) ? redirectUrlTo : handler; + var match = function (url) { + return regexp.exec(url.path); + }; + var details = { regexp: regexp, type: "REGEXP" }; + return extend(new BaseUrlRule(match, _handler), details); + }; + UrlRuleFactory.isUrlRule = function (obj) { + return obj && ['type', 'match', 'handler'].every(function (key) { return isDefined(obj[key]); }); + }; + return UrlRuleFactory; +}()); +/** + * A base rule which calls `match` + * + * The value from the `match` function is passed through to the `handler`. + * @internalapi + */ +var BaseUrlRule = /** @class */ (function () { + function BaseUrlRule(match, handler) { + var _this = this; + this.match = match; + this.type = "RAW"; + this.matchPriority = function (match) { return 0 - _this.$id; }; + this.handler = handler || identity; + } + return BaseUrlRule; +}()); + +/** + * @internalapi + * @module url + */ +/** for typedoc */ +/** @hidden */ +function appendBasePath(url, isHtml5, absolute, baseHref) { + if (baseHref === '/') + return url; + if (isHtml5) + return stripFile(baseHref) + url; + if (absolute) + return baseHref.slice(1) + url; + return url; +} +/** @hidden */ +var prioritySort = function (a, b) { + return (b.priority || 0) - (a.priority || 0); +}; +/** @hidden */ +var typeSort = function (a, b) { + var weights = { "STATE": 4, "URLMATCHER": 4, "REGEXP": 3, "RAW": 2, "OTHER": 1 }; + return (weights[a.type] || 0) - (weights[b.type] || 0); +}; +/** @hidden */ +var urlMatcherSort = function (a, b) { + return !a.urlMatcher || !b.urlMatcher ? 0 : UrlMatcher.compare(a.urlMatcher, b.urlMatcher); +}; +/** @hidden */ +var idSort = function (a, b) { + // Identically sorted STATE and URLMATCHER best rule will be chosen by `matchPriority` after each rule matches the URL + var useMatchPriority = { STATE: true, URLMATCHER: true }; + var equal = useMatchPriority[a.type] && useMatchPriority[b.type]; + return equal ? 0 : (a.$id || 0) - (b.$id || 0); +}; +/** + * Default rule priority sorting function. + * + * Sorts rules by: + * + * - Explicit priority (set rule priority using [[UrlRulesApi.when]]) + * - Rule type (STATE: 4, URLMATCHER: 4, REGEXP: 3, RAW: 2, OTHER: 1) + * - `UrlMatcher` specificity ([[UrlMatcher.compare]]): works for STATE and URLMATCHER types to pick the most specific rule. + * - Rule registration order (for rule types other than STATE and URLMATCHER) + * - Equally sorted State and UrlMatcher rules will each match the URL. + * Then, the *best* match is chosen based on how many parameter values were matched. + * + * @coreapi + */ +var defaultRuleSortFn; +defaultRuleSortFn = function (a, b) { + var cmp = prioritySort(a, b); + if (cmp !== 0) + return cmp; + cmp = typeSort(a, b); + if (cmp !== 0) + return cmp; + cmp = urlMatcherSort(a, b); + if (cmp !== 0) + return cmp; + return idSort(a, b); +}; +/** + * Updates URL and responds to URL changes + * + * ### Deprecation warning: + * This class is now considered to be an internal API + * Use the [[UrlService]] instead. + * For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]]. + * + * This class updates the URL when the state changes. + * It also responds to changes in the URL. + */ +var UrlRouter = /** @class */ (function () { + /** @hidden */ + function UrlRouter(router) { + /** @hidden */ this._sortFn = defaultRuleSortFn; + /** @hidden */ this._rules = []; + /** @hidden */ this.interceptDeferred = false; + /** @hidden */ this._id = 0; + /** @hidden */ this._sorted = false; + this._router = router; + this.urlRuleFactory = new UrlRuleFactory(router); + createProxyFunctions(val(UrlRouter.prototype), this, val(this)); + } + /** @internalapi */ + UrlRouter.prototype.dispose = function () { + this.listen(false); + this._rules = []; + delete this._otherwiseFn; + }; + /** @inheritdoc */ + UrlRouter.prototype.sort = function (compareFn) { + this._rules = this.stableSort(this._rules, this._sortFn = compareFn || this._sortFn); + this._sorted = true; + }; + UrlRouter.prototype.ensureSorted = function () { + this._sorted || this.sort(); + }; + UrlRouter.prototype.stableSort = function (arr, compareFn) { + var arrOfWrapper = arr.map(function (elem, idx) { return ({ elem: elem, idx: idx }); }); + arrOfWrapper.sort(function (wrapperA, wrapperB) { + var cmpDiff = compareFn(wrapperA.elem, wrapperB.elem); + return cmpDiff === 0 + ? wrapperA.idx - wrapperB.idx + : cmpDiff; + }); + return arrOfWrapper.map(function (wrapper) { return wrapper.elem; }); + }; + /** + * Given a URL, check all rules and return the best [[MatchResult]] + * @param url + * @returns {MatchResult} + */ + UrlRouter.prototype.match = function (url) { + var _this = this; + this.ensureSorted(); + url = extend({ path: '', search: {}, hash: '' }, url); + var rules = this.rules(); + if (this._otherwiseFn) + rules.push(this._otherwiseFn); + // Checks a single rule. Returns { rule: rule, match: match, weight: weight } if it matched, or undefined + var checkRule = function (rule) { + var match = rule.match(url, _this._router); + return match && { match: match, rule: rule, weight: rule.matchPriority(match) }; + }; + // The rules are pre-sorted. + // - Find the first matching rule. + // - Find any other matching rule that sorted *exactly the same*, according to `.sort()`. + // - Choose the rule with the highest match weight. + var best; + for (var i = 0; i < rules.length; i++) { + // Stop when there is a 'best' rule and the next rule sorts differently than it. + if (best && this._sortFn(rules[i], best.rule) !== 0) + break; + var current = checkRule(rules[i]); + // Pick the best MatchResult + best = (!best || current && current.weight > best.weight) ? current : best; + } + return best; + }; + /** @inheritdoc */ + UrlRouter.prototype.sync = function (evt) { + if (evt && evt.defaultPrevented) + return; + var router = this._router, $url = router.urlService, $state = router.stateService; + var url = { + path: $url.path(), search: $url.search(), hash: $url.hash(), + }; + var best = this.match(url); + var applyResult = pattern([ + [isString, function (newurl) { return $url.url(newurl, true); }], + [TargetState.isDef, function (def) { return $state.go(def.state, def.params, def.options); }], + [is(TargetState), function (target) { return $state.go(target.state(), target.params(), target.options()); }], + ]); + applyResult(best && best.rule.handler(best.match, url, router)); + }; + /** @inheritdoc */ + UrlRouter.prototype.listen = function (enabled) { + var _this = this; + if (enabled === false) { + this._stopFn && this._stopFn(); + delete this._stopFn; + } + else { + return this._stopFn = this._stopFn || this._router.urlService.onChange(function (evt) { return _this.sync(evt); }); + } + }; + /** + * Internal API. + * @internalapi + */ + UrlRouter.prototype.update = function (read) { + var $url = this._router.locationService; + if (read) { + this.location = $url.path(); + return; + } + if ($url.path() === this.location) + return; + $url.url(this.location, true); + }; + /** + * Internal API. + * + * Pushes a new location to the browser history. + * + * @internalapi + * @param urlMatcher + * @param params + * @param options + */ + UrlRouter.prototype.push = function (urlMatcher, params, options) { + var replace = options && !!options.replace; + this._router.urlService.url(urlMatcher.format(params || {}), replace); + }; + /** + * Builds and returns a URL with interpolated parameters + * + * #### Example: + * ```js + * matcher = $umf.compile("/about/:person"); + * params = { person: "bob" }; + * $bob = $urlRouter.href(matcher, params); + * // $bob == "/about/bob"; + * ``` + * + * @param urlMatcher The [[UrlMatcher]] object which is used as the template of the URL to generate. + * @param params An object of parameter values to fill the matcher's required parameters. + * @param options Options object. The options are: + * + * - **`absolute`** - {boolean=false}, If true will generate an absolute url, e.g. "http://www.example.com/fullurl". + * + * @returns Returns the fully compiled URL, or `null` if `params` fail validation against `urlMatcher` + */ + UrlRouter.prototype.href = function (urlMatcher, params, options) { + var url = urlMatcher.format(params); + if (url == null) + return null; + options = options || { absolute: false }; + var cfg = this._router.urlService.config; + var isHtml5 = cfg.html5Mode(); + if (!isHtml5 && url !== null) { + url = "#" + cfg.hashPrefix() + url; + } + url = appendBasePath(url, isHtml5, options.absolute, cfg.baseHref()); + if (!options.absolute || !url) { + return url; + } + var slash = (!isHtml5 && url ? '/' : ''), port = cfg.port(); + port = (port === 80 || port === 443 ? '' : ':' + port); + return [cfg.protocol(), '://', cfg.host(), port, slash, url].join(''); + }; + /** + * Manually adds a URL Rule. + * + * Usually, a url rule is added using [[StateDeclaration.url]] or [[when]]. + * This api can be used directly for more control (to register a [[BaseUrlRule]], for example). + * Rules can be created using [[UrlRouter.urlRuleFactory]], or create manually as simple objects. + * + * A rule should have a `match` function which returns truthy if the rule matched. + * It should also have a `handler` function which is invoked if the rule is the best match. + * + * @return a function that deregisters the rule + */ + UrlRouter.prototype.rule = function (rule) { + var _this = this; + if (!UrlRuleFactory.isUrlRule(rule)) + throw new Error("invalid rule"); + rule.$id = this._id++; + rule.priority = rule.priority || 0; + this._rules.push(rule); + this._sorted = false; + return function () { return _this.removeRule(rule); }; + }; + /** @inheritdoc */ + UrlRouter.prototype.removeRule = function (rule) { + removeFrom(this._rules, rule); + }; + /** @inheritdoc */ + UrlRouter.prototype.rules = function () { + this.ensureSorted(); + return this._rules.slice(); + }; + /** @inheritdoc */ + UrlRouter.prototype.otherwise = function (handler) { + var handlerFn = getHandlerFn(handler); + this._otherwiseFn = this.urlRuleFactory.create(val(true), handlerFn); + this._sorted = false; + }; + + /** @inheritdoc */ + UrlRouter.prototype.initial = function (handler) { + var handlerFn = getHandlerFn(handler); + var matchFn = function (urlParts, router) { + return router.globals.transitionHistory.size() === 0 && !!/^\/?$/.exec(urlParts.path); + }; + this.rule(this.urlRuleFactory.create(matchFn, handlerFn)); + }; + + /** @inheritdoc */ + UrlRouter.prototype.when = function (matcher, handler, options) { + var rule = this.urlRuleFactory.create(matcher, handler); + if (isDefined(options && options.priority)) + rule.priority = options.priority; + this.rule(rule); + return rule; + }; + + /** @inheritdoc */ + UrlRouter.prototype.deferIntercept = function (defer) { + if (defer === undefined) + defer = true; + this.interceptDeferred = defer; + }; + + return UrlRouter; +}()); +function getHandlerFn(handler) { + if (!isFunction(handler) && !isString(handler) && !is(TargetState)(handler) && !TargetState.isDef(handler)) { + throw new Error("'handler' must be a string, function, TargetState, or have a state: 'newtarget' property"); + } + return isFunction(handler) ? handler : val(handler); +} + +/** + * @coreapi + * @module view + */ /** for typedoc */ +/** + * The View service + * + * This service pairs existing `ui-view` components (which live in the DOM) + * with view configs (from the state declaration objects: [[StateDeclaration.views]]). + * + * - After a successful Transition, the views from the newly entered states are activated via [[activateViewConfig]]. + * The views from exited states are deactivated via [[deactivateViewConfig]]. + * (See: the [[registerActivateViews]] Transition Hook) + * + * - As `ui-view` components pop in and out of existence, they register themselves using [[registerUIView]]. + * + * - When the [[sync]] function is called, the registered `ui-view`(s) ([[ActiveUIView]]) + * are configured with the matching [[ViewConfig]](s) + * + */ +var ViewService = /** @class */ (function () { + function ViewService() { + var _this = this; + this._uiViews = []; + this._viewConfigs = []; + this._viewConfigFactories = {}; + this._pluginapi = { + _rootViewContext: this._rootViewContext.bind(this), + _viewConfigFactory: this._viewConfigFactory.bind(this), + _registeredUIViews: function () { return _this._uiViews; }, + _activeViewConfigs: function () { return _this._viewConfigs; }, + }; + } + ViewService.prototype._rootViewContext = function (context) { + return this._rootContext = context || this._rootContext; + }; + + ViewService.prototype._viewConfigFactory = function (viewType, factory) { + this._viewConfigFactories[viewType] = factory; + }; + ViewService.prototype.createViewConfig = function (path, decl) { + var cfgFactory = this._viewConfigFactories[decl.$type]; + if (!cfgFactory) + throw new Error("ViewService: No view config factory registered for type " + decl.$type); + var cfgs = cfgFactory(path, decl); + return isArray(cfgs) ? cfgs : [cfgs]; + }; + /** + * Deactivates a ViewConfig. + * + * This function deactivates a `ViewConfig`. + * After calling [[sync]], it will un-pair from any `ui-view` with which it is currently paired. + * + * @param viewConfig The ViewConfig view to deregister. + */ + ViewService.prototype.deactivateViewConfig = function (viewConfig) { + trace.traceViewServiceEvent("<- Removing", viewConfig); + removeFrom(this._viewConfigs, viewConfig); + }; + ViewService.prototype.activateViewConfig = function (viewConfig) { + trace.traceViewServiceEvent("-> Registering", viewConfig); + this._viewConfigs.push(viewConfig); + }; + ViewService.prototype.sync = function () { + var _this = this; + var uiViewsByFqn = this._uiViews.map(function (uiv) { return [uiv.fqn, uiv]; }).reduce(applyPairs, {}); + // Return a weighted depth value for a uiView. + // The depth is the nesting depth of ui-views (based on FQN; times 10,000) + // plus the depth of the state that is populating the uiView + function uiViewDepth(uiView) { + var stateDepth = function (context) { + return context && context.parent ? stateDepth(context.parent) + 1 : 1; + }; + return (uiView.fqn.split(".").length * 10000) + stateDepth(uiView.creationContext); + } + // Return the ViewConfig's context's depth in the context tree. + function viewConfigDepth(config) { + var context = config.viewDecl.$context, count = 0; + while (++count && context.parent) + context = context.parent; + return count; + } + // Given a depth function, returns a compare function which can return either ascending or descending order + var depthCompare = curry(function (depthFn, posNeg, left, right) { return posNeg * (depthFn(left) - depthFn(right)); }); + var matchingConfigPair = function (uiView) { + var matchingConfigs = _this._viewConfigs.filter(ViewService.matches(uiViewsByFqn, uiView)); + if (matchingConfigs.length > 1) { + // This is OK. Child states can target a ui-view that the parent state also targets (the child wins) + // Sort by depth and return the match from the deepest child + // console.log(`Multiple matching view configs for ${uiView.fqn}`, matchingConfigs); + matchingConfigs.sort(depthCompare(viewConfigDepth, -1)); // descending + } + return [uiView, matchingConfigs[0]]; + }; + var configureUIView = function (_a) { + var uiView = _a[0], viewConfig = _a[1]; + // If a parent ui-view is reconfigured, it could destroy child ui-views. + // Before configuring a child ui-view, make sure it's still in the active uiViews array. + if (_this._uiViews.indexOf(uiView) !== -1) + uiView.configUpdated(viewConfig); + }; + // Sort views by FQN and state depth. Process uiviews nearest the root first. + var pairs$$1 = this._uiViews.sort(depthCompare(uiViewDepth, 1)).map(matchingConfigPair); + trace.traceViewSync(pairs$$1); + pairs$$1.forEach(configureUIView); + }; + + /** + * Registers a `ui-view` component + * + * When a `ui-view` component is created, it uses this method to register itself. + * After registration the [[sync]] method is used to ensure all `ui-view` are configured with the proper [[ViewConfig]]. + * + * Note: the `ui-view` component uses the `ViewConfig` to determine what view should be loaded inside the `ui-view`, + * and what the view's state context is. + * + * Note: There is no corresponding `deregisterUIView`. + * A `ui-view` should hang on to the return value of `registerUIView` and invoke it to deregister itself. + * + * @param uiView The metadata for a UIView + * @return a de-registration function used when the view is destroyed. + */ + ViewService.prototype.registerUIView = function (uiView) { + trace.traceViewServiceUIViewEvent("-> Registering", uiView); + var uiViews = this._uiViews; + var fqnAndTypeMatches = function (uiv) { return uiv.fqn === uiView.fqn && uiv.$type === uiView.$type; }; + if (uiViews.filter(fqnAndTypeMatches).length) + trace.traceViewServiceUIViewEvent("!!!! duplicate uiView named:", uiView); + uiViews.push(uiView); + this.sync(); + return function () { + var idx = uiViews.indexOf(uiView); + if (idx === -1) { + trace.traceViewServiceUIViewEvent("Tried removing non-registered uiView", uiView); + return; + } + trace.traceViewServiceUIViewEvent("<- Deregistering", uiView); + removeFrom(uiViews)(uiView); + }; + }; + + /** + * Returns the list of views currently available on the page, by fully-qualified name. + * + * @return {Array} Returns an array of fully-qualified view names. + */ + ViewService.prototype.available = function () { + return this._uiViews.map(prop("fqn")); + }; + /** + * Returns the list of views on the page containing loaded content. + * + * @return {Array} Returns an array of fully-qualified view names. + */ + ViewService.prototype.active = function () { + return this._uiViews.filter(prop("$config")).map(prop("name")); + }; + /** + * Normalizes a view's name from a state.views configuration block. + * + * This should be used by a framework implementation to calculate the values for + * [[_ViewDeclaration.$uiViewName]] and [[_ViewDeclaration.$uiViewContextAnchor]]. + * + * @param context the context object (state declaration) that the view belongs to + * @param rawViewName the name of the view, as declared in the [[StateDeclaration.views]] + * + * @returns the normalized uiViewName and uiViewContextAnchor that the view targets + */ + ViewService.normalizeUIViewTarget = function (context, rawViewName) { + if (rawViewName === void 0) { rawViewName = ""; } + // TODO: Validate incoming view name with a regexp to allow: + // ex: "view.name@foo.bar" , "^.^.view.name" , "view.name@^.^" , "" , + // "@" , "$default@^" , "!$default.$default" , "!foo.bar" + var viewAtContext = rawViewName.split("@"); + var uiViewName = viewAtContext[0] || "$default"; // default to unnamed view + var uiViewContextAnchor = isString(viewAtContext[1]) ? viewAtContext[1] : "^"; // default to parent context + // Handle relative view-name sugar syntax. + // Matches rawViewName "^.^.^.foo.bar" into array: ["^.^.^.foo.bar", "^.^.^", "foo.bar"], + var relativeViewNameSugar = /^(\^(?:\.\^)*)\.(.*$)/.exec(uiViewName); + if (relativeViewNameSugar) { + // Clobbers existing contextAnchor (rawViewName validation will fix this) + uiViewContextAnchor = relativeViewNameSugar[1]; // set anchor to "^.^.^" + uiViewName = relativeViewNameSugar[2]; // set view-name to "foo.bar" + } + if (uiViewName.charAt(0) === '!') { + uiViewName = uiViewName.substr(1); + uiViewContextAnchor = ""; // target absolutely from root + } + // handle parent relative targeting "^.^.^" + var relativeMatch = /^(\^(?:\.\^)*)$/; + if (relativeMatch.exec(uiViewContextAnchor)) { + var anchor = uiViewContextAnchor.split(".").reduce((function (anchor, x) { return anchor.parent; }), context); + uiViewContextAnchor = anchor.name; + } + else if (uiViewContextAnchor === '.') { + uiViewContextAnchor = context.name; + } + return { uiViewName: uiViewName, uiViewContextAnchor: uiViewContextAnchor }; + }; + /** + * Given a ui-view and a ViewConfig, determines if they "match". + * + * A ui-view has a fully qualified name (fqn) and a context object. The fqn is built from its overall location in + * the DOM, describing its nesting relationship to any parent ui-view tags it is nested inside of. + * + * A ViewConfig has a target ui-view name and a context anchor. The ui-view name can be a simple name, or + * can be a segmented ui-view path, describing a portion of a ui-view fqn. + * + * In order for a ui-view to match ViewConfig, ui-view's $type must match the ViewConfig's $type + * + * If the ViewConfig's target ui-view name is a simple name (no dots), then a ui-view matches if: + * - the ui-view's name matches the ViewConfig's target name + * - the ui-view's context matches the ViewConfig's anchor + * + * If the ViewConfig's target ui-view name is a segmented name (with dots), then a ui-view matches if: + * - There exists a parent ui-view where: + * - the parent ui-view's name matches the first segment (index 0) of the ViewConfig's target name + * - the parent ui-view's context matches the ViewConfig's anchor + * - And the remaining segments (index 1..n) of the ViewConfig's target name match the tail of the ui-view's fqn + * + * Example: + * + * DOM: + * + * + * + * + * + * + * + * + * + * uiViews: [ + * { fqn: "$default", creationContext: { name: "" } }, + * { fqn: "$default.foo", creationContext: { name: "A" } }, + * { fqn: "$default.foo.$default", creationContext: { name: "A.B" } } + * { fqn: "$default.foo.$default.bar", creationContext: { name: "A.B.C" } } + * ] + * + * These four view configs all match the ui-view with the fqn: "$default.foo.$default.bar": + * + * - ViewConfig1: { uiViewName: "bar", uiViewContextAnchor: "A.B.C" } + * - ViewConfig2: { uiViewName: "$default.bar", uiViewContextAnchor: "A.B" } + * - ViewConfig3: { uiViewName: "foo.$default.bar", uiViewContextAnchor: "A" } + * - ViewConfig4: { uiViewName: "$default.foo.$default.bar", uiViewContextAnchor: "" } + * + * Using ViewConfig3 as an example, it matches the ui-view with fqn "$default.foo.$default.bar" because: + * - The ViewConfig's segmented target name is: [ "foo", "$default", "bar" ] + * - There exists a parent ui-view (which has fqn: "$default.foo") where: + * - the parent ui-view's name "foo" matches the first segment "foo" of the ViewConfig's target name + * - the parent ui-view's context "A" matches the ViewConfig's anchor context "A" + * - And the remaining segments [ "$default", "bar" ].join("."_ of the ViewConfig's target name match + * the tail of the ui-view's fqn "default.bar" + * + * @internalapi + */ + ViewService.matches = function (uiViewsByFqn, uiView) { return function (viewConfig) { + // Don't supply an ng1 ui-view with an ng2 ViewConfig, etc + if (uiView.$type !== viewConfig.viewDecl.$type) + return false; + // Split names apart from both viewConfig and uiView into segments + var vc = viewConfig.viewDecl; + var vcSegments = vc.$uiViewName.split("."); + var uivSegments = uiView.fqn.split("."); + // Check if the tails of the segment arrays match. ex, these arrays' tails match: + // vc: ["foo", "bar"], uiv fqn: ["$default", "foo", "bar"] + if (!equals(vcSegments, uivSegments.slice(0 - vcSegments.length))) + return false; + // Now check if the fqn ending at the first segment of the viewConfig matches the context: + // ["$default", "foo"].join(".") == "$default.foo", does the ui-view $default.foo context match? + var negOffset = (1 - vcSegments.length) || undefined; + var fqnToFirstSegment = uivSegments.slice(0, negOffset).join("."); + var uiViewContext = uiViewsByFqn[fqnToFirstSegment].creationContext; + return vc.$uiViewContextAnchor === (uiViewContext && uiViewContext.name); + }; }; + return ViewService; +}()); + +/** + * @coreapi + * @module core + */ /** */ +/** + * Global router state + * + * This is where we hold the global mutable state such as current state, current + * params, current transition, etc. + */ +var UIRouterGlobals = /** @class */ (function () { + function UIRouterGlobals() { + /** + * Current parameter values + * + * The parameter values from the latest successful transition + */ + this.params = new StateParams(); + /** @internalapi */ + this.lastStartedTransitionId = -1; + /** @internalapi */ + this.transitionHistory = new Queue([], 1); + /** @internalapi */ + this.successfulTransitions = new Queue([], 1); + } + UIRouterGlobals.prototype.dispose = function () { + this.transitionHistory.clear(); + this.successfulTransitions.clear(); + this.transition = null; + }; + return UIRouterGlobals; +}()); + +/** + * @coreapi + * @module url + */ /** */ +/** @hidden */ +var makeStub = function (keys) { + return keys.reduce(function (acc, key) { return (acc[key] = notImplemented(key), acc); }, { dispose: noop$1 }); +}; +/** @hidden */ var locationServicesFns = ["url", "path", "search", "hash", "onChange"]; +/** @hidden */ var locationConfigFns = ["port", "protocol", "host", "baseHref", "html5Mode", "hashPrefix"]; +/** @hidden */ var umfFns = ["type", "caseInsensitive", "strictMode", "defaultSquashPolicy"]; +/** @hidden */ var rulesFns = ["sort", "when", "initial", "otherwise", "rules", "rule", "removeRule"]; +/** @hidden */ var syncFns = ["deferIntercept", "listen", "sync", "match"]; +/** + * API for URL management + */ +var UrlService = /** @class */ (function () { + /** @hidden */ + function UrlService(router, lateBind) { + if (lateBind === void 0) { lateBind = true; } + this.router = router; + this.rules = {}; + this.config = {}; + // proxy function calls from UrlService to the LocationService/LocationConfig + var locationServices = function () { return router.locationService; }; + createProxyFunctions(locationServices, this, locationServices, locationServicesFns, lateBind); + var locationConfig = function () { return router.locationConfig; }; + createProxyFunctions(locationConfig, this.config, locationConfig, locationConfigFns, lateBind); + var umf = function () { return router.urlMatcherFactory; }; + createProxyFunctions(umf, this.config, umf, umfFns); + var urlRouter = function () { return router.urlRouter; }; + createProxyFunctions(urlRouter, this.rules, urlRouter, rulesFns); + createProxyFunctions(urlRouter, this, urlRouter, syncFns); + } + UrlService.prototype.url = function (newurl, replace, state) { return; }; + + /** @inheritdoc */ + UrlService.prototype.path = function () { return; }; + + /** @inheritdoc */ + UrlService.prototype.search = function () { return; }; + + /** @inheritdoc */ + UrlService.prototype.hash = function () { return; }; + + /** @inheritdoc */ + UrlService.prototype.onChange = function (callback) { return; }; + + /** + * Returns the current URL parts + * + * This method returns the current URL components as a [[UrlParts]] object. + * + * @returns the current url parts + */ + UrlService.prototype.parts = function () { + return { path: this.path(), search: this.search(), hash: this.hash() }; + }; + UrlService.prototype.dispose = function () { }; + /** @inheritdoc */ + UrlService.prototype.sync = function (evt) { return; }; + /** @inheritdoc */ + UrlService.prototype.listen = function (enabled) { return; }; + + /** @inheritdoc */ + UrlService.prototype.deferIntercept = function (defer) { return; }; + /** @inheritdoc */ + UrlService.prototype.match = function (urlParts) { return; }; + /** @hidden */ + UrlService.locationServiceStub = makeStub(locationServicesFns); + /** @hidden */ + UrlService.locationConfigStub = makeStub(locationConfigFns); + return UrlService; +}()); + +/** + * @coreapi + * @module core + */ /** */ +/** @hidden */ +var _routerInstance = 0; +/** + * The master class used to instantiate an instance of UI-Router. + * + * UI-Router (for each specific framework) will create an instance of this class during bootstrap. + * This class instantiates and wires the UI-Router services together. + * + * After a new instance of the UIRouter class is created, it should be configured for your app. + * For instance, app states should be registered with the [[UIRouter.stateRegistry]]. + * + * --- + * + * Normally the framework code will bootstrap UI-Router. + * If you are bootstrapping UIRouter manually, tell it to monitor the URL by calling + * [[UrlService.listen]] then [[UrlService.sync]]. + */ +var UIRouter = /** @class */ (function () { + /** + * Creates a new `UIRouter` object + * + * @param locationService a [[LocationServices]] implementation + * @param locationConfig a [[LocationConfig]] implementation + * @internalapi + */ + function UIRouter(locationService, locationConfig) { + if (locationService === void 0) { locationService = UrlService.locationServiceStub; } + if (locationConfig === void 0) { locationConfig = UrlService.locationConfigStub; } + this.locationService = locationService; + this.locationConfig = locationConfig; + /** @hidden */ this.$id = _routerInstance++; + /** @hidden */ this._disposed = false; + /** @hidden */ this._disposables = []; + /** Provides trace information to the console */ + this.trace = trace; + /** Provides services related to ui-view synchronization */ + this.viewService = new ViewService(); + /** Provides services related to Transitions */ + this.transitionService = new TransitionService(this); + /** Global router state */ + this.globals = new UIRouterGlobals(); + /** + * Deprecated for public use. Use [[urlService]] instead. + * @deprecated Use [[urlService]] instead + */ + this.urlMatcherFactory = new UrlMatcherFactory(); + /** + * Deprecated for public use. Use [[urlService]] instead. + * @deprecated Use [[urlService]] instead + */ + this.urlRouter = new UrlRouter(this); + /** Provides a registry for states, and related registration services */ + this.stateRegistry = new StateRegistry(this); + /** Provides services related to states */ + this.stateService = new StateService(this); + /** Provides services related to the URL */ + this.urlService = new UrlService(this); + /** @hidden */ + this._plugins = {}; + this.viewService._pluginapi._rootViewContext(this.stateRegistry.root()); + this.globals.$current = this.stateRegistry.root(); + this.globals.current = this.globals.$current.self; + this.disposable(this.globals); + this.disposable(this.stateService); + this.disposable(this.stateRegistry); + this.disposable(this.transitionService); + this.disposable(this.urlRouter); + this.disposable(locationService); + this.disposable(locationConfig); + } + /** Registers an object to be notified when the router is disposed */ + UIRouter.prototype.disposable = function (disposable) { + this._disposables.push(disposable); + }; + /** + * Disposes this router instance + * + * When called, clears resources retained by the router by calling `dispose(this)` on all + * registered [[disposable]] objects. + * + * Or, if a `disposable` object is provided, calls `dispose(this)` on that object only. + * + * @param disposable (optional) the disposable to dispose + */ + UIRouter.prototype.dispose = function (disposable) { + var _this = this; + if (disposable && isFunction(disposable.dispose)) { + disposable.dispose(this); + return undefined; + } + this._disposed = true; + this._disposables.slice().forEach(function (d) { + try { + typeof d.dispose === 'function' && d.dispose(_this); + removeFrom(_this._disposables, d); + } + catch (ignored) { } + }); + }; + /** + * Adds a plugin to UI-Router + * + * This method adds a UI-Router Plugin. + * A plugin can enhance or change UI-Router behavior using any public API. + * + * #### Example: + * ```js + * import { MyCoolPlugin } from "ui-router-cool-plugin"; + * + * var plugin = router.addPlugin(MyCoolPlugin); + * ``` + * + * ### Plugin authoring + * + * A plugin is simply a class (or constructor function) which accepts a [[UIRouter]] instance and (optionally) an options object. + * + * The plugin can implement its functionality using any of the public APIs of [[UIRouter]]. + * For example, it may configure router options or add a Transition Hook. + * + * The plugin can then be published as a separate module. + * + * #### Example: + * ```js + * export class MyAuthPlugin implements UIRouterPlugin { + * constructor(router: UIRouter, options: any) { + * this.name = "MyAuthPlugin"; + * let $transitions = router.transitionService; + * let $state = router.stateService; + * + * let authCriteria = { + * to: (state) => state.data && state.data.requiresAuth + * }; + * + * function authHook(transition: Transition) { + * let authService = transition.injector().get('AuthService'); + * if (!authService.isAuthenticated()) { + * return $state.target('login'); + * } + * } + * + * $transitions.onStart(authCriteria, authHook); + * } + * } + * ``` + * + * @param plugin one of: + * - a plugin class which implements [[UIRouterPlugin]] + * - a constructor function for a [[UIRouterPlugin]] which accepts a [[UIRouter]] instance + * - a factory function which accepts a [[UIRouter]] instance and returns a [[UIRouterPlugin]] instance + * @param options options to pass to the plugin class/factory + * @returns the registered plugin instance + */ + UIRouter.prototype.plugin = function (plugin, options) { + if (options === void 0) { options = {}; } + var pluginInstance = new plugin(this, options); + if (!pluginInstance.name) + throw new Error("Required property `name` missing on plugin: " + pluginInstance); + this._disposables.push(pluginInstance); + return this._plugins[pluginInstance.name] = pluginInstance; + }; + UIRouter.prototype.getPlugin = function (pluginName) { + return pluginName ? this._plugins[pluginName] : values(this._plugins); + }; + return UIRouter; +}()); + +/** @module hooks */ /** */ +function addCoreResolvables(trans) { + trans.addResolvable({ token: UIRouter, deps: [], resolveFn: function () { return trans.router; }, data: trans.router }, ""); + trans.addResolvable({ token: Transition, deps: [], resolveFn: function () { return trans; }, data: trans }, ""); + trans.addResolvable({ token: '$transition$', deps: [], resolveFn: function () { return trans; }, data: trans }, ""); + trans.addResolvable({ token: '$stateParams', deps: [], resolveFn: function () { return trans.params(); }, data: trans.params() }, ""); + trans.entering().forEach(function (state) { + trans.addResolvable({ token: '$state$', deps: [], resolveFn: function () { return state; }, data: state }, state); + }); +} +var registerAddCoreResolvables = function (transitionService) { + return transitionService.onCreate({}, addCoreResolvables); +}; + +/** @module hooks */ /** */ +/** + * A [[TransitionHookFn]] that redirects to a different state or params + * + * Registered using `transitionService.onStart({ to: (state) => !!state.redirectTo }, redirectHook);` + * + * See [[StateDeclaration.redirectTo]] + */ +var redirectToHook = function (trans) { + var redirect = trans.to().redirectTo; + if (!redirect) + return; + var $state = trans.router.stateService; + function handleResult(result) { + if (!result) + return; + if (result instanceof TargetState) + return result; + if (isString(result)) + return $state.target(result, trans.params(), trans.options()); + if (result['state'] || result['params']) + return $state.target(result['state'] || trans.to(), result['params'] || trans.params(), trans.options()); + } + if (isFunction(redirect)) { + return services.$q.when(redirect(trans)).then(handleResult); + } + return handleResult(redirect); +}; +var registerRedirectToHook = function (transitionService) { + return transitionService.onStart({ to: function (state) { return !!state.redirectTo; } }, redirectToHook); +}; + +/** + * A factory which creates an onEnter, onExit or onRetain transition hook function + * + * The returned function invokes the (for instance) state.onEnter hook when the + * state is being entered. + * + * @hidden + */ +function makeEnterExitRetainHook(hookName) { + return function (transition, state) { + var _state = state.$$state(); + var hookFn = _state[hookName]; + return hookFn(transition, state); + }; +} +/** + * The [[TransitionStateHookFn]] for onExit + * + * When the state is being exited, the state's .onExit function is invoked. + * + * Registered using `transitionService.onExit({ exiting: (state) => !!state.onExit }, onExitHook);` + * + * See: [[IHookRegistry.onExit]] + */ +var onExitHook = makeEnterExitRetainHook('onExit'); +var registerOnExitHook = function (transitionService) { + return transitionService.onExit({ exiting: function (state) { return !!state.onExit; } }, onExitHook); +}; +/** + * The [[TransitionStateHookFn]] for onRetain + * + * When the state was already entered, and is not being exited or re-entered, the state's .onRetain function is invoked. + * + * Registered using `transitionService.onRetain({ retained: (state) => !!state.onRetain }, onRetainHook);` + * + * See: [[IHookRegistry.onRetain]] + */ +var onRetainHook = makeEnterExitRetainHook('onRetain'); +var registerOnRetainHook = function (transitionService) { + return transitionService.onRetain({ retained: function (state) { return !!state.onRetain; } }, onRetainHook); +}; +/** + * The [[TransitionStateHookFn]] for onEnter + * + * When the state is being entered, the state's .onEnter function is invoked. + * + * Registered using `transitionService.onEnter({ entering: (state) => !!state.onEnter }, onEnterHook);` + * + * See: [[IHookRegistry.onEnter]] + */ +var onEnterHook = makeEnterExitRetainHook('onEnter'); +var registerOnEnterHook = function (transitionService) { + return transitionService.onEnter({ entering: function (state) { return !!state.onEnter; } }, onEnterHook); +}; + +/** @module hooks */ +/** for typedoc */ +/** + * A [[TransitionHookFn]] which resolves all EAGER Resolvables in the To Path + * + * Registered using `transitionService.onStart({}, eagerResolvePath);` + * + * When a Transition starts, this hook resolves all the EAGER Resolvables, which the transition then waits for. + * + * See [[StateDeclaration.resolve]] + */ +var eagerResolvePath = function (trans) { + return new ResolveContext(trans.treeChanges().to) + .resolvePath("EAGER", trans) + .then(noop$1); +}; +var registerEagerResolvePath = function (transitionService) { + return transitionService.onStart({}, eagerResolvePath, { priority: 1000 }); +}; +/** + * A [[TransitionHookFn]] which resolves all LAZY Resolvables for the state (and all its ancestors) in the To Path + * + * Registered using `transitionService.onEnter({ entering: () => true }, lazyResolveState);` + * + * When a State is being entered, this hook resolves all the Resolvables for this state, which the transition then waits for. + * + * See [[StateDeclaration.resolve]] + */ +var lazyResolveState = function (trans, state) { + return new ResolveContext(trans.treeChanges().to) + .subContext(state.$$state()) + .resolvePath("LAZY", trans) + .then(noop$1); +}; +var registerLazyResolveState = function (transitionService) { + return transitionService.onEnter({ entering: val(true) }, lazyResolveState, { priority: 1000 }); +}; + +/** @module hooks */ /** for typedoc */ +/** + * A [[TransitionHookFn]] which waits for the views to load + * + * Registered using `transitionService.onStart({}, loadEnteringViews);` + * + * Allows the views to do async work in [[ViewConfig.load]] before the transition continues. + * In angular 1, this includes loading the templates. + */ +var loadEnteringViews = function (transition) { + var $q = services.$q; + var enteringViews = transition.views("entering"); + if (!enteringViews.length) + return; + return $q.all(enteringViews.map(function (view) { return $q.when(view.load()); })).then(noop$1); +}; +var registerLoadEnteringViews = function (transitionService) { + return transitionService.onFinish({}, loadEnteringViews); +}; +/** + * A [[TransitionHookFn]] which activates the new views when a transition is successful. + * + * Registered using `transitionService.onSuccess({}, activateViews);` + * + * After a transition is complete, this hook deactivates the old views from the previous state, + * and activates the new views from the destination state. + * + * See [[ViewService]] + */ +var activateViews = function (transition) { + var enteringViews = transition.views("entering"); + var exitingViews = transition.views("exiting"); + if (!enteringViews.length && !exitingViews.length) + return; + var $view = transition.router.viewService; + exitingViews.forEach(function (vc) { return $view.deactivateViewConfig(vc); }); + enteringViews.forEach(function (vc) { return $view.activateViewConfig(vc); }); + $view.sync(); +}; +var registerActivateViews = function (transitionService) { + return transitionService.onSuccess({}, activateViews); +}; + +/** + * A [[TransitionHookFn]] which updates global UI-Router state + * + * Registered using `transitionService.onBefore({}, updateGlobalState);` + * + * Before a [[Transition]] starts, updates the global value of "the current transition" ([[Globals.transition]]). + * After a successful [[Transition]], updates the global values of "the current state" + * ([[Globals.current]] and [[Globals.$current]]) and "the current param values" ([[Globals.params]]). + * + * See also the deprecated properties: + * [[StateService.transition]], [[StateService.current]], [[StateService.params]] + */ +var updateGlobalState = function (trans) { + var globals = trans.router.globals; + var transitionSuccessful = function () { + globals.successfulTransitions.enqueue(trans); + globals.$current = trans.$to(); + globals.current = globals.$current.self; + copy(trans.params(), globals.params); + }; + var clearCurrentTransition = function () { + // Do not clear globals.transition if a different transition has started in the meantime + if (globals.transition === trans) + globals.transition = null; + }; + trans.onSuccess({}, transitionSuccessful, { priority: 10000 }); + trans.promise.then(clearCurrentTransition, clearCurrentTransition); +}; +var registerUpdateGlobalState = function (transitionService) { + return transitionService.onCreate({}, updateGlobalState); +}; + +/** + * A [[TransitionHookFn]] which updates the URL after a successful transition + * + * Registered using `transitionService.onSuccess({}, updateUrl);` + */ +var updateUrl = function (transition) { + var options = transition.options(); + var $state = transition.router.stateService; + var $urlRouter = transition.router.urlRouter; + // Dont update the url in these situations: + // The transition was triggered by a URL sync (options.source === 'url') + // The user doesn't want the url to update (options.location === false) + // The destination state, and all parents have no navigable url + if (options.source !== 'url' && options.location && $state.$current.navigable) { + var urlOptions = { replace: options.location === 'replace' }; + $urlRouter.push($state.$current.navigable.url, $state.params, urlOptions); + } + $urlRouter.update(true); +}; +var registerUpdateUrl = function (transitionService) { + return transitionService.onSuccess({}, updateUrl, { priority: 9999 }); +}; + +/** + * A [[TransitionHookFn]] that performs lazy loading + * + * When entering a state "abc" which has a `lazyLoad` function defined: + * - Invoke the `lazyLoad` function (unless it is already in process) + * - Flag the hook function as "in process" + * - The function should return a promise (that resolves when lazy loading is complete) + * - Wait for the promise to settle + * - If the promise resolves to a [[LazyLoadResult]], then register those states + * - Flag the hook function as "not in process" + * - If the hook was successful + * - Remove the `lazyLoad` function from the state declaration + * - If all the hooks were successful + * - Retry the transition (by returning a TargetState) + * + * ``` + * .state('abc', { + * component: 'fooComponent', + * lazyLoad: () => System.import('./fooComponent') + * }); + * ``` + * + * See [[StateDeclaration.lazyLoad]] + */ +var lazyLoadHook = function (transition) { + var router = transition.router; + function retryTransition() { + if (transition.originalTransition().options().source !== 'url') { + // The original transition was not triggered via url sync + // The lazy state should be loaded now, so re-try the original transition + var orig = transition.targetState(); + return router.stateService.target(orig.identifier(), orig.params(), orig.options()); + } + // The original transition was triggered via url sync + // Run the URL rules and find the best match + var $url = router.urlService; + var result = $url.match($url.parts()); + var rule = result && result.rule; + // If the best match is a state, redirect the transition (instead + // of calling sync() which supersedes the current transition) + if (rule && rule.type === "STATE") { + var state = rule.state; + var params = result.match; + return router.stateService.target(state, params, transition.options()); + } + // No matching state found, so let .sync() choose the best non-state match/otherwise + router.urlService.sync(); + } + var promises = transition.entering() + .filter(function (state) { return !!state.$$state().lazyLoad; }) + .map(function (state) { return lazyLoadState(transition, state); }); + return services.$q.all(promises).then(retryTransition); +}; +var registerLazyLoadHook = function (transitionService) { + return transitionService.onBefore({ entering: function (state) { return !!state.lazyLoad; } }, lazyLoadHook); +}; +/** + * Invokes a state's lazy load function + * + * @param transition a Transition context + * @param state the state to lazy load + * @returns A promise for the lazy load result + */ +function lazyLoadState(transition, state) { + var lazyLoadFn = state.$$state().lazyLoad; + // Store/get the lazy load promise on/from the hookfn so it doesn't get re-invoked + var promise = lazyLoadFn['_promise']; + if (!promise) { + var success = function (result) { + delete state.lazyLoad; + delete state.$$state().lazyLoad; + delete lazyLoadFn['_promise']; + return result; + }; + var error = function (err) { + delete lazyLoadFn['_promise']; + return services.$q.reject(err); + }; + promise = lazyLoadFn['_promise'] = + services.$q.when(lazyLoadFn(transition, state)) + .then(updateStateRegistry) + .then(success, error); + } + /** Register any lazy loaded state definitions */ + function updateStateRegistry(result) { + if (result && Array.isArray(result.states)) { + result.states.forEach(function (state) { return transition.router.stateRegistry.register(state); }); + } + return result; + } + return promise; +} + +/** + * This class defines a type of hook, such as `onBefore` or `onEnter`. + * Plugins can define custom hook types, such as sticky states does for `onInactive`. + * + * @interalapi + */ +var TransitionEventType = /** @class */ (function () { + function TransitionEventType(name, hookPhase, hookOrder, criteriaMatchPath, reverseSort, getResultHandler, getErrorHandler, synchronous) { + if (reverseSort === void 0) { reverseSort = false; } + if (getResultHandler === void 0) { getResultHandler = TransitionHook.HANDLE_RESULT; } + if (getErrorHandler === void 0) { getErrorHandler = TransitionHook.REJECT_ERROR; } + if (synchronous === void 0) { synchronous = false; } + this.name = name; + this.hookPhase = hookPhase; + this.hookOrder = hookOrder; + this.criteriaMatchPath = criteriaMatchPath; + this.reverseSort = reverseSort; + this.getResultHandler = getResultHandler; + this.getErrorHandler = getErrorHandler; + this.synchronous = synchronous; + } + return TransitionEventType; +}()); + +/** @module hooks */ /** */ +/** + * A [[TransitionHookFn]] that skips a transition if it should be ignored + * + * This hook is invoked at the end of the onBefore phase. + * + * If the transition should be ignored (because no parameter or states changed) + * then the transition is ignored and not processed. + */ +function ignoredHook(trans) { + var ignoredReason = trans._ignoredReason(); + if (!ignoredReason) + return; + trace.traceTransitionIgnored(trans); + var pending = trans.router.globals.transition; + // The user clicked a link going back to the *current state* ('A') + // However, there is also a pending transition in flight (to 'B') + // Abort the transition to 'B' because the user now wants to be back at 'A'. + if (ignoredReason === 'SameAsCurrent' && pending) { + pending.abort(); + } + return Rejection.ignored().toPromise(); +} +var registerIgnoredTransitionHook = function (transitionService) { + return transitionService.onBefore({}, ignoredHook, { priority: -9999 }); +}; + +/** @module hooks */ /** */ +/** + * A [[TransitionHookFn]] that rejects the Transition if it is invalid + * + * This hook is invoked at the end of the onBefore phase. + * If the transition is invalid (for example, param values do not validate) + * then the transition is rejected. + */ +function invalidTransitionHook(trans) { + if (!trans.valid()) { + throw new Error(trans.error()); + } +} +var registerInvalidTransitionHook = function (transitionService) { + return transitionService.onBefore({}, invalidTransitionHook, { priority: -10000 }); +}; + +/** + * @coreapi + * @module transition + */ +/** for typedoc */ +/** + * The default [[Transition]] options. + * + * Include this object when applying custom defaults: + * let reloadOpts = { reload: true, notify: true } + * let options = defaults(theirOpts, customDefaults, defaultOptions); + */ +var defaultTransOpts = { + location: true, + relative: null, + inherit: false, + notify: true, + reload: false, + custom: {}, + current: function () { return null; }, + source: "unknown" +}; +/** + * This class provides services related to Transitions. + * + * - Most importantly, it allows global Transition Hooks to be registered. + * - It allows the default transition error handler to be set. + * - It also has a factory function for creating new [[Transition]] objects, (used internally by the [[StateService]]). + * + * At bootstrap, [[UIRouter]] creates a single instance (singleton) of this class. + */ +var TransitionService = /** @class */ (function () { + /** @hidden */ + function TransitionService(_router) { + /** @hidden */ + this._transitionCount = 0; + /** @hidden The transition hook types, such as `onEnter`, `onStart`, etc */ + this._eventTypes = []; + /** @hidden The registered transition hooks */ + this._registeredHooks = {}; + /** @hidden The paths on a criteria object */ + this._criteriaPaths = {}; + this._router = _router; + this.$view = _router.viewService; + this._deregisterHookFns = {}; + this._pluginapi = createProxyFunctions(val(this), {}, val(this), [ + '_definePathType', + '_defineEvent', + '_getPathTypes', + '_getEvents', + 'getHooks', + ]); + this._defineCorePaths(); + this._defineCoreEvents(); + this._registerCoreTransitionHooks(); + } + /** + * Registers a [[TransitionHookFn]], called *while a transition is being constructed*. + * + * Registers a transition lifecycle hook, which is invoked during transition construction. + * + * This low level hook should only be used by plugins. + * This can be a useful time for plugins to add resolves or mutate the transition as needed. + * The Sticky States plugin uses this hook to modify the treechanges. + * + * ### Lifecycle + * + * `onCreate` hooks are invoked *while a transition is being constructed*. + * + * ### Return value + * + * The hook's return value is ignored + * + * @internalapi + * @param criteria defines which Transitions the Hook should be invoked for. + * @param callback the hook function which will be invoked. + * @param options the registration options + * @returns a function which deregisters the hook. + */ + TransitionService.prototype.onCreate = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onBefore = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onStart = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onExit = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onRetain = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onEnter = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onFinish = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onSuccess = function (criteria, callback, options) { return; }; + /** @inheritdoc */ + TransitionService.prototype.onError = function (criteria, callback, options) { return; }; + /** + * dispose + * @internalapi + */ + TransitionService.prototype.dispose = function (router) { + values(this._registeredHooks).forEach(function (hooksArray) { return hooksArray.forEach(function (hook) { + hook._deregistered = true; + removeFrom(hooksArray, hook); + }); }); + }; + /** + * Creates a new [[Transition]] object + * + * This is a factory function for creating new Transition objects. + * It is used internally by the [[StateService]] and should generally not be called by application code. + * + * @param fromPath the path to the current state (the from state) + * @param targetState the target state (destination) + * @returns a Transition + */ + TransitionService.prototype.create = function (fromPath, targetState) { + return new Transition(fromPath, targetState, this._router); + }; + /** @hidden */ + TransitionService.prototype._defineCoreEvents = function () { + var Phase = exports.TransitionHookPhase; + var TH = TransitionHook; + var paths = this._criteriaPaths; + var NORMAL_SORT = false, REVERSE_SORT = true; + var ASYNCHRONOUS = false, SYNCHRONOUS = true; + this._defineEvent("onCreate", Phase.CREATE, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.THROW_ERROR, SYNCHRONOUS); + this._defineEvent("onBefore", Phase.BEFORE, 0, paths.to); + this._defineEvent("onStart", Phase.RUN, 0, paths.to); + this._defineEvent("onExit", Phase.RUN, 100, paths.exiting, REVERSE_SORT); + this._defineEvent("onRetain", Phase.RUN, 200, paths.retained); + this._defineEvent("onEnter", Phase.RUN, 300, paths.entering); + this._defineEvent("onFinish", Phase.RUN, 400, paths.to); + this._defineEvent("onSuccess", Phase.SUCCESS, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.LOG_ERROR, SYNCHRONOUS); + this._defineEvent("onError", Phase.ERROR, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.LOG_ERROR, SYNCHRONOUS); + }; + /** @hidden */ + TransitionService.prototype._defineCorePaths = function () { + var STATE = exports.TransitionHookScope.STATE, TRANSITION = exports.TransitionHookScope.TRANSITION; + this._definePathType("to", TRANSITION); + this._definePathType("from", TRANSITION); + this._definePathType("exiting", STATE); + this._definePathType("retained", STATE); + this._definePathType("entering", STATE); + }; + /** @hidden */ + TransitionService.prototype._defineEvent = function (name, hookPhase, hookOrder, criteriaMatchPath, reverseSort, getResultHandler, getErrorHandler, synchronous) { + if (reverseSort === void 0) { reverseSort = false; } + if (getResultHandler === void 0) { getResultHandler = TransitionHook.HANDLE_RESULT; } + if (getErrorHandler === void 0) { getErrorHandler = TransitionHook.REJECT_ERROR; } + if (synchronous === void 0) { synchronous = false; } + var eventType = new TransitionEventType(name, hookPhase, hookOrder, criteriaMatchPath, reverseSort, getResultHandler, getErrorHandler, synchronous); + this._eventTypes.push(eventType); + makeEvent(this, this, eventType); + }; + + /** @hidden */ + TransitionService.prototype._getEvents = function (phase) { + var transitionHookTypes = isDefined(phase) ? + this._eventTypes.filter(function (type) { return type.hookPhase === phase; }) : + this._eventTypes.slice(); + return transitionHookTypes.sort(function (l, r) { + var cmpByPhase = l.hookPhase - r.hookPhase; + return cmpByPhase === 0 ? l.hookOrder - r.hookOrder : cmpByPhase; + }); + }; + /** + * Adds a Path to be used as a criterion against a TreeChanges path + * + * For example: the `exiting` path in [[HookMatchCriteria]] is a STATE scoped path. + * It was defined by calling `defineTreeChangesCriterion('exiting', TransitionHookScope.STATE)` + * Each state in the exiting path is checked against the criteria and returned as part of the match. + * + * Another example: the `to` path in [[HookMatchCriteria]] is a TRANSITION scoped path. + * It was defined by calling `defineTreeChangesCriterion('to', TransitionHookScope.TRANSITION)` + * Only the tail of the `to` path is checked against the criteria and returned as part of the match. + * + * @hidden + */ + TransitionService.prototype._definePathType = function (name, hookScope) { + this._criteriaPaths[name] = { name: name, scope: hookScope }; + }; + /** * @hidden */ + TransitionService.prototype._getPathTypes = function () { + return this._criteriaPaths; + }; + /** @hidden */ + TransitionService.prototype.getHooks = function (hookName) { + return this._registeredHooks[hookName]; + }; + /** @hidden */ + TransitionService.prototype._registerCoreTransitionHooks = function () { + var fns = this._deregisterHookFns; + fns.addCoreResolves = registerAddCoreResolvables(this); + fns.ignored = registerIgnoredTransitionHook(this); + fns.invalid = registerInvalidTransitionHook(this); + // Wire up redirectTo hook + fns.redirectTo = registerRedirectToHook(this); + // Wire up onExit/Retain/Enter state hooks + fns.onExit = registerOnExitHook(this); + fns.onRetain = registerOnRetainHook(this); + fns.onEnter = registerOnEnterHook(this); + // Wire up Resolve hooks + fns.eagerResolve = registerEagerResolvePath(this); + fns.lazyResolve = registerLazyResolveState(this); + // Wire up the View management hooks + fns.loadViews = registerLoadEnteringViews(this); + fns.activateViews = registerActivateViews(this); + // Updates global state after a transition + fns.updateGlobals = registerUpdateGlobalState(this); + // After globals.current is updated at priority: 10000 + fns.updateUrl = registerUpdateUrl(this); + // Lazy load state trees + fns.lazyLoad = registerLazyLoadHook(this); + }; + return TransitionService; +}()); + +/** + * @coreapi + * @module state + */ +/** */ +/** + * Provides state related service functions + * + * This class provides services related to ui-router states. + * An instance of this class is located on the global [[UIRouter]] object. + */ +var StateService = /** @class */ (function () { + /** @internalapi */ + function StateService(router) { + this.router = router; + /** @internalapi */ + this.invalidCallbacks = []; + /** @hidden */ + this._defaultErrorHandler = function $defaultErrorHandler($error$) { + if ($error$ instanceof Error && $error$.stack) { + console.error($error$); + console.error($error$.stack); + } + else if ($error$ instanceof Rejection) { + console.error($error$.toString()); + if ($error$.detail && $error$.detail.stack) + console.error($error$.detail.stack); + } + else { + console.error($error$); + } + }; + var getters = ['current', '$current', 'params', 'transition']; + var boundFns = Object.keys(StateService.prototype).filter(not(inArray(getters))); + createProxyFunctions(val(StateService.prototype), this, val(this), boundFns); + } + Object.defineProperty(StateService.prototype, "transition", { + /** + * The [[Transition]] currently in progress (or null) + * + * This is a passthrough through to [[UIRouterGlobals.transition]] + */ + get: function () { return this.router.globals.transition; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(StateService.prototype, "params", { + /** + * The latest successful state parameters + * + * This is a passthrough through to [[UIRouterGlobals.params]] + */ + get: function () { return this.router.globals.params; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(StateService.prototype, "current", { + /** + * The current [[StateDeclaration]] + * + * This is a passthrough through to [[UIRouterGlobals.current]] + */ + get: function () { return this.router.globals.current; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(StateService.prototype, "$current", { + /** + * The current [[StateObject]] + * + * This is a passthrough through to [[UIRouterGlobals.$current]] + */ + get: function () { return this.router.globals.$current; }, + enumerable: true, + configurable: true + }); + /** @internalapi */ + StateService.prototype.dispose = function () { + this.defaultErrorHandler(noop$1); + this.invalidCallbacks = []; + }; + /** + * Handler for when [[transitionTo]] is called with an invalid state. + * + * Invokes the [[onInvalid]] callbacks, in natural order. + * Each callback's return value is checked in sequence until one of them returns an instance of TargetState. + * The results of the callbacks are wrapped in $q.when(), so the callbacks may return promises. + * + * If a callback returns an TargetState, then it is used as arguments to $state.transitionTo() and the result returned. + * + * @internalapi + */ + StateService.prototype._handleInvalidTargetState = function (fromPath, toState) { + var _this = this; + var fromState = PathUtils.makeTargetState(this.router.stateRegistry, fromPath); + var globals = this.router.globals; + var latestThing = function () { return globals.transitionHistory.peekTail(); }; + var latest = latestThing(); + var callbackQueue = new Queue(this.invalidCallbacks.slice()); + var injector = new ResolveContext(fromPath).injector(); + var checkForRedirect = function (result) { + if (!(result instanceof TargetState)) { + return; + } + var target = result; + // Recreate the TargetState, in case the state is now defined. + target = _this.target(target.identifier(), target.params(), target.options()); + if (!target.valid()) { + return Rejection.invalid(target.error()).toPromise(); + } + if (latestThing() !== latest) { + return Rejection.superseded().toPromise(); + } + return _this.transitionTo(target.identifier(), target.params(), target.options()); + }; + function invokeNextCallback() { + var nextCallback = callbackQueue.dequeue(); + if (nextCallback === undefined) + return Rejection.invalid(toState.error()).toPromise(); + var callbackResult = services.$q.when(nextCallback(toState, fromState, injector)); + return callbackResult.then(checkForRedirect).then(function (result) { return result || invokeNextCallback(); }); + } + return invokeNextCallback(); + }; + /** + * Registers an Invalid State handler + * + * Registers a [[OnInvalidCallback]] function to be invoked when [[StateService.transitionTo]] + * has been called with an invalid state reference parameter + * + * Example: + * ```js + * stateService.onInvalid(function(to, from, injector) { + * if (to.name() === 'foo') { + * let lazyLoader = injector.get('LazyLoadService'); + * return lazyLoader.load('foo') + * .then(() => stateService.target('foo')); + * } + * }); + * ``` + * + * @param {function} callback invoked when the toState is invalid + * This function receives the (invalid) toState, the fromState, and an injector. + * The function may optionally return a [[TargetState]] or a Promise for a TargetState. + * If one is returned, it is treated as a redirect. + * + * @returns a function which deregisters the callback + */ + StateService.prototype.onInvalid = function (callback) { + this.invalidCallbacks.push(callback); + return function deregisterListener() { + removeFrom(this.invalidCallbacks)(callback); + }.bind(this); + }; + /** + * Reloads the current state + * + * A method that force reloads the current state, or a partial state hierarchy. + * All resolves are re-resolved, and components reinstantiated. + * + * #### Example: + * ```js + * let app angular.module('app', ['ui.router']); + * + * app.controller('ctrl', function ($scope, $state) { + * $scope.reload = function(){ + * $state.reload(); + * } + * }); + * ``` + * + * Note: `reload()` is just an alias for: + * + * ```js + * $state.transitionTo($state.current, $state.params, { + * reload: true, inherit: false + * }); + * ``` + * + * @param reloadState A state name or a state object. + * If present, this state and all its children will be reloaded, but ancestors will not reload. + * + * #### Example: + * ```js + * //assuming app application consists of 3 states: 'contacts', 'contacts.detail', 'contacts.detail.item' + * //and current state is 'contacts.detail.item' + * let app angular.module('app', ['ui.router']); + * + * app.controller('ctrl', function ($scope, $state) { + * $scope.reload = function(){ + * //will reload 'contact.detail' and nested 'contact.detail.item' states + * $state.reload('contact.detail'); + * } + * }); + * ``` + * + * @returns A promise representing the state of the new transition. See [[StateService.go]] + */ + StateService.prototype.reload = function (reloadState) { + return this.transitionTo(this.current, this.params, { + reload: isDefined(reloadState) ? reloadState : true, + inherit: false, + notify: false, + }); + }; + + /** + * Transition to a different state and/or parameters + * + * Convenience method for transitioning to a new state. + * + * `$state.go` calls `$state.transitionTo` internally but automatically sets options to + * `{ location: true, inherit: true, relative: router.globals.$current, notify: true }`. + * This allows you to use either an absolute or relative `to` argument (because of `relative: router.globals.$current`). + * It also allows you to specify * only the parameters you'd like to update, while letting unspecified parameters + * inherit from the current parameter values (because of `inherit: true`). + * + * #### Example: + * ```js + * let app = angular.module('app', ['ui.router']); + * + * app.controller('ctrl', function ($scope, $state) { + * $scope.changeState = function () { + * $state.go('contact.detail'); + * }; + * }); + * ``` + * + * @param to Absolute state name, state object, or relative state path (relative to current state). + * + * Some examples: + * + * - `$state.go('contact.detail')` - will go to the `contact.detail` state + * - `$state.go('^')` - will go to the parent state + * - `$state.go('^.sibling')` - if current state is `home.child`, will go to the `home.sibling` state + * - `$state.go('.child.grandchild')` - if current state is home, will go to the `home.child.grandchild` state + * + * @param params A map of the parameters that will be sent to the state, will populate $stateParams. + * + * Any parameters that are not specified will be inherited from current parameter values (because of `inherit: true`). + * This allows, for example, going to a sibling state that shares parameters defined by a parent state. + * + * @param options Transition options + * + * @returns {promise} A promise representing the state of the new transition. + */ + StateService.prototype.go = function (to, params, options) { + var defautGoOpts = { relative: this.$current, inherit: true }; + var transOpts = defaults(options, defautGoOpts, defaultTransOpts); + return this.transitionTo(to, params, transOpts); + }; + + /** + * Creates a [[TargetState]] + * + * This is a factory method for creating a TargetState + * + * This may be returned from a Transition Hook to redirect a transition, for example. + */ + StateService.prototype.target = function (identifier, params, options) { + if (options === void 0) { options = {}; } + // If we're reloading, find the state object to reload from + if (isObject(options.reload) && !options.reload.name) + throw new Error('Invalid reload state object'); + var reg = this.router.stateRegistry; + options.reloadState = options.reload === true ? reg.root() : reg.matcher.find(options.reload, options.relative); + if (options.reload && !options.reloadState) + throw new Error("No such reload state '" + (isString(options.reload) ? options.reload : options.reload.name) + "'"); + return new TargetState(this.router.stateRegistry, identifier, params, options); + }; + + StateService.prototype.getCurrentPath = function () { + var _this = this; + var globals = this.router.globals; + var latestSuccess = globals.successfulTransitions.peekTail(); + var rootPath = function () { return [new PathNode(_this.router.stateRegistry.root())]; }; + return latestSuccess ? latestSuccess.treeChanges().to : rootPath(); + }; + /** + * Low-level method for transitioning to a new state. + * + * The [[go]] method (which uses `transitionTo` internally) is recommended in most situations. + * + * #### Example: + * ```js + * let app = angular.module('app', ['ui.router']); + * + * app.controller('ctrl', function ($scope, $state) { + * $scope.changeState = function () { + * $state.transitionTo('contact.detail'); + * }; + * }); + * ``` + * + * @param to State name or state object. + * @param toParams A map of the parameters that will be sent to the state, + * will populate $stateParams. + * @param options Transition options + * + * @returns A promise representing the state of the new transition. See [[go]] + */ + StateService.prototype.transitionTo = function (to, toParams, options) { + var _this = this; + if (toParams === void 0) { toParams = {}; } + if (options === void 0) { options = {}; } + var router = this.router; + var globals = router.globals; + options = defaults(options, defaultTransOpts); + var getCurrent = function () { + return globals.transition; + }; + options = extend(options, { current: getCurrent }); + var ref = this.target(to, toParams, options); + var currentPath = this.getCurrentPath(); + if (!ref.exists()) + return this._handleInvalidTargetState(currentPath, ref); + if (!ref.valid()) + return silentRejection(ref.error()); + /** + * Special handling for Ignored, Aborted, and Redirected transitions + * + * The semantics for the transition.run() promise and the StateService.transitionTo() + * promise differ. For instance, the run() promise may be rejected because it was + * IGNORED, but the transitionTo() promise is resolved because from the user perspective + * no error occurred. Likewise, the transition.run() promise may be rejected because of + * a Redirect, but the transitionTo() promise is chained to the new Transition's promise. + */ + var rejectedTransitionHandler = function (transition) { return function (error) { + if (error instanceof Rejection) { + var isLatest = router.globals.lastStartedTransitionId === transition.$id; + if (error.type === exports.RejectType.IGNORED) { + isLatest && router.urlRouter.update(); + // Consider ignored `Transition.run()` as a successful `transitionTo` + return services.$q.when(globals.current); + } + var detail = error.detail; + if (error.type === exports.RejectType.SUPERSEDED && error.redirected && detail instanceof TargetState) { + // If `Transition.run()` was redirected, allow the `transitionTo()` promise to resolve successfully + // by returning the promise for the new (redirect) `Transition.run()`. + var redirect = transition.redirect(detail); + return redirect.run().catch(rejectedTransitionHandler(redirect)); + } + if (error.type === exports.RejectType.ABORTED) { + isLatest && router.urlRouter.update(); + return services.$q.reject(error); + } + } + var errorHandler = _this.defaultErrorHandler(); + errorHandler(error); + return services.$q.reject(error); + }; }; + var transition = this.router.transitionService.create(currentPath, ref); + var transitionToPromise = transition.run().catch(rejectedTransitionHandler(transition)); + silenceUncaughtInPromise(transitionToPromise); // issue #2676 + // Return a promise for the transition, which also has the transition object on it. + return extend(transitionToPromise, { transition: transition }); + }; + + /** + * Checks if the current state *is* the provided state + * + * Similar to [[includes]] but only checks for the full state name. + * If params is supplied then it will be tested for strict equality against the current + * active params object, so all params must match with none missing and no extras. + * + * #### Example: + * ```js + * $state.$current.name = 'contacts.details.item'; + * + * // absolute name + * $state.is('contact.details.item'); // returns true + * $state.is(contactDetailItemStateObject); // returns true + * ``` + * + * // relative name (. and ^), typically from a template + * // E.g. from the 'contacts.details' template + * ```html + *
Item
+ * ``` + * + * @param stateOrName The state name (absolute or relative) or state object you'd like to check. + * @param params A param object, e.g. `{sectionId: section.id}`, that you'd like + * to test against the current active state. + * @param options An options object. The options are: + * - `relative`: If `stateOrName` is a relative state name and `options.relative` is set, .is will + * test relative to `options.relative` state (or name). + * + * @returns Returns true if it is the state. + */ + StateService.prototype.is = function (stateOrName, params, options) { + options = defaults(options, { relative: this.$current }); + var state = this.router.stateRegistry.matcher.find(stateOrName, options.relative); + if (!isDefined(state)) + return undefined; + if (this.$current !== state) + return false; + if (!params) + return true; + var schema = state.parameters({ inherit: true, matchingKeys: params }); + return Param.equals(schema, Param.values(schema, params), this.params); + }; + + /** + * Checks if the current state *includes* the provided state + * + * A method to determine if the current active state is equal to or is the child of the + * state stateName. If any params are passed then they will be tested for a match as well. + * Not all the parameters need to be passed, just the ones you'd like to test for equality. + * + * #### Example when `$state.$current.name === 'contacts.details.item'` + * ```js + * // Using partial names + * $state.includes("contacts"); // returns true + * $state.includes("contacts.details"); // returns true + * $state.includes("contacts.details.item"); // returns true + * $state.includes("contacts.list"); // returns false + * $state.includes("about"); // returns false + * ``` + * + * #### Glob Examples when `* $state.$current.name === 'contacts.details.item.url'`: + * ```js + * $state.includes("*.details.*.*"); // returns true + * $state.includes("*.details.**"); // returns true + * $state.includes("**.item.**"); // returns true + * $state.includes("*.details.item.url"); // returns true + * $state.includes("*.details.*.url"); // returns true + * $state.includes("*.details.*"); // returns false + * $state.includes("item.**"); // returns false + * ``` + * + * @param stateOrName A partial name, relative name, glob pattern, + * or state object to be searched for within the current state name. + * @param params A param object, e.g. `{sectionId: section.id}`, + * that you'd like to test against the current active state. + * @param options An options object. The options are: + * - `relative`: If `stateOrName` is a relative state name and `options.relative` is set, .is will + * test relative to `options.relative` state (or name). + * + * @returns {boolean} Returns true if it does include the state + */ + StateService.prototype.includes = function (stateOrName, params, options) { + options = defaults(options, { relative: this.$current }); + var glob = isString(stateOrName) && Glob.fromString(stateOrName); + if (glob) { + if (!glob.matches(this.$current.name)) + return false; + stateOrName = this.$current.name; + } + var state = this.router.stateRegistry.matcher.find(stateOrName, options.relative), include = this.$current.includes; + if (!isDefined(state)) + return undefined; + if (!isDefined(include[state.name])) + return false; + if (!params) + return true; + var schema = state.parameters({ inherit: true, matchingKeys: params }); + return Param.equals(schema, Param.values(schema, params), this.params); + }; + + /** + * Generates a URL for a state and parameters + * + * Returns the url for the given state populated with the given params. + * + * #### Example: + * ```js + * expect($state.href("about.person", { person: "bob" })).toEqual("/about/bob"); + * ``` + * + * @param stateOrName The state name or state object you'd like to generate a url from. + * @param params An object of parameter values to fill the state's required parameters. + * @param options Options object. The options are: + * + * @returns {string} compiled state url + */ + StateService.prototype.href = function (stateOrName, params, options) { + var defaultHrefOpts = { + lossy: true, + inherit: true, + absolute: false, + relative: this.$current, + }; + options = defaults(options, defaultHrefOpts); + params = params || {}; + var state = this.router.stateRegistry.matcher.find(stateOrName, options.relative); + if (!isDefined(state)) + return null; + if (options.inherit) + params = this.params.$inherit(params, this.$current, state); + var nav = (state && options.lossy) ? state.navigable : state; + if (!nav || nav.url === undefined || nav.url === null) { + return null; + } + return this.router.urlRouter.href(nav.url, params, { + absolute: options.absolute, + }); + }; + + /** + * Sets or gets the default [[transitionTo]] error handler. + * + * The error handler is called when a [[Transition]] is rejected or when any error occurred during the Transition. + * This includes errors caused by resolves and transition hooks. + * + * Note: + * This handler does not receive certain Transition rejections. + * Redirected and Ignored Transitions are not considered to be errors by [[StateService.transitionTo]]. + * + * The built-in default error handler logs the error to the console. + * + * You can provide your own custom handler. + * + * #### Example: + * ```js + * stateService.defaultErrorHandler(function() { + * // Do not log transitionTo errors + * }); + * ``` + * + * @param handler a global error handler function + * @returns the current global error handler + */ + StateService.prototype.defaultErrorHandler = function (handler) { + return this._defaultErrorHandler = handler || this._defaultErrorHandler; + }; + StateService.prototype.get = function (stateOrName, base) { + var reg = this.router.stateRegistry; + if (arguments.length === 0) + return reg.get(); + return reg.get(stateOrName, base || this.$current); + }; + /** + * Lazy loads a state + * + * Explicitly runs a state's [[StateDeclaration.lazyLoad]] function. + * + * @param stateOrName the state that should be lazy loaded + * @param transition the optional Transition context to use (if the lazyLoad function requires an injector, etc) + * Note: If no transition is provided, a noop transition is created using the from the current state to the current state. + * This noop transition is not actually run. + * + * @returns a promise to lazy load + */ + StateService.prototype.lazyLoad = function (stateOrName, transition) { + var state = this.get(stateOrName); + if (!state || !state.lazyLoad) + throw new Error("Can not lazy load " + stateOrName); + var currentPath = this.getCurrentPath(); + var target = PathUtils.makeTargetState(this.router.stateRegistry, currentPath); + transition = transition || this.router.transitionService.create(currentPath, target); + return lazyLoadState(transition, state); + }; + return StateService; +}()); + +/** + * # Transition subsystem + * + * This module contains APIs related to a Transition. + * + * See: + * - [[TransitionService]] + * - [[Transition]] + * - [[HookFn]], [[TransitionHookFn]], [[TransitionStateHookFn]], [[HookMatchCriteria]], [[HookResult]] + * + * @coreapi + * @preferred + * @module transition + */ /** for typedoc */ + +/** + * @internalapi + * @module vanilla + */ +/** */ +/** + * An angular1-like promise api + * + * This object implements four methods similar to the + * [angular 1 promise api](https://docs.angularjs.org/api/ng/service/$q) + * + * UI-Router evolved from an angular 1 library to a framework agnostic library. + * However, some of the `@uirouter/core` code uses these ng1 style APIs to support ng1 style dependency injection. + * + * This API provides native ES6 promise support wrapped as a $q-like API. + * Internally, UI-Router uses this $q object to perform promise operations. + * The `angular-ui-router` (ui-router for angular 1) uses the $q API provided by angular. + * + * $q-like promise api + */ +var $q = { + /** Normalizes a value as a promise */ + when: function (val) { return new Promise(function (resolve, reject) { return resolve(val); }); }, + /** Normalizes a value as a promise rejection */ + reject: function (val) { return new Promise(function (resolve, reject) { reject(val); }); }, + /** @returns a deferred object, which has `resolve` and `reject` functions */ + defer: function () { + var deferred = {}; + deferred.promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }); + return deferred; + }, + /** Like Promise.all(), but also supports object key/promise notation like $q */ + all: function (promises) { + if (isArray(promises)) { + return Promise.all(promises); + } + if (isObject(promises)) { + // Convert promises map to promises array. + // When each promise resolves, map it to a tuple { key: key, val: val } + var chain = Object.keys(promises) + .map(function (key) { return promises[key].then(function (val) { return ({ key: key, val: val }); }); }); + // Then wait for all promises to resolve, and convert them back to an object + return $q.all(chain).then(function (values) { + return values.reduce(function (acc, tuple) { acc[tuple.key] = tuple.val; return acc; }, {}); + }); + } + } +}; + +/** + * @internalapi + * @module vanilla + */ +/** */ +// globally available injectables +var globals = {}; +var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; +var ARGUMENT_NAMES = /([^\s,]+)/g; +/** + * A basic angular1-like injector api + * + * This object implements four methods similar to the + * [angular 1 dependency injector](https://docs.angularjs.org/api/auto/service/$injector) + * + * UI-Router evolved from an angular 1 library to a framework agnostic library. + * However, some of the `@uirouter/core` code uses these ng1 style APIs to support ng1 style dependency injection. + * + * This object provides a naive implementation of a globally scoped dependency injection system. + * It supports the following DI approaches: + * + * ### Function parameter names + * + * A function's `.toString()` is called, and the parameter names are parsed. + * This only works when the parameter names aren't "mangled" by a minifier such as UglifyJS. + * + * ```js + * function injectedFunction(FooService, BarService) { + * // FooService and BarService are injected + * } + * ``` + * + * ### Function annotation + * + * A function may be annotated with an array of dependency names as the `$inject` property. + * + * ```js + * injectedFunction.$inject = [ 'FooService', 'BarService' ]; + * function injectedFunction(fs, bs) { + * // FooService and BarService are injected as fs and bs parameters + * } + * ``` + * + * ### Array notation + * + * An array provides the names of the dependencies to inject (as strings). + * The function is the last element of the array. + * + * ```js + * [ 'FooService', 'BarService', function (fs, bs) { + * // FooService and BarService are injected as fs and bs parameters + * }] + * ``` + * + * @type {$InjectorLike} + */ +var $injector = { + /** Gets an object from DI based on a string token */ + get: function (name) { return globals[name]; }, + /** Returns true if an object named `name` exists in global DI */ + has: function (name) { return $injector.get(name) != null; }, + /** + * Injects a function + * + * @param fn the function to inject + * @param context the function's `this` binding + * @param locals An object with additional DI tokens and values, such as `{ someToken: { foo: 1 } }` + */ + invoke: function (fn, context, locals) { + var all = extend({}, globals, locals || {}); + var params = $injector.annotate(fn); + var ensureExist = assertPredicate(function (key) { return all.hasOwnProperty(key); }, function (key) { return "DI can't find injectable: '" + key + "'"; }); + var args = params.filter(ensureExist).map(function (x) { return all[x]; }); + if (isFunction(fn)) + return fn.apply(context, args); + else + return fn.slice(-1)[0].apply(context, args); + }, + /** + * Returns a function's dependencies + * + * Analyzes a function (or array) and returns an array of DI tokens that the function requires. + * @return an array of `string`s + */ + annotate: function (fn) { + if (!isInjectable(fn)) + throw new Error("Not an injectable function: " + fn); + if (fn && fn.$inject) + return fn.$inject; + if (isArray(fn)) + return fn.slice(0, -1); + var fnStr = fn.toString().replace(STRIP_COMMENTS, ''); + var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES); + return result || []; + } +}; + +/** + * @internalapi + * @module vanilla + */ +/** */ +var keyValsToObjectR = function (accum, _a) { + var key = _a[0], val = _a[1]; + if (!accum.hasOwnProperty(key)) { + accum[key] = val; + } + else if (isArray(accum[key])) { + accum[key].push(val); + } + else { + accum[key] = [accum[key], val]; + } + return accum; +}; +var getParams = function (queryString) { + return queryString.split("&").filter(identity).map(splitEqual).reduce(keyValsToObjectR, {}); +}; +function parseUrl$1(url) { + var orEmptyString = function (x) { return x || ""; }; + var _a = splitHash(url).map(orEmptyString), beforehash = _a[0], hash = _a[1]; + var _b = splitQuery(beforehash).map(orEmptyString), path = _b[0], search = _b[1]; + return { path: path, search: search, hash: hash, url: url }; +} +var buildUrl = function (loc) { + var path = loc.path(); + var searchObject = loc.search(); + var hash = loc.hash(); + var search = Object.keys(searchObject).map(function (key) { + var param = searchObject[key]; + var vals = isArray(param) ? param : [param]; + return vals.map(function (val) { return key + "=" + val; }); + }).reduce(unnestR, []).join("&"); + return path + (search ? "?" + search : "") + (hash ? "#" + hash : ""); +}; +function locationPluginFactory(name, isHtml5, serviceClass, configurationClass) { + return function (router) { + var service = router.locationService = new serviceClass(router); + var configuration = router.locationConfig = new configurationClass(router, isHtml5); + function dispose(router) { + router.dispose(service); + router.dispose(configuration); + } + return { name: name, service: service, configuration: configuration, dispose: dispose }; + }; +} + +/** + * @internalapi + * @module vanilla + */ /** */ +/** A base `LocationServices` */ +var BaseLocationServices = /** @class */ (function () { + function BaseLocationServices(router, fireAfterUpdate) { + var _this = this; + this.fireAfterUpdate = fireAfterUpdate; + this._listener = function (evt) { return _this._listeners.forEach(function (cb) { return cb(evt); }); }; + this._listeners = []; + this.hash = function () { return parseUrl$1(_this._get()).hash; }; + this.path = function () { return parseUrl$1(_this._get()).path; }; + this.search = function () { return getParams(parseUrl$1(_this._get()).search); }; + this._location = root.location; + this._history = root.history; + } + BaseLocationServices.prototype.url = function (url, replace) { + if (replace === void 0) { replace = true; } + if (isDefined(url) && url !== this._get()) { + this._set(null, null, url, replace); + if (this.fireAfterUpdate) { + this._listeners.forEach(function (cb) { return cb({ url: url }); }); + } + } + return buildUrl(this); + }; + BaseLocationServices.prototype.onChange = function (cb) { + var _this = this; + this._listeners.push(cb); + return function () { return removeFrom(_this._listeners, cb); }; + }; + BaseLocationServices.prototype.dispose = function (router) { + deregAll(this._listeners); + }; + return BaseLocationServices; +}()); + +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/** + * @internalapi + * @module vanilla + */ +/** */ +/** A `LocationServices` that uses the browser hash "#" to get/set the current location */ +var HashLocationService = /** @class */ (function (_super) { + __extends(HashLocationService, _super); + function HashLocationService(router) { + var _this = _super.call(this, router, false) || this; + root.addEventListener('hashchange', _this._listener, false); + return _this; + } + HashLocationService.prototype._get = function () { + return trimHashVal(this._location.hash); + }; + HashLocationService.prototype._set = function (state, title, url, replace) { + this._location.hash = url; + }; + HashLocationService.prototype.dispose = function (router) { + _super.prototype.dispose.call(this, router); + root.removeEventListener('hashchange', this._listener); + }; + return HashLocationService; +}(BaseLocationServices)); + +var __extends$1 = (undefined && undefined.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/** + * @internalapi + * @module vanilla + */ +/** */ +/** A `LocationServices` that gets/sets the current location from an in-memory object */ +var MemoryLocationService = /** @class */ (function (_super) { + __extends$1(MemoryLocationService, _super); + function MemoryLocationService(router) { + return _super.call(this, router, true) || this; + } + MemoryLocationService.prototype._get = function () { + return this._url; + }; + MemoryLocationService.prototype._set = function (state, title, url, replace) { + this._url = url; + }; + return MemoryLocationService; +}(BaseLocationServices)); + +var __extends$2 = (undefined && undefined.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/** + * A `LocationServices` that gets/sets the current location using the browser's `location` and `history` apis + * + * Uses `history.pushState` and `history.replaceState` + */ +var PushStateLocationService = /** @class */ (function (_super) { + __extends$2(PushStateLocationService, _super); + function PushStateLocationService(router) { + var _this = _super.call(this, router, true) || this; + _this._config = router.urlService.config; + root.addEventListener('popstate', _this._listener, false); + return _this; + } + + /** + * Gets the base prefix without: + * - trailing slash + * - trailing filename + * - protocol and hostname + * + * If , this returns '/base'. + * If , this returns '/base'. + * + * See: https://html.spec.whatwg.org/dev/semantics.html#the-base-element + */ + PushStateLocationService.prototype._getBasePrefix = function () { + return stripFile(this._config.baseHref()); + }; + PushStateLocationService.prototype._get = function () { + var _a = this._location, pathname = _a.pathname, hash = _a.hash, search = _a.search; + search = splitQuery(search)[1]; // strip ? if found + hash = splitHash(hash)[1]; // strip # if found + var basePrefix = this._getBasePrefix(); + var exactMatch = pathname === this._config.baseHref(); + var startsWith = pathname.startsWith(basePrefix); + pathname = exactMatch ? '/' : startsWith ? pathname.substring(basePrefix.length) : pathname; + return pathname + (search ? '?' + search : '') + (hash ? '#' + hash : ''); + }; + PushStateLocationService.prototype._set = function (state, title, url, replace) { + var fullUrl = this._getBasePrefix() + url; + if (replace) { + this._history.replaceState(state, title, fullUrl); + } + else { + this._history.pushState(state, title, fullUrl); + } + }; + PushStateLocationService.prototype.dispose = function (router) { + _super.prototype.dispose.call(this, router); + root.removeEventListener('popstate', this._listener); + }; + return PushStateLocationService; +}(BaseLocationServices)); + +/** A `LocationConfig` mock that gets/sets all config from an in-memory object */ +var MemoryLocationConfig = /** @class */ (function () { + function MemoryLocationConfig() { + var _this = this; + this._baseHref = ''; + this._port = 80; + this._protocol = "http"; + this._host = "localhost"; + this._hashPrefix = ""; + this.port = function () { return _this._port; }; + this.protocol = function () { return _this._protocol; }; + this.host = function () { return _this._host; }; + this.baseHref = function () { return _this._baseHref; }; + this.html5Mode = function () { return false; }; + this.hashPrefix = function (newval) { return isDefined(newval) ? _this._hashPrefix = newval : _this._hashPrefix; }; + this.dispose = noop$1; + } + return MemoryLocationConfig; +}()); + +/** + * @internalapi + * @module vanilla + */ +/** */ +/** A `LocationConfig` that delegates to the browser's `location` object */ +var BrowserLocationConfig = /** @class */ (function () { + function BrowserLocationConfig(router, _isHtml5) { + if (_isHtml5 === void 0) { _isHtml5 = false; } + this._isHtml5 = _isHtml5; + this._baseHref = undefined; + this._hashPrefix = ""; + } + BrowserLocationConfig.prototype.port = function () { + if (location.port) { + return Number(location.port); + } + return this.protocol() === 'https' ? 443 : 80; + }; + BrowserLocationConfig.prototype.protocol = function () { + return location.protocol.replace(/:/g, ''); + }; + BrowserLocationConfig.prototype.host = function () { + return location.hostname; + }; + BrowserLocationConfig.prototype.html5Mode = function () { + return this._isHtml5; + }; + BrowserLocationConfig.prototype.hashPrefix = function (newprefix) { + return isDefined(newprefix) ? this._hashPrefix = newprefix : this._hashPrefix; + }; + + BrowserLocationConfig.prototype.baseHref = function (href) { + return isDefined(href) ? this._baseHref = href : + isDefined(this._baseHref) ? this._baseHref : this.applyDocumentBaseHref(); + }; + BrowserLocationConfig.prototype.applyDocumentBaseHref = function () { + var baseTag = document.getElementsByTagName("base")[0]; + return this._baseHref = baseTag ? baseTag.href.substr(location.origin.length) : ""; + }; + BrowserLocationConfig.prototype.dispose = function () { }; + return BrowserLocationConfig; +}()); + +/** + * @internalapi + * @module vanilla + */ +/** */ +function servicesPlugin(router) { + services.$injector = $injector; + services.$q = $q; + return { name: "vanilla.services", $q: $q, $injector: $injector, dispose: function () { return null; } }; +} +/** A `UIRouterPlugin` uses the browser hash to get/set the current location */ +var hashLocationPlugin = locationPluginFactory('vanilla.hashBangLocation', false, HashLocationService, BrowserLocationConfig); +/** A `UIRouterPlugin` that gets/sets the current location using the browser's `location` and `history` apis */ +var pushStateLocationPlugin = locationPluginFactory("vanilla.pushStateLocation", true, PushStateLocationService, BrowserLocationConfig); +/** A `UIRouterPlugin` that gets/sets the current location from an in-memory object */ +var memoryLocationPlugin = locationPluginFactory("vanilla.memoryLocation", false, MemoryLocationService, MemoryLocationConfig); + +/** + * @internalapi + * @module vanilla + */ +/** */ + +/** + * # Core classes and interfaces + * + * The classes and interfaces that are core to ui-router and do not belong + * to a more specific subsystem (such as resolve). + * + * @coreapi + * @preferred + * @module core + */ /** for typedoc */ +/** @internalapi */ +var UIRouterPluginBase = /** @class */ (function () { + function UIRouterPluginBase() { + } + UIRouterPluginBase.prototype.dispose = function (router) { }; + return UIRouterPluginBase; +}()); + +/** + * @coreapi + * @module common + */ /** */ + + + +var index$1 = Object.freeze({ + root: root, + fromJson: fromJson, + toJson: toJson, + forEach: forEach, + extend: extend, + equals: equals, + identity: identity, + noop: noop$1, + createProxyFunctions: createProxyFunctions, + inherit: inherit, + inArray: inArray, + _inArray: _inArray, + removeFrom: removeFrom, + _removeFrom: _removeFrom, + pushTo: pushTo, + _pushTo: _pushTo, + deregAll: deregAll, + defaults: defaults, + mergeR: mergeR, + ancestors: ancestors, + pick: pick, + omit: omit, + pluck: pluck, + filter: filter, + find: find, + mapObj: mapObj, + map: map, + values: values, + allTrueR: allTrueR, + anyTrueR: anyTrueR, + unnestR: unnestR, + flattenR: flattenR, + pushR: pushR, + uniqR: uniqR, + unnest: unnest, + flatten: flatten, + assertPredicate: assertPredicate, + assertMap: assertMap, + assertFn: assertFn, + pairs: pairs, + arrayTuples: arrayTuples, + applyPairs: applyPairs, + tail: tail, + copy: copy, + _extend: _extend, + silenceUncaughtInPromise: silenceUncaughtInPromise, + silentRejection: silentRejection, + notImplemented: notImplemented, + services: services, + Glob: Glob, + curry: curry, + compose: compose, + pipe: pipe, + prop: prop, + propEq: propEq, + parse: parse, + not: not, + and: and, + or: or, + all: all, + any: any, + is: is, + eq: eq, + val: val, + invoke: invoke, + pattern: pattern, + isUndefined: isUndefined, + isDefined: isDefined, + isNull: isNull, + isNullOrUndefined: isNullOrUndefined, + isFunction: isFunction, + isNumber: isNumber, + isString: isString, + isObject: isObject, + isArray: isArray, + isDate: isDate, + isRegExp: isRegExp, + isState: isState, + isInjectable: isInjectable, + isPromise: isPromise, + Queue: Queue, + maxLength: maxLength, + padString: padString, + kebobString: kebobString, + functionToString: functionToString, + fnToString: fnToString, + stringify: stringify, + beforeAfterSubstr: beforeAfterSubstr, + hostRegex: hostRegex, + stripFile: stripFile, + splitHash: splitHash, + splitQuery: splitQuery, + splitEqual: splitEqual, + trimHashVal: trimHashVal, + splitOnDelim: splitOnDelim, + joinNeighborsR: joinNeighborsR, + get Category () { return exports.Category; }, + Trace: Trace, + trace: trace, + get DefType () { return exports.DefType; }, + Param: Param, + ParamTypes: ParamTypes, + StateParams: StateParams, + ParamType: ParamType, + PathNode: PathNode, + PathUtils: PathUtils, + resolvePolicies: resolvePolicies, + defaultResolvePolicy: defaultResolvePolicy, + Resolvable: Resolvable, + NATIVE_INJECTOR_TOKEN: NATIVE_INJECTOR_TOKEN, + ResolveContext: ResolveContext, + resolvablesBuilder: resolvablesBuilder, + StateBuilder: StateBuilder, + StateObject: StateObject, + StateMatcher: StateMatcher, + StateQueueManager: StateQueueManager, + StateRegistry: StateRegistry, + StateService: StateService, + TargetState: TargetState, + get TransitionHookPhase () { return exports.TransitionHookPhase; }, + get TransitionHookScope () { return exports.TransitionHookScope; }, + HookBuilder: HookBuilder, + matchState: matchState, + RegisteredHook: RegisteredHook, + makeEvent: makeEvent, + get RejectType () { return exports.RejectType; }, + Rejection: Rejection, + Transition: Transition, + TransitionHook: TransitionHook, + TransitionEventType: TransitionEventType, + defaultTransOpts: defaultTransOpts, + TransitionService: TransitionService, + UrlMatcher: UrlMatcher, + UrlMatcherFactory: UrlMatcherFactory, + UrlRouter: UrlRouter, + UrlRuleFactory: UrlRuleFactory, + BaseUrlRule: BaseUrlRule, + UrlService: UrlService, + ViewService: ViewService, + UIRouterGlobals: UIRouterGlobals, + UIRouter: UIRouter, + $q: $q, + $injector: $injector, + BaseLocationServices: BaseLocationServices, + HashLocationService: HashLocationService, + MemoryLocationService: MemoryLocationService, + PushStateLocationService: PushStateLocationService, + MemoryLocationConfig: MemoryLocationConfig, + BrowserLocationConfig: BrowserLocationConfig, + keyValsToObjectR: keyValsToObjectR, + getParams: getParams, + parseUrl: parseUrl$1, + buildUrl: buildUrl, + locationPluginFactory: locationPluginFactory, + servicesPlugin: servicesPlugin, + hashLocationPlugin: hashLocationPlugin, + pushStateLocationPlugin: pushStateLocationPlugin, + memoryLocationPlugin: memoryLocationPlugin, + UIRouterPluginBase: UIRouterPluginBase +}); + +function getNg1ViewConfigFactory() { + var templateFactory = null; + return function (path, view) { + templateFactory = templateFactory || services.$injector.get("$templateFactory"); + return [new Ng1ViewConfig(path, view, templateFactory)]; + }; +} +var hasAnyKey = function (keys, obj) { + return keys.reduce(function (acc, key) { return acc || isDefined(obj[key]); }, false); +}; +/** + * This is a [[StateBuilder.builder]] function for angular1 `views`. + * + * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder + * handles the `views` property with logic specific to @uirouter/angularjs (ng1). + * + * If no `views: {}` property exists on the [[StateDeclaration]], then it creates the `views` object + * and applies the state-level configuration to a view named `$default`. + */ +function ng1ViewsBuilder(state) { + // Do not process root state + if (!state.parent) + return {}; + var tplKeys = ['templateProvider', 'templateUrl', 'template', 'notify', 'async'], ctrlKeys = ['controller', 'controllerProvider', 'controllerAs', 'resolveAs'], compKeys = ['component', 'bindings', 'componentProvider'], nonCompKeys = tplKeys.concat(ctrlKeys), allViewKeys = compKeys.concat(nonCompKeys); + // Do not allow a state to have both state-level props and also a `views: {}` property. + // A state without a `views: {}` property can declare properties for the `$default` view as properties of the state. + // However, the `$default` approach should not be mixed with a separate `views: ` block. + if (isDefined(state.views) && hasAnyKey(allViewKeys, state)) { + throw new Error("State '" + state.name + "' has a 'views' object. " + + "It cannot also have \"view properties\" at the state level. " + + "Move the following properties into a view (in the 'views' object): " + + (" " + allViewKeys.filter(function (key) { return isDefined(state[key]); }).join(", "))); + } + var views = {}, viewsObject = state.views || { "$default": pick(state, allViewKeys) }; + forEach(viewsObject, function (config, name) { + // Account for views: { "": { template... } } + name = name || "$default"; + // Account for views: { header: "headerComponent" } + if (isString(config)) + config = { component: config }; + // Make a shallow copy of the config object + config = extend({}, config); + // Do not allow a view to mix props for component-style view with props for template/controller-style view + if (hasAnyKey(compKeys, config) && hasAnyKey(nonCompKeys, config)) { + throw new Error("Cannot combine: " + compKeys.join("|") + " with: " + nonCompKeys.join("|") + " in stateview: '" + name + "@" + state.name + "'"); + } + config.resolveAs = config.resolveAs || '$resolve'; + config.$type = "ng1"; + config.$context = state; + config.$name = name; + var normalized = ViewService.normalizeUIViewTarget(config.$context, config.$name); + config.$uiViewName = normalized.uiViewName; + config.$uiViewContextAnchor = normalized.uiViewContextAnchor; + views[name] = config; + }); + return views; +} +var id$1 = 0; +var Ng1ViewConfig = /** @class */ (function () { + function Ng1ViewConfig(path, viewDecl, factory) { + var _this = this; + this.path = path; + this.viewDecl = viewDecl; + this.factory = factory; + this.$id = id$1++; + this.loaded = false; + this.getTemplate = function (uiView, context) { + return _this.component ? _this.factory.makeComponentTemplate(uiView, context, _this.component, _this.viewDecl.bindings) : _this.template; + }; + } + Ng1ViewConfig.prototype.load = function () { + var _this = this; + var $q = services.$q; + var context = new ResolveContext(this.path); + var params = this.path.reduce(function (acc, node) { return extend(acc, node.paramValues); }, {}); + var promises = { + template: $q.when(this.factory.fromConfig(this.viewDecl, params, context)), + controller: $q.when(this.getController(context)) + }; + return $q.all(promises).then(function (results) { + trace.traceViewServiceEvent("Loaded", _this); + _this.controller = results.controller; + extend(_this, results.template); // Either { template: "tpl" } or { component: "cmpName" } + return _this; + }); + }; + /** + * Gets the controller for a view configuration. + * + * @returns {Function|Promise.} Returns a controller, or a promise that resolves to a controller. + */ + Ng1ViewConfig.prototype.getController = function (context) { + var provider = this.viewDecl.controllerProvider; + if (!isInjectable(provider)) + return this.viewDecl.controller; + var deps = services.$injector.annotate(provider); + var providerFn = isArray(provider) ? tail(provider) : provider; + var resolvable = new Resolvable("", providerFn, deps); + return resolvable.get(context); + }; + return Ng1ViewConfig; +}()); + +/** @module view */ +/** for typedoc */ +/** + * Service which manages loading of templates from a ViewConfig. + */ +var TemplateFactory = /** @class */ (function () { + function TemplateFactory() { + var _this = this; + /** @hidden */ this._useHttp = ng.version.minor < 3; + /** @hidden */ this.$get = ['$http', '$templateCache', '$injector', function ($http, $templateCache, $injector) { + _this.$templateRequest = $injector.has && $injector.has('$templateRequest') && $injector.get('$templateRequest'); + _this.$http = $http; + _this.$templateCache = $templateCache; + return _this; + }]; + } + /** @hidden */ + TemplateFactory.prototype.useHttpService = function (value) { + this._useHttp = value; + }; + + /** + * Creates a template from a configuration object. + * + * @param config Configuration object for which to load a template. + * The following properties are search in the specified order, and the first one + * that is defined is used to create the template: + * + * @param params Parameters to pass to the template function. + * @param context The resolve context associated with the template's view + * + * @return {string|object} The template html as a string, or a promise for + * that string,or `null` if no template is configured. + */ + TemplateFactory.prototype.fromConfig = function (config, params, context) { + var defaultTemplate = ""; + var asTemplate = function (result) { return services.$q.when(result).then(function (str) { return ({ template: str }); }); }; + var asComponent = function (result) { return services.$q.when(result).then(function (str) { return ({ component: str }); }); }; + return (isDefined(config.template) ? asTemplate(this.fromString(config.template, params)) : + isDefined(config.templateUrl) ? asTemplate(this.fromUrl(config.templateUrl, params)) : + isDefined(config.templateProvider) ? asTemplate(this.fromProvider(config.templateProvider, params, context)) : + isDefined(config.component) ? asComponent(config.component) : + isDefined(config.componentProvider) ? asComponent(this.fromComponentProvider(config.componentProvider, params, context)) : + asTemplate(defaultTemplate)); + }; + + /** + * Creates a template from a string or a function returning a string. + * + * @param template html template as a string or function that returns an html template as a string. + * @param params Parameters to pass to the template function. + * + * @return {string|object} The template html as a string, or a promise for that + * string. + */ + TemplateFactory.prototype.fromString = function (template, params) { + return isFunction(template) ? template(params) : template; + }; + + /** + * Loads a template from the a URL via `$http` and `$templateCache`. + * + * @param {string|Function} url url of the template to load, or a function + * that returns a url. + * @param {Object} params Parameters to pass to the url function. + * @return {string|Promise.} The template html as a string, or a promise + * for that string. + */ + TemplateFactory.prototype.fromUrl = function (url, params) { + if (isFunction(url)) + url = url(params); + if (url == null) + return null; + if (this._useHttp) { + return this.$http.get(url, { cache: this.$templateCache, headers: { Accept: 'text/html' } }) + .then(function (response) { + return response.data; + }); + } + return this.$templateRequest(url); + }; + + /** + * Creates a template by invoking an injectable provider function. + * + * @param provider Function to invoke via `locals` + * @param {Function} injectFn a function used to invoke the template provider + * @return {string|Promise.} The template html as a string, or a promise + * for that string. + */ + TemplateFactory.prototype.fromProvider = function (provider, params, context) { + var deps = services.$injector.annotate(provider); + var providerFn = isArray(provider) ? tail(provider) : provider; + var resolvable = new Resolvable("", providerFn, deps); + return resolvable.get(context); + }; + + /** + * Creates a component's template by invoking an injectable provider function. + * + * @param provider Function to invoke via `locals` + * @param {Function} injectFn a function used to invoke the template provider + * @return {string} The template html as a string: "". + */ + TemplateFactory.prototype.fromComponentProvider = function (provider, params, context) { + var deps = services.$injector.annotate(provider); + var providerFn = isArray(provider) ? tail(provider) : provider; + var resolvable = new Resolvable("", providerFn, deps); + return resolvable.get(context); + }; + + /** + * Creates a template from a component's name + * + * This implements route-to-component. + * It works by retrieving the component (directive) metadata from the injector. + * It analyses the component's bindings, then constructs a template that instantiates the component. + * The template wires input and output bindings to resolves or from the parent component. + * + * @param uiView {object} The parent ui-view (for binding outputs to callbacks) + * @param context The ResolveContext (for binding outputs to callbacks returned from resolves) + * @param component {string} Component's name in camel case. + * @param bindings An object defining the component's bindings: {foo: '<'} + * @return {string} The template as a string: "". + */ + TemplateFactory.prototype.makeComponentTemplate = function (uiView, context, component, bindings) { + bindings = bindings || {}; + // Bind once prefix + var prefix = ng.version.minor >= 3 ? "::" : ""; + // Convert to kebob name. Add x- prefix if the string starts with `x-` or `data-` + var kebob = function (camelCase) { + var kebobed = kebobString(camelCase); + return /^(x|data)-/.exec(kebobed) ? "x-" + kebobed : kebobed; + }; + var attributeTpl = function (input) { + var name = input.name, type = input.type; + var attrName = kebob(name); + // If the ui-view has an attribute which matches a binding on the routed component + // then pass that attribute through to the routed component template. + // Prefer ui-view wired mappings to resolve data, unless the resolve was explicitly bound using `bindings:` + if (uiView.attr(attrName) && !bindings[name]) + return attrName + "='" + uiView.attr(attrName) + "'"; + var resolveName = bindings[name] || name; + // Pre-evaluate the expression for "@" bindings by enclosing in {{ }} + // some-attr="{{ ::$resolve.someResolveName }}" + if (type === '@') + return attrName + "='{{" + prefix + "$resolve." + resolveName + "}}'"; + // Wire "&" callbacks to resolves that return a callback function + // Get the result of the resolve (should be a function) and annotate it to get its arguments. + // some-attr="$resolve.someResolveResultName(foo, bar)" + if (type === '&') { + var res = context.getResolvable(resolveName); + var fn = res && res.data; + var args = fn && services.$injector.annotate(fn) || []; + // account for array style injection, i.e., ['foo', function(foo) {}] + var arrayIdxStr = isArray(fn) ? "[" + (fn.length - 1) + "]" : ''; + return attrName + "='$resolve." + resolveName + arrayIdxStr + "(" + args.join(",") + ")'"; + } + // some-attr="::$resolve.someResolveName" + return attrName + "='" + prefix + "$resolve." + resolveName + "'"; + }; + var attrs = getComponentBindings(component).map(attributeTpl).join(" "); + var kebobName = kebob(component); + return "<" + kebobName + " " + attrs + ">"; + }; + + return TemplateFactory; +}()); +// Gets all the directive(s)' inputs ('@', '=', and '<') and outputs ('&') +function getComponentBindings(name) { + var cmpDefs = services.$injector.get(name + "Directive"); // could be multiple + if (!cmpDefs || !cmpDefs.length) + throw new Error("Unable to find component named '" + name + "'"); + return cmpDefs.map(getBindings).reduce(unnestR, []); +} +// Given a directive definition, find its object input attributes +// Use different properties, depending on the type of directive (component, bindToController, normal) +var getBindings = function (def) { + if (isObject(def.bindToController)) + return scopeBindings(def.bindToController); + return scopeBindings(def.scope); +}; +// for ng 1.2 style, process the scope: { input: "=foo" } +// for ng 1.3 through ng 1.5, process the component's bindToController: { input: "=foo" } object +var scopeBindings = function (bindingsObj) { return Object.keys(bindingsObj || {}) + .map(function (key) { return [key, /^([=<@&])[?]?(.*)/.exec(bindingsObj[key])]; }) + .filter(function (tuple) { return isDefined(tuple) && isArray(tuple[1]); }) + .map(function (tuple) { return ({ name: tuple[1][2] || tuple[0], type: tuple[1][1] }); }); }; + +/** @module ng1 */ /** for typedoc */ +/** + * The Angular 1 `StateProvider` + * + * The `$stateProvider` works similar to Angular's v1 router, but it focuses purely + * on state. + * + * A state corresponds to a "place" in the application in terms of the overall UI and + * navigation. A state describes (via the controller / template / view properties) what + * the UI looks like and does at that place. + * + * States often have things in common, and the primary way of factoring out these + * commonalities in this model is via the state hierarchy, i.e. parent/child states aka + * nested states. + * + * The `$stateProvider` provides interfaces to declare these states for your app. + */ +var StateProvider = /** @class */ (function () { + function StateProvider(stateRegistry, stateService) { + this.stateRegistry = stateRegistry; + this.stateService = stateService; + createProxyFunctions(val(StateProvider.prototype), this, val(this)); + } + /** + * Decorates states when they are registered + * + * Allows you to extend (carefully) or override (at your own peril) the + * `stateBuilder` object used internally by [[StateRegistry]]. + * This can be used to add custom functionality to ui-router, + * for example inferring templateUrl based on the state name. + * + * When passing only a name, it returns the current (original or decorated) builder + * function that matches `name`. + * + * The builder functions that can be decorated are listed below. Though not all + * necessarily have a good use case for decoration, that is up to you to decide. + * + * In addition, users can attach custom decorators, which will generate new + * properties within the state's internal definition. There is currently no clear + * use-case for this beyond accessing internal states (i.e. $state.$current), + * however, expect this to become increasingly relevant as we introduce additional + * meta-programming features. + * + * **Warning**: Decorators should not be interdependent because the order of + * execution of the builder functions in non-deterministic. Builder functions + * should only be dependent on the state definition object and super function. + * + * + * Existing builder functions and current return values: + * + * - **parent** `{object}` - returns the parent state object. + * - **data** `{object}` - returns state data, including any inherited data that is not + * overridden by own values (if any). + * - **url** `{object}` - returns a {@link ui.router.util.type:UrlMatcher UrlMatcher} + * or `null`. + * - **navigable** `{object}` - returns closest ancestor state that has a URL (aka is + * navigable). + * - **params** `{object}` - returns an array of state params that are ensured to + * be a super-set of parent's params. + * - **views** `{object}` - returns a views object where each key is an absolute view + * name (i.e. "viewName@stateName") and each value is the config object + * (template, controller) for the view. Even when you don't use the views object + * explicitly on a state config, one is still created for you internally. + * So by decorating this builder function you have access to decorating template + * and controller properties. + * - **ownParams** `{object}` - returns an array of params that belong to the state, + * not including any params defined by ancestor states. + * - **path** `{string}` - returns the full path from the root down to this state. + * Needed for state activation. + * - **includes** `{object}` - returns an object that includes every state that + * would pass a `$state.includes()` test. + * + * #### Example: + * Override the internal 'views' builder with a function that takes the state + * definition, and a reference to the internal function being overridden: + * ```js + * $stateProvider.decorator('views', function (state, parent) { + * let result = {}, + * views = parent(state); + * + * angular.forEach(views, function (config, name) { + * let autoName = (state.name + '.' + name).replace('.', '/'); + * config.templateUrl = config.templateUrl || '/partials/' + autoName + '.html'; + * result[name] = config; + * }); + * return result; + * }); + * + * $stateProvider.state('home', { + * views: { + * 'contact.list': { controller: 'ListController' }, + * 'contact.item': { controller: 'ItemController' } + * } + * }); + * ``` + * + * + * ```js + * // Auto-populates list and item views with /partials/home/contact/list.html, + * // and /partials/home/contact/item.html, respectively. + * $state.go('home'); + * ``` + * + * @param {string} name The name of the builder function to decorate. + * @param {object} func A function that is responsible for decorating the original + * builder function. The function receives two parameters: + * + * - `{object}` - state - The state config object. + * - `{object}` - super - The original builder function. + * + * @return {object} $stateProvider - $stateProvider instance + */ + StateProvider.prototype.decorator = function (name, func) { + return this.stateRegistry.decorator(name, func) || this; + }; + StateProvider.prototype.state = function (name, definition) { + if (isObject(name)) { + definition = name; + } + else { + definition.name = name; + } + this.stateRegistry.register(definition); + return this; + }; + /** + * Registers an invalid state handler + * + * This is a passthrough to [[StateService.onInvalid]] for ng1. + */ + StateProvider.prototype.onInvalid = function (callback) { + return this.stateService.onInvalid(callback); + }; + return StateProvider; +}()); + +/** @module ng1 */ /** */ +/** + * This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`, + * `onRetain` callback hooks on a [[Ng1StateDeclaration]]. + * + * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder + * ensures that those hooks are injectable for @uirouter/angularjs (ng1). + */ +var getStateHookBuilder = function (hookName) { + return function stateHookBuilder(state, parentFn) { + var hook = state[hookName]; + var pathname = hookName === 'onExit' ? 'from' : 'to'; + function decoratedNg1Hook(trans, state) { + var resolveContext = new ResolveContext(trans.treeChanges(pathname)); + var locals = extend(getLocals(resolveContext), { $state$: state, $transition$: trans }); + return services.$injector.invoke(hook, this, locals); + } + return hook ? decoratedNg1Hook : undefined; + }; +}; + +/** + * Implements UI-Router LocationServices and LocationConfig using Angular 1's $location service + */ +var Ng1LocationServices = /** @class */ (function () { + function Ng1LocationServices($locationProvider) { + // .onChange() registry + this._urlListeners = []; + this.$locationProvider = $locationProvider; + var _lp = val($locationProvider); + createProxyFunctions(_lp, this, _lp, ['hashPrefix']); + } + Ng1LocationServices.prototype.dispose = function () { }; + Ng1LocationServices.prototype.onChange = function (callback) { + var _this = this; + this._urlListeners.push(callback); + return function () { return removeFrom(_this._urlListeners)(callback); }; + }; + Ng1LocationServices.prototype.html5Mode = function () { + var html5Mode = this.$locationProvider.html5Mode(); + html5Mode = isObject(html5Mode) ? html5Mode.enabled : html5Mode; + return html5Mode && this.$sniffer.history; + }; + Ng1LocationServices.prototype.url = function (newUrl, replace, state) { + if (replace === void 0) { replace = false; } + if (newUrl) + this.$location.url(newUrl); + if (replace) + this.$location.replace(); + if (state) + this.$location.state(state); + return this.$location.url(); + }; + Ng1LocationServices.prototype._runtimeServices = function ($rootScope, $location, $sniffer, $browser) { + var _this = this; + this.$location = $location; + this.$sniffer = $sniffer; + // Bind $locationChangeSuccess to the listeners registered in LocationService.onChange + $rootScope.$on("$locationChangeSuccess", function (evt) { return _this._urlListeners.forEach(function (fn) { return fn(evt); }); }); + var _loc = val($location); + var _browser = val($browser); + // Bind these LocationService functions to $location + createProxyFunctions(_loc, this, _loc, ["replace", "path", "search", "hash"]); + // Bind these LocationConfig functions to $location + createProxyFunctions(_loc, this, _loc, ['port', 'protocol', 'host']); + // Bind these LocationConfig functions to $browser + createProxyFunctions(_browser, this, _browser, ['baseHref']); + }; + /** + * Applys ng1-specific path parameter encoding + * + * The Angular 1 `$location` service is a bit weird. + * It doesn't allow slashes to be encoded/decoded bi-directionally. + * + * See the writeup at https://github.com/angular-ui/ui-router/issues/2598 + * + * This code patches the `path` parameter type so it encoded/decodes slashes as ~2F + * + * @param router + */ + Ng1LocationServices.monkeyPatchPathParameterType = function (router) { + var pathType = router.urlMatcherFactory.type('path'); + pathType.encode = function (val) { + return val != null ? val.toString().replace(/(~|\/)/g, function (m) { return ({ '~': '~~', '/': '~2F' }[m]); }) : val; + }; + pathType.decode = function (val) { + return val != null ? val.toString().replace(/(~~|~2F)/g, function (m) { return ({ '~~': '~', '~2F': '/' }[m]); }) : val; + }; + }; + return Ng1LocationServices; +}()); + +/** @module url */ /** */ +/** + * Manages rules for client-side URL + * + * ### Deprecation warning: + * This class is now considered to be an internal API + * Use the [[UrlService]] instead. + * For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]]. + * + * This class manages the router rules for what to do when the URL changes. + * + * This provider remains for backwards compatibility. + * + * @deprecated + */ +var UrlRouterProvider = /** @class */ (function () { + /** @hidden */ + function UrlRouterProvider(router) { + this._router = router; + this._urlRouter = router.urlRouter; + } + /** @hidden */ + UrlRouterProvider.prototype.$get = function () { + var urlRouter = this._urlRouter; + urlRouter.update(true); + if (!urlRouter.interceptDeferred) + urlRouter.listen(); + return urlRouter; + }; + /** + * Registers a url handler function. + * + * Registers a low level url handler (a `rule`). + * A rule detects specific URL patterns and returns a redirect, or performs some action. + * + * If a rule returns a string, the URL is replaced with the string, and all rules are fired again. + * + * #### Example: + * ```js + * var app = angular.module('app', ['ui.router.router']); + * + * app.config(function ($urlRouterProvider) { + * // Here's an example of how you might allow case insensitive urls + * $urlRouterProvider.rule(function ($injector, $location) { + * var path = $location.path(), + * normalized = path.toLowerCase(); + * + * if (path !== normalized) { + * return normalized; + * } + * }); + * }); + * ``` + * + * @param ruleFn + * Handler function that takes `$injector` and `$location` services as arguments. + * You can use them to detect a url and return a different url as a string. + * + * @return [[UrlRouterProvider]] (`this`) + */ + UrlRouterProvider.prototype.rule = function (ruleFn) { + var _this = this; + if (!isFunction(ruleFn)) + throw new Error("'rule' must be a function"); + var match = function () { + return ruleFn(services.$injector, _this._router.locationService); + }; + var rule = new BaseUrlRule(match, identity); + this._urlRouter.rule(rule); + return this; + }; + + /** + * Defines the path or behavior to use when no url can be matched. + * + * #### Example: + * ```js + * var app = angular.module('app', ['ui.router.router']); + * + * app.config(function ($urlRouterProvider) { + * // if the path doesn't match any of the urls you configured + * // otherwise will take care of routing the user to the + * // specified url + * $urlRouterProvider.otherwise('/index'); + * + * // Example of using function rule as param + * $urlRouterProvider.otherwise(function ($injector, $location) { + * return '/a/valid/url'; + * }); + * }); + * ``` + * + * @param rule + * The url path you want to redirect to or a function rule that returns the url path or performs a `$state.go()`. + * The function version is passed two params: `$injector` and `$location` services, and should return a url string. + * + * @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance + */ + UrlRouterProvider.prototype.otherwise = function (rule) { + var _this = this; + var urlRouter = this._urlRouter; + if (isString(rule)) { + urlRouter.otherwise(rule); + } + else if (isFunction(rule)) { + urlRouter.otherwise(function () { return rule(services.$injector, _this._router.locationService); }); + } + else { + throw new Error("'rule' must be a string or function"); + } + return this; + }; + + /** + * Registers a handler for a given url matching. + * + * If the handler is a string, it is + * treated as a redirect, and is interpolated according to the syntax of match + * (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise). + * + * If the handler is a function, it is injectable. + * It gets invoked if `$location` matches. + * You have the option of inject the match object as `$match`. + * + * The handler can return + * + * - **falsy** to indicate that the rule didn't match after all, then `$urlRouter` + * will continue trying to find another one that matches. + * - **string** which is treated as a redirect and passed to `$location.url()` + * - **void** or any **truthy** value tells `$urlRouter` that the url was handled. + * + * #### Example: + * ```js + * var app = angular.module('app', ['ui.router.router']); + * + * app.config(function ($urlRouterProvider) { + * $urlRouterProvider.when($state.url, function ($match, $stateParams) { + * if ($state.$current.navigable !== state || + * !equalForKeys($match, $stateParams) { + * $state.transitionTo(state, $match, false); + * } + * }); + * }); + * ``` + * + * @param what A pattern string to match, compiled as a [[UrlMatcher]]. + * @param handler The path (or function that returns a path) that you want to redirect your user to. + * @param ruleCallback [optional] A callback that receives the `rule` registered with [[UrlMatcher.rule]] + * + * Note: the handler may also invoke arbitrary code, such as `$state.go()` + */ + UrlRouterProvider.prototype.when = function (what, handler) { + if (isArray(handler) || isFunction(handler)) { + handler = UrlRouterProvider.injectableHandler(this._router, handler); + } + this._urlRouter.when(what, handler); + return this; + }; + + UrlRouterProvider.injectableHandler = function (router, handler) { + return function (match) { + return services.$injector.invoke(handler, null, { $match: match, $stateParams: router.globals.params }); + }; + }; + /** + * Disables monitoring of the URL. + * + * Call this method before UI-Router has bootstrapped. + * It will stop UI-Router from performing the initial url sync. + * + * This can be useful to perform some asynchronous initialization before the router starts. + * Once the initialization is complete, call [[listen]] to tell UI-Router to start watching and synchronizing the URL. + * + * #### Example: + * ```js + * var app = angular.module('app', ['ui.router']); + * + * app.config(function ($urlRouterProvider) { + * // Prevent $urlRouter from automatically intercepting URL changes; + * $urlRouterProvider.deferIntercept(); + * }) + * + * app.run(function (MyService, $urlRouter, $http) { + * $http.get("/stuff").then(function(resp) { + * MyService.doStuff(resp.data); + * $urlRouter.listen(); + * $urlRouter.sync(); + * }); + * }); + * ``` + * + * @param defer Indicates whether to defer location change interception. + * Passing no parameter is equivalent to `true`. + */ + UrlRouterProvider.prototype.deferIntercept = function (defer) { + this._urlRouter.deferIntercept(defer); + }; + + return UrlRouterProvider; +}()); + +/** + * # Angular 1 types + * + * UI-Router core provides various Typescript types which you can use for code completion and validating parameter values, etc. + * The customizations to the core types for Angular UI-Router are documented here. + * + * The optional [[$resolve]] service is also documented here. + * + * @module ng1 + * @preferred + */ +/** for typedoc */ +ng.module("ui.router.angular1", []); +var mod_init = ng.module('ui.router.init', []); +var mod_util = ng.module('ui.router.util', ['ng', 'ui.router.init']); +var mod_rtr = ng.module('ui.router.router', ['ui.router.util']); +var mod_state = ng.module('ui.router.state', ['ui.router.router', 'ui.router.util', 'ui.router.angular1']); +var mod_main = ng.module('ui.router', ['ui.router.init', 'ui.router.state', 'ui.router.angular1']); +var mod_cmpt = ng.module('ui.router.compat', ['ui.router']); // tslint:disable-line +var router = null; +$uiRouter.$inject = ['$locationProvider']; +/** This angular 1 provider instantiates a Router and exposes its services via the angular injector */ +function $uiRouter($locationProvider) { + // Create a new instance of the Router when the $uiRouterProvider is initialized + router = this.router = new UIRouter(); + router.stateProvider = new StateProvider(router.stateRegistry, router.stateService); + // Apply ng1 specific StateBuilder code for `views`, `resolve`, and `onExit/Retain/Enter` properties + router.stateRegistry.decorator("views", ng1ViewsBuilder); + router.stateRegistry.decorator("onExit", getStateHookBuilder("onExit")); + router.stateRegistry.decorator("onRetain", getStateHookBuilder("onRetain")); + router.stateRegistry.decorator("onEnter", getStateHookBuilder("onEnter")); + router.viewService._pluginapi._viewConfigFactory('ng1', getNg1ViewConfigFactory()); + var ng1LocationService = router.locationService = router.locationConfig = new Ng1LocationServices($locationProvider); + Ng1LocationServices.monkeyPatchPathParameterType(router); + // backwards compat: also expose router instance as $uiRouterProvider.router + router['router'] = router; + router['$get'] = $get; + $get.$inject = ['$location', '$browser', '$sniffer', '$rootScope', '$http', '$templateCache']; + function $get($location, $browser, $sniffer, $rootScope, $http, $templateCache) { + ng1LocationService._runtimeServices($rootScope, $location, $sniffer, $browser); + delete router['router']; + delete router['$get']; + return router; + } + return router; +} +var getProviderFor = function (serviceName) { return ['$uiRouterProvider', function ($urp) { + var service = $urp.router[serviceName]; + service["$get"] = function () { return service; }; + return service; + }]; }; +// This effectively calls $get() on `$uiRouterProvider` to trigger init (when ng enters runtime) +runBlock.$inject = ['$injector', '$q', '$uiRouter']; +function runBlock($injector, $q, $uiRouter) { + services.$injector = $injector; + services.$q = $q; + // The $injector is now available. + // Find any resolvables that had dependency annotation deferred + $uiRouter.stateRegistry.get() + .map(function (x) { return x.$$state().resolvables; }) + .reduce(unnestR, []) + .filter(function (x) { return x.deps === "deferred"; }) + .forEach(function (resolvable) { return resolvable.deps = $injector.annotate(resolvable.resolveFn, $injector.strictDi); }); +} +// $urlRouter service and $urlRouterProvider +var getUrlRouterProvider = function (uiRouter) { + return uiRouter.urlRouterProvider = new UrlRouterProvider(uiRouter); +}; +// $state service and $stateProvider +// $urlRouter service and $urlRouterProvider +var getStateProvider = function () { + return extend(router.stateProvider, { $get: function () { return router.stateService; } }); +}; +watchDigests.$inject = ['$rootScope']; +function watchDigests($rootScope) { + $rootScope.$watch(function () { trace.approximateDigests++; }); +} +mod_init.provider("$uiRouter", $uiRouter); +mod_rtr.provider('$urlRouter', ['$uiRouterProvider', getUrlRouterProvider]); +mod_util.provider('$urlService', getProviderFor('urlService')); +mod_util.provider('$urlMatcherFactory', ['$uiRouterProvider', function () { return router.urlMatcherFactory; }]); +mod_util.provider('$templateFactory', function () { return new TemplateFactory(); }); +mod_state.provider('$stateRegistry', getProviderFor('stateRegistry')); +mod_state.provider('$uiRouterGlobals', getProviderFor('globals')); +mod_state.provider('$transitions', getProviderFor('transitionService')); +mod_state.provider('$state', ['$uiRouterProvider', getStateProvider]); +mod_state.factory('$stateParams', ['$uiRouter', function ($uiRouter) { return $uiRouter.globals.params; }]); +mod_main.factory('$view', function () { return router.viewService; }); +mod_main.service("$trace", function () { return trace; }); +mod_main.run(watchDigests); +mod_util.run(['$urlMatcherFactory', function ($urlMatcherFactory) { }]); +mod_state.run(['$state', function ($state) { }]); +mod_rtr.run(['$urlRouter', function ($urlRouter) { }]); +mod_init.run(runBlock); +/** @hidden TODO: find a place to move this */ +var getLocals = function (ctx) { + var tokens = ctx.getTokens().filter(isString); + var tuples = tokens.map(function (key) { + var resolvable = ctx.getResolvable(key); + var waitPolicy = ctx.getPolicy(resolvable).async; + return [key, waitPolicy === 'NOWAIT' ? resolvable.promise : resolvable.data]; + }); + return tuples.reduce(applyPairs, {}); +}; + +/** + * # Angular 1 injectable services + * + * This is a list of the objects which can be injected using angular's injector. + * + * There are three different kind of injectable objects: + * + * ## **Provider** objects + * #### injectable into a `.config()` block during configtime + * + * - [[$uiRouterProvider]]: The UI-Router instance + * - [[$stateProvider]]: State registration + * - [[$transitionsProvider]]: Transition hooks + * - [[$urlServiceProvider]]: All URL related public APIs + * + * - [[$uiViewScrollProvider]]: Disable ui-router view scrolling + * - [[$urlRouterProvider]]: (deprecated) Url matching rules + * - [[$urlMatcherFactoryProvider]]: (deprecated) Url parsing config + * + * ## **Service** objects + * #### injectable globally during runtime + * + * - [[$uiRouter]]: The UI-Router instance + * - [[$trace]]: Enable transition trace/debug + * - [[$transitions]]: Transition hooks + * - [[$state]]: Imperative state related APIs + * - [[$stateRegistry]]: State registration + * - [[$urlService]]: All URL related public APIs + * - [[$uiRouterGlobals]]: Global variables + * - [[$uiViewScroll]]: Scroll an element into view + * + * - [[$stateParams]]: (deprecated) Global state param values + * - [[$urlRouter]]: (deprecated) URL synchronization + * - [[$urlMatcherFactory]]: (deprecated) URL parsing config + * + * ## **Per-Transition** objects + * + * - These kind of objects are injectable into: + * - Resolves ([[Ng1StateDeclaration.resolve]]), + * - Transition Hooks ([[TransitionService.onStart]], etc), + * - Routed Controllers ([[Ng1ViewDeclaration.controller]]) + * + * #### Different instances are injected based on the [[Transition]] + * + * - [[$transition$]]: The current Transition object + * - [[$stateParams]]: State param values for pending Transition (deprecated) + * - Any resolve data defined using [[Ng1StateDeclaration.resolve]] + * + * @ng1api + * @preferred + * @module injectables + */ /** */ +/** + * The current (or pending) State Parameters + * + * An injectable global **Service Object** which holds the state parameters for the latest **SUCCESSFUL** transition. + * + * The values are not updated until *after* a `Transition` successfully completes. + * + * **Also:** an injectable **Per-Transition Object** object which holds the pending state parameters for the pending `Transition` currently running. + * + * ### Deprecation warning: + * + * The value injected for `$stateParams` is different depending on where it is injected. + * + * - When injected into an angular service, the object injected is the global **Service Object** with the parameter values for the latest successful `Transition`. + * - When injected into transition hooks, resolves, or view controllers, the object is the **Per-Transition Object** with the parameter values for the running `Transition`. + * + * Because of these confusing details, this service is deprecated. + * + * ### Instead of using the global `$stateParams` service object, + * inject [[$uiRouterGlobals]] and use [[UIRouterGlobals.params]] + * + * ```js + * MyService.$inject = ['$uiRouterGlobals']; + * function MyService($uiRouterGlobals) { + * return { + * paramValues: function () { + * return $uiRouterGlobals.params; + * } + * } + * } + * ``` + * + * ### Instead of using the per-transition `$stateParams` object, + * inject the current `Transition` (as [[$transition$]]) and use [[Transition.params]] + * + * ```js + * MyController.$inject = ['$transition$']; + * function MyController($transition$) { + * var username = $transition$.params().username; + * // .. do something with username + * } + * ``` + * + * --- + * + * This object can be injected into other services. + * + * #### Deprecated Example: + * ```js + * SomeService.$inject = ['$http', '$stateParams']; + * function SomeService($http, $stateParams) { + * return { + * getUser: function() { + * return $http.get('/api/users/' + $stateParams.username); + * } + * } + * }; + * angular.service('SomeService', SomeService); + * ``` + * @deprecated + */ + +/** + * # Angular 1 Directives + * + * These are the directives included in UI-Router for Angular 1. + * These directives are used in templates to create viewports and link/navigate to states. + * + * @ng1api + * @preferred + * @module directives + */ /** for typedoc */ +/** @hidden */ +function parseStateRef(ref) { + var paramsOnly = ref.match(/^\s*({[^}]*})\s*$/), parsed; + if (paramsOnly) + ref = '(' + paramsOnly[1] + ')'; + parsed = ref.replace(/\n/g, " ").match(/^\s*([^(]*?)\s*(\((.*)\))?\s*$/); + if (!parsed || parsed.length !== 4) + throw new Error("Invalid state ref '" + ref + "'"); + return { state: parsed[1] || null, paramExpr: parsed[3] || null }; +} +/** @hidden */ +function stateContext(el) { + var $uiView = el.parent().inheritedData('$uiView'); + var path = parse('$cfg.path')($uiView); + return path ? tail(path).state.name : undefined; +} +/** @hidden */ +function processedDef($state, $element, def) { + var uiState = def.uiState || $state.current.name; + var uiStateOpts = extend(defaultOpts($element, $state), def.uiStateOpts || {}); + var href = $state.href(uiState, def.uiStateParams, uiStateOpts); + return { uiState: uiState, uiStateParams: def.uiStateParams, uiStateOpts: uiStateOpts, href: href }; +} +/** @hidden */ +function getTypeInfo(el) { + // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute. + var isSvg = Object.prototype.toString.call(el.prop('href')) === '[object SVGAnimatedString]'; + var isForm = el[0].nodeName === "FORM"; + return { + attr: isForm ? "action" : (isSvg ? 'xlink:href' : 'href'), + isAnchor: el.prop("tagName").toUpperCase() === "A", + clickable: !isForm + }; +} +/** @hidden */ +function clickHook(el, $state, $timeout, type, getDef) { + return function (e) { + var button = e.which || e.button, target = getDef(); + if (!(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || el.attr('target'))) { + // HACK: This is to allow ng-clicks to be processed before the transition is initiated: + var transition = $timeout(function () { + $state.go(target.uiState, target.uiStateParams, target.uiStateOpts); + }); + e.preventDefault(); + // if the state has no URL, ignore one preventDefault from the directive. + var ignorePreventDefaultCount = type.isAnchor && !target.href ? 1 : 0; + e.preventDefault = function () { + if (ignorePreventDefaultCount-- <= 0) + $timeout.cancel(transition); + }; + } + }; +} +/** @hidden */ +function defaultOpts(el, $state) { + return { + relative: stateContext(el) || $state.$current, + inherit: true, + source: "sref" + }; +} +/** @hidden */ +function bindEvents(element, scope, hookFn, uiStateOpts) { + var events; + if (uiStateOpts) { + events = uiStateOpts.events; + } + if (!isArray(events)) { + events = ['click']; + } + var on = element.on ? 'on' : 'bind'; + for (var _i = 0, events_1 = events; _i < events_1.length; _i++) { + var event_1 = events_1[_i]; + element[on](event_1, hookFn); + } + scope.$on('$destroy', function () { + var off = element.off ? 'off' : 'unbind'; + for (var _i = 0, events_2 = events; _i < events_2.length; _i++) { + var event_2 = events_2[_i]; + element[off](event_2, hookFn); + } + }); +} +/** + * `ui-sref`: A directive for linking to a state + * + * A directive which links to a state (and optionally, parameters). + * When clicked, this directive activates the linked state with the supplied parameter values. + * + * ### Linked State + * The attribute value of the `ui-sref` is the name of the state to link to. + * + * #### Example: + * This will activate the `home` state when the link is clicked. + * ```html + * Home + * ``` + * + * ### Relative Links + * You can also use relative state paths within `ui-sref`, just like a relative path passed to `$state.go()` ([[StateService.go]]). + * You just need to be aware that the path is relative to the state that *created* the link. + * This allows a state to create a relative `ui-sref` which always targets the same destination. + * + * #### Example: + * Both these links are relative to the parent state, even when a child state is currently active. + * ```html + * child 1 state + * child 2 state + * ``` + * + * This link activates the parent state. + * ```html + * Return + * ``` + * + * ### hrefs + * If the linked state has a URL, the directive will automatically generate and + * update the `href` attribute (using the [[StateService.href]] method). + * + * #### Example: + * Assuming the `users` state has a url of `/users/` + * ```html + * Users + * ``` + * + * ### Parameter Values + * In addition to the state name, a `ui-sref` can include parameter values which are applied when activating the state. + * Param values can be provided in the `ui-sref` value after the state name, enclosed by parentheses. + * The content inside the parentheses is an expression, evaluated to the parameter values. + * + * #### Example: + * This example renders a list of links to users. + * The state's `userId` parameter value comes from each user's `user.id` property. + * ```html + *
  • + * {{ user.displayName }} + *
  • + * ``` + * + * Note: + * The parameter values expression is `$watch`ed for updates. + * + * ### Transition Options + * You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `ui-sref-opts` attribute. + * Options are restricted to `location`, `inherit`, and `reload`. + * + * #### Example: + * ```html + * Home + * ``` + * + * ### Other DOM Events + * + * You can also customize which DOM events to respond to (instead of `click`) by + * providing an `events` array in the `ui-sref-opts` attribute. + * + * #### Example: + * ```html + * + * ``` + * + * ### Highlighting the active link + * This directive can be used in conjunction with [[uiSrefActive]] to highlight the active link. + * + * ### Examples + * If you have the following template: + * + * ```html + * Home + * About + * Next page + * + * + * ``` + * + * Then (assuming the current state is `contacts`) the rendered html including hrefs would be: + * + * ```html + * Home + * About + * Next page + * + *
      + *
    • + * Joe + *
    • + *
    • + * Alice + *
    • + *
    • + * Bob + *
    • + *
    + * + * Home + * ``` + * + * ### Notes + * + * - You can use `ui-sref` to change **only the parameter values** by omitting the state name and parentheses. + * #### Example: + * Sets the `lang` parameter to `en` and remains on the same state. + * + * ```html + * English + * ``` + * + * - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example. + * + * - Unlike the parameter values expression, the state name is not `$watch`ed (for performance reasons). + * If you need to dynamically update the state being linked to, use the fully dynamic [[uiState]] directive. + */ +var uiSref; +uiSref = ['$uiRouter', '$timeout', + function $StateRefDirective($uiRouter, $timeout) { + var $state = $uiRouter.stateService; + return { + restrict: 'A', + require: ['?^uiSrefActive', '?^uiSrefActiveEq'], + link: function (scope, element, attrs, uiSrefActive) { + var type = getTypeInfo(element); + var active = uiSrefActive[1] || uiSrefActive[0]; + var unlinkInfoFn = null; + var hookFn; + var rawDef = {}; + var getDef = function () { return processedDef($state, element, rawDef); }; + var ref = parseStateRef(attrs.uiSref); + rawDef.uiState = ref.state; + rawDef.uiStateOpts = attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {}; + function update() { + var def = getDef(); + if (unlinkInfoFn) + unlinkInfoFn(); + if (active) + unlinkInfoFn = active.$$addStateInfo(def.uiState, def.uiStateParams); + if (def.href != null) + attrs.$set(type.attr, def.href); + } + if (ref.paramExpr) { + scope.$watch(ref.paramExpr, function (val) { + rawDef.uiStateParams = extend({}, val); + update(); + }, true); + rawDef.uiStateParams = extend({}, scope.$eval(ref.paramExpr)); + } + update(); + scope.$on('$destroy', $uiRouter.stateRegistry.onStatesChanged(update)); + scope.$on('$destroy', $uiRouter.transitionService.onSuccess({}, update)); + if (!type.clickable) + return; + hookFn = clickHook(element, $state, $timeout, type, getDef); + bindEvents(element, scope, hookFn, rawDef.uiStateOpts); + } + }; + }]; +/** + * `ui-state`: A fully dynamic directive for linking to a state + * + * A directive which links to a state (and optionally, parameters). + * When clicked, this directive activates the linked state with the supplied parameter values. + * + * **This directive is very similar to [[uiSref]], but it `$observe`s and `$watch`es/evaluates all its inputs.** + * + * A directive which links to a state (and optionally, parameters). + * When clicked, this directive activates the linked state with the supplied parameter values. + * + * ### Linked State + * The attribute value of `ui-state` is an expression which is `$watch`ed and evaluated as the state to link to. + * **This is in contrast with `ui-sref`, which takes a state name as a string literal.** + * + * #### Example: + * Create a list of links. + * ```html + *
  • + * {{ link.displayName }} + *
  • + * ``` + * + * ### Relative Links + * If the expression evaluates to a relative path, it is processed like [[uiSref]]. + * You just need to be aware that the path is relative to the state that *created* the link. + * This allows a state to create relative `ui-state` which always targets the same destination. + * + * ### hrefs + * If the linked state has a URL, the directive will automatically generate and + * update the `href` attribute (using the [[StateService.href]] method). + * + * ### Parameter Values + * In addition to the state name expression, a `ui-state` can include parameter values which are applied when activating the state. + * Param values should be provided using the `ui-state-params` attribute. + * The `ui-state-params` attribute value is `$watch`ed and evaluated as an expression. + * + * #### Example: + * This example renders a list of links with param values. + * The state's `userId` parameter value comes from each user's `user.id` property. + * ```html + *
  • + * {{ link.displayName }} + *
  • + * ``` + * + * ### Transition Options + * You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `ui-state-opts` attribute. + * Options are restricted to `location`, `inherit`, and `reload`. + * The value of the `ui-state-opts` is `$watch`ed and evaluated as an expression. + * + * #### Example: + * ```html + * Home + * ``` + * + * ### Other DOM Events + * + * You can also customize which DOM events to respond to (instead of `click`) by + * providing an `events` array in the `ui-state-opts` attribute. + * + * #### Example: + * ```html + * + * ``` + * + * ### Highlighting the active link + * This directive can be used in conjunction with [[uiSrefActive]] to highlight the active link. + * + * ### Notes + * + * - You can use `ui-params` to change **only the parameter values** by omitting the state name and supplying only `ui-state-params`. + * However, it might be simpler to use [[uiSref]] parameter-only links. + * + * #### Example: + * Sets the `lang` parameter to `en` and remains on the same state. + * + * ```html + * English + * ``` + * + * - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example. + * ``` + */ +var uiState; +uiState = ['$uiRouter', '$timeout', + function $StateRefDynamicDirective($uiRouter, $timeout) { + var $state = $uiRouter.stateService; + return { + restrict: 'A', + require: ['?^uiSrefActive', '?^uiSrefActiveEq'], + link: function (scope, element, attrs, uiSrefActive) { + var type = getTypeInfo(element); + var active = uiSrefActive[1] || uiSrefActive[0]; + var unlinkInfoFn = null; + var hookFn; + var rawDef = {}; + var getDef = function () { return processedDef($state, element, rawDef); }; + var inputAttrs = ['uiState', 'uiStateParams', 'uiStateOpts']; + var watchDeregFns = inputAttrs.reduce(function (acc, attr) { return (acc[attr] = noop$1, acc); }, {}); + function update() { + var def = getDef(); + if (unlinkInfoFn) + unlinkInfoFn(); + if (active) + unlinkInfoFn = active.$$addStateInfo(def.uiState, def.uiStateParams); + if (def.href != null) + attrs.$set(type.attr, def.href); + } + inputAttrs.forEach(function (field) { + rawDef[field] = attrs[field] ? scope.$eval(attrs[field]) : null; + attrs.$observe(field, function (expr) { + watchDeregFns[field](); + watchDeregFns[field] = scope.$watch(expr, function (newval) { + rawDef[field] = newval; + update(); + }, true); + }); + }); + update(); + scope.$on('$destroy', $uiRouter.stateRegistry.onStatesChanged(update)); + scope.$on('$destroy', $uiRouter.transitionService.onSuccess({}, update)); + if (!type.clickable) + return; + hookFn = clickHook(element, $state, $timeout, type, getDef); + bindEvents(element, scope, hookFn, rawDef.uiStateOpts); + } + }; + }]; +/** + * `ui-sref-active` and `ui-sref-active-eq`: A directive that adds a CSS class when a `ui-sref` is active + * + * A directive working alongside [[uiSref]] and [[uiState]] to add classes to an element when the + * related directive's state is active (and remove them when it is inactive). + * + * The primary use-case is to highlight the active link in navigation menus, + * distinguishing it from the inactive menu items. + * + * ### Linking to a `ui-sref` or `ui-state` + * `ui-sref-active` can live on the same element as `ui-sref`/`ui-state`, or it can be on a parent element. + * If a `ui-sref-active` is a parent to more than one `ui-sref`/`ui-state`, it will apply the CSS class when **any of the links are active**. + * + * ### Matching + * + * The `ui-sref-active` directive applies the CSS class when the `ui-sref`/`ui-state`'s target state **or any child state is active**. + * This is a "fuzzy match" which uses [[StateService.includes]]. + * + * The `ui-sref-active-eq` directive applies the CSS class when the `ui-sref`/`ui-state`'s target state is directly active (not when child states are active). + * This is an "exact match" which uses [[StateService.is]]. + * + * ### Parameter values + * If the `ui-sref`/`ui-state` includes parameter values, the current parameter values must match the link's values for the link to be highlighted. + * This allows a list of links to the same state with different parameters to be rendered, and the correct one highlighted. + * + * #### Example: + * ```html + *
  • + * {{ user.lastName }} + *
  • + * ``` + * + * ### Examples + * + * Given the following template: + * #### Example: + * ```html + * + * ``` + * + * When the app state is `app.user` (or any child state), + * and contains the state parameter "user" with value "bilbobaggins", + * the resulting HTML will appear as (note the 'active' class): + * + * ```html + * + * ``` + * + * ### Glob mode + * + * It is possible to pass `ui-sref-active` an expression that evaluates to an object. + * The objects keys represent active class names and values represent the respective state names/globs. + * `ui-sref-active` will match if the current active state **includes** any of + * the specified state names/globs, even the abstract ones. + * + * #### Example: + * Given the following template, with "admin" being an abstract state: + * ```html + *
    + * Roles + *
    + * ``` + * + * When the current state is "admin.roles" the "active" class will be applied to both the
    and elements. + * It is important to note that the state names/globs passed to `ui-sref-active` override any state provided by a linked `ui-sref`. + * + * ### Notes: + * + * - The class name is interpolated **once** during the directives link time (any further changes to the + * interpolated value are ignored). + * + * - Multiple classes may be specified in a space-separated format: `ui-sref-active='class1 class2 class3'` + */ +var uiSrefActive; +uiSrefActive = ['$state', '$stateParams', '$interpolate', '$uiRouter', + function $StateRefActiveDirective($state, $stateParams, $interpolate, $uiRouter) { + return { + restrict: "A", + controller: ['$scope', '$element', '$attrs', + function ($scope, $element, $attrs) { + var states = [], activeEqClass, uiSrefActive; + // There probably isn't much point in $observing this + // uiSrefActive and uiSrefActiveEq share the same directive object with some + // slight difference in logic routing + activeEqClass = $interpolate($attrs.uiSrefActiveEq || '', false)($scope); + try { + uiSrefActive = $scope.$eval($attrs.uiSrefActive); + } + catch (e) { + // Do nothing. uiSrefActive is not a valid expression. + // Fall back to using $interpolate below + } + uiSrefActive = uiSrefActive || $interpolate($attrs.uiSrefActive || '', false)($scope); + if (isObject(uiSrefActive)) { + forEach(uiSrefActive, function (stateOrName, activeClass) { + if (isString(stateOrName)) { + var ref = parseStateRef(stateOrName); + addState(ref.state, $scope.$eval(ref.paramExpr), activeClass); + } + }); + } + // Allow uiSref to communicate with uiSrefActive[Equals] + this.$$addStateInfo = function (newState, newParams) { + // we already got an explicit state provided by ui-sref-active, so we + // shadow the one that comes from ui-sref + if (isObject(uiSrefActive) && states.length > 0) { + return; + } + var deregister = addState(newState, newParams, uiSrefActive); + update(); + return deregister; + }; + function updateAfterTransition(trans) { + trans.promise.then(update, noop$1); + } + $scope.$on('$stateChangeSuccess', update); + $scope.$on('$destroy', $uiRouter.transitionService.onStart({}, updateAfterTransition)); + if ($uiRouter.globals.transition) { + updateAfterTransition($uiRouter.globals.transition); + } + function addState(stateName, stateParams, activeClass) { + var state = $state.get(stateName, stateContext($element)); + var stateInfo = { + state: state || { name: stateName }, + params: stateParams, + activeClass: activeClass + }; + states.push(stateInfo); + return function removeState() { + removeFrom(states)(stateInfo); + }; + } + // Update route state + function update() { + var splitClasses = function (str) { + return str.split(/\s/).filter(identity); + }; + var getClasses = function (stateList) { + return stateList.map(function (x) { return x.activeClass; }).map(splitClasses).reduce(unnestR, []); + }; + var allClasses = getClasses(states).concat(splitClasses(activeEqClass)).reduce(uniqR, []); + var fuzzyClasses = getClasses(states.filter(function (x) { return $state.includes(x.state.name, x.params); })); + var exactlyMatchesAny = !!states.filter(function (x) { return $state.is(x.state.name, x.params); }).length; + var exactClasses = exactlyMatchesAny ? splitClasses(activeEqClass) : []; + var addClasses = fuzzyClasses.concat(exactClasses).reduce(uniqR, []); + var removeClasses = allClasses.filter(function (cls) { return !inArray(addClasses, cls); }); + $scope.$evalAsync(function () { + addClasses.forEach(function (className) { return $element.addClass(className); }); + removeClasses.forEach(function (className) { return $element.removeClass(className); }); + }); + } + update(); + }] + }; + }]; +ng.module('ui.router.state') + .directive('uiSref', uiSref) + .directive('uiSrefActive', uiSrefActive) + .directive('uiSrefActiveEq', uiSrefActive) + .directive('uiState', uiState); + +/** @module ng1 */ /** for typedoc */ +/** + * `isState` Filter: truthy if the current state is the parameter + * + * Translates to [[StateService.is]] `$state.is("stateName")`. + * + * #### Example: + * ```html + *
    show if state is 'stateName'
    + * ``` + */ +$IsStateFilter.$inject = ['$state']; +function $IsStateFilter($state) { + var isFilter = function (state, params, options) { + return $state.is(state, params, options); + }; + isFilter.$stateful = true; + return isFilter; +} +/** + * `includedByState` Filter: truthy if the current state includes the parameter + * + * Translates to [[StateService.includes]]` $state.is("fullOrPartialStateName")`. + * + * #### Example: + * ```html + *
    show if state includes 'fullOrPartialStateName'
    + * ``` + */ +$IncludedByStateFilter.$inject = ['$state']; +function $IncludedByStateFilter($state) { + var includesFilter = function (state, params, options) { + return $state.includes(state, params, options); + }; + includesFilter.$stateful = true; + return includesFilter; +} +ng.module('ui.router.state') + .filter('isState', $IsStateFilter) + .filter('includedByState', $IncludedByStateFilter); + +/** + * @ng1api + * @module directives + */ /** for typedoc */ +/** + * `ui-view`: A viewport directive which is filled in by a view from the active state. + * + * ### Attributes + * + * - `name`: (Optional) A view name. + * The name should be unique amongst the other views in the same state. + * You can have views of the same name that live in different states. + * The ui-view can be targeted in a View using the name ([[Ng1StateDeclaration.views]]). + * + * - `autoscroll`: an expression. When it evaluates to true, the `ui-view` will be scrolled into view when it is activated. + * Uses [[$uiViewScroll]] to do the scrolling. + * + * - `onload`: Expression to evaluate whenever the view updates. + * + * #### Example: + * A view can be unnamed or named. + * ```html + * + *
    + * + * + *
    + * + * + * + * ``` + * + * You can only have one unnamed view within any template (or root html). If you are only using a + * single view and it is unnamed then you can populate it like so: + * + * ```html + *
    + * $stateProvider.state("home", { + * template: "

    HELLO!

    " + * }) + * ``` + * + * The above is a convenient shortcut equivalent to specifying your view explicitly with the + * [[Ng1StateDeclaration.views]] config property, by name, in this case an empty name: + * + * ```js + * $stateProvider.state("home", { + * views: { + * "": { + * template: "

    HELLO!

    " + * } + * } + * }) + * ``` + * + * But typically you'll only use the views property if you name your view or have more than one view + * in the same template. There's not really a compelling reason to name a view if its the only one, + * but you could if you wanted, like so: + * + * ```html + *
    + * ``` + * + * ```js + * $stateProvider.state("home", { + * views: { + * "main": { + * template: "

    HELLO!

    " + * } + * } + * }) + * ``` + * + * Really though, you'll use views to set up multiple views: + * + * ```html + *
    + *
    + *
    + * ``` + * + * ```js + * $stateProvider.state("home", { + * views: { + * "": { + * template: "

    HELLO!

    " + * }, + * "chart": { + * template: "" + * }, + * "data": { + * template: "" + * } + * } + * }) + * ``` + * + * #### Examples for `autoscroll`: + * ```html + * + * + * + * + * + * + * + * ``` + * + * Resolve data: + * + * The resolved data from the state's `resolve` block is placed on the scope as `$resolve` (this + * can be customized using [[Ng1ViewDeclaration.resolveAs]]). This can be then accessed from the template. + * + * Note that when `controllerAs` is being used, `$resolve` is set on the controller instance *after* the + * controller is instantiated. The `$onInit()` hook can be used to perform initialization code which + * depends on `$resolve` data. + * + * #### Example: + * ```js + * $stateProvider.state('home', { + * template: '', + * resolve: { + * user: function(UserService) { return UserService.fetchUser(); } + * } + * }); + * ``` + */ +var uiView; +uiView = ['$view', '$animate', '$uiViewScroll', '$interpolate', '$q', + function $ViewDirective($view, $animate, $uiViewScroll, $interpolate, $q) { + function getRenderer(attrs, scope) { + return { + enter: function (element, target, cb) { + if (ng.version.minor > 2) { + $animate.enter(element, null, target).then(cb); + } + else { + $animate.enter(element, null, target, cb); + } + }, + leave: function (element, cb) { + if (ng.version.minor > 2) { + $animate.leave(element).then(cb); + } + else { + $animate.leave(element, cb); + } + } + }; + } + function configsEqual(config1, config2) { + return config1 === config2; + } + var rootData = { + $cfg: { viewDecl: { $context: $view._pluginapi._rootViewContext() } }, + $uiView: {} + }; + var directive = { + count: 0, + restrict: 'ECA', + terminal: true, + priority: 400, + transclude: 'element', + compile: function (tElement, tAttrs, $transclude) { + return function (scope, $element, attrs) { + var previousEl, currentEl, currentScope, unregister, onloadExp = attrs['onload'] || '', autoScrollExp = attrs['autoscroll'], renderer = getRenderer(attrs, scope), viewConfig = undefined, inherited = $element.inheritedData('$uiView') || rootData, name = $interpolate(attrs['uiView'] || attrs['name'] || '')(scope) || '$default'; + var activeUIView = { + $type: 'ng1', + id: directive.count++, + name: name, + fqn: inherited.$uiView.fqn ? inherited.$uiView.fqn + "." + name : name, + config: null, + configUpdated: configUpdatedCallback, + get creationContext() { + var fromParentTagConfig = parse('$cfg.viewDecl.$context')(inherited); + // Allow + // See https://github.com/angular-ui/ui-router/issues/3355 + var fromParentTag = parse('$uiView.creationContext')(inherited); + return fromParentTagConfig || fromParentTag; + } + }; + trace.traceUIViewEvent("Linking", activeUIView); + function configUpdatedCallback(config) { + if (config && !(config instanceof Ng1ViewConfig)) + return; + if (configsEqual(viewConfig, config)) + return; + trace.traceUIViewConfigUpdated(activeUIView, config && config.viewDecl && config.viewDecl.$context); + viewConfig = config; + updateView(config); + } + $element.data('$uiView', { $uiView: activeUIView }); + updateView(); + unregister = $view.registerUIView(activeUIView); + scope.$on("$destroy", function () { + trace.traceUIViewEvent("Destroying/Unregistering", activeUIView); + unregister(); + }); + function cleanupLastView() { + if (previousEl) { + trace.traceUIViewEvent("Removing (previous) el", previousEl.data('$uiView')); + previousEl.remove(); + previousEl = null; + } + if (currentScope) { + trace.traceUIViewEvent("Destroying scope", activeUIView); + currentScope.$destroy(); + currentScope = null; + } + if (currentEl) { + var _viewData_1 = currentEl.data('$uiViewAnim'); + trace.traceUIViewEvent("Animate out", _viewData_1); + renderer.leave(currentEl, function () { + _viewData_1.$$animLeave.resolve(); + previousEl = null; + }); + previousEl = currentEl; + currentEl = null; + } + } + function updateView(config) { + var newScope = scope.$new(); + var animEnter = $q.defer(), animLeave = $q.defer(); + var $uiViewData = { + $cfg: config, + $uiView: activeUIView, + }; + var $uiViewAnim = { + $animEnter: animEnter.promise, + $animLeave: animLeave.promise, + $$animLeave: animLeave + }; + /** + * @ngdoc event + * @name ui.router.state.directive:ui-view#$viewContentLoading + * @eventOf ui.router.state.directive:ui-view + * @eventType emits on ui-view directive scope + * @description + * + * Fired once the view **begins loading**, *before* the DOM is rendered. + * + * @param {Object} event Event object. + * @param {string} viewName Name of the view. + */ + newScope.$emit('$viewContentLoading', name); + var cloned = $transclude(newScope, function (clone) { + clone.data('$uiViewAnim', $uiViewAnim); + clone.data('$uiView', $uiViewData); + renderer.enter(clone, $element, function onUIViewEnter() { + animEnter.resolve(); + if (currentScope) + currentScope.$emit('$viewContentAnimationEnded'); + if (isDefined(autoScrollExp) && !autoScrollExp || scope.$eval(autoScrollExp)) { + $uiViewScroll(clone); + } + }); + cleanupLastView(); + }); + currentEl = cloned; + currentScope = newScope; + /** + * @ngdoc event + * @name ui.router.state.directive:ui-view#$viewContentLoaded + * @eventOf ui.router.state.directive:ui-view + * @eventType emits on ui-view directive scope + * @description * + * Fired once the view is **loaded**, *after* the DOM is rendered. + * + * @param {Object} event Event object. + */ + currentScope.$emit('$viewContentLoaded', config || viewConfig); + currentScope.$eval(onloadExp); + } + }; + } + }; + return directive; + }]; +$ViewDirectiveFill.$inject = ['$compile', '$controller', '$transitions', '$view', '$q', '$timeout']; +/** @hidden */ +function $ViewDirectiveFill($compile, $controller, $transitions, $view, $q, $timeout) { + var getControllerAs = parse('viewDecl.controllerAs'); + var getResolveAs = parse('viewDecl.resolveAs'); + return { + restrict: 'ECA', + priority: -400, + compile: function (tElement) { + var initial = tElement.html(); + tElement.empty(); + return function (scope, $element) { + var data = $element.data('$uiView'); + if (!data) { + $element.html(initial); + $compile($element.contents())(scope); + return; + } + var cfg = data.$cfg || { viewDecl: {}, getTemplate: ng_from_import.noop }; + var resolveCtx = cfg.path && new ResolveContext(cfg.path); + $element.html(cfg.getTemplate($element, resolveCtx) || initial); + trace.traceUIViewFill(data.$uiView, $element.html()); + var link = $compile($element.contents()); + var controller = cfg.controller; + var controllerAs = getControllerAs(cfg); + var resolveAs = getResolveAs(cfg); + var locals = resolveCtx && getLocals(resolveCtx); + scope[resolveAs] = locals; + if (controller) { + var controllerInstance = $controller(controller, extend({}, locals, { $scope: scope, $element: $element })); + if (controllerAs) { + scope[controllerAs] = controllerInstance; + scope[controllerAs][resolveAs] = locals; + } + // TODO: Use $view service as a central point for registering component-level hooks + // Then, when a component is created, tell the $view service, so it can invoke hooks + // $view.componentLoaded(controllerInstance, { $scope: scope, $element: $element }); + // scope.$on('$destroy', () => $view.componentUnloaded(controllerInstance, { $scope: scope, $element: $element })); + $element.data('$ngControllerController', controllerInstance); + $element.children().data('$ngControllerController', controllerInstance); + registerControllerCallbacks($q, $transitions, controllerInstance, scope, cfg); + } + // Wait for the component to appear in the DOM + if (isString(cfg.viewDecl.component)) { + var cmp_1 = cfg.viewDecl.component; + var kebobName = kebobString(cmp_1); + var tagRegexp_1 = new RegExp("^(x-|data-)?" + kebobName + "$", "i"); + var getComponentController = function () { + var directiveEl = [].slice.call($element[0].children) + .filter(function (el) { return el && el.tagName && tagRegexp_1.exec(el.tagName); }); + return directiveEl && ng.element(directiveEl).data("$" + cmp_1 + "Controller"); + }; + var deregisterWatch_1 = scope.$watch(getComponentController, function (ctrlInstance) { + if (!ctrlInstance) + return; + registerControllerCallbacks($q, $transitions, ctrlInstance, scope, cfg); + deregisterWatch_1(); + }); + } + link(scope); + }; + } + }; +} +/** @hidden */ +var hasComponentImpl = typeof ng.module('ui.router')['component'] === 'function'; +/** @hidden incrementing id */ +var _uiCanExitId = 0; +/** @hidden TODO: move these callbacks to $view and/or `/hooks/components.ts` or something */ +function registerControllerCallbacks($q, $transitions, controllerInstance, $scope, cfg) { + // Call $onInit() ASAP + if (isFunction(controllerInstance.$onInit) && !(cfg.viewDecl.component && hasComponentImpl)) { + controllerInstance.$onInit(); + } + var viewState = tail(cfg.path).state.self; + var hookOptions = { bind: controllerInstance }; + // Add component-level hook for onParamsChange + if (isFunction(controllerInstance.uiOnParamsChanged)) { + var resolveContext = new ResolveContext(cfg.path); + var viewCreationTrans_1 = resolveContext.getResolvable('$transition$').data; + // Fire callback on any successful transition + var paramsUpdated = function ($transition$) { + // Exit early if the $transition$ is the same as the view was created within. + // Exit early if the $transition$ will exit the state the view is for. + if ($transition$ === viewCreationTrans_1 || $transition$.exiting().indexOf(viewState) !== -1) + return; + var toParams = $transition$.params("to"); + var fromParams = $transition$.params("from"); + var toSchema = $transition$.treeChanges().to.map(function (node) { return node.paramSchema; }).reduce(unnestR, []); + var fromSchema = $transition$.treeChanges().from.map(function (node) { return node.paramSchema; }).reduce(unnestR, []); + // Find the to params that have different values than the from params + var changedToParams = toSchema.filter(function (param) { + var idx = fromSchema.indexOf(param); + return idx === -1 || !fromSchema[idx].type.equals(toParams[param.id], fromParams[param.id]); + }); + // Only trigger callback if a to param has changed or is new + if (changedToParams.length) { + var changedKeys_1 = changedToParams.map(function (x) { return x.id; }); + // Filter the params to only changed/new to params. `$transition$.params()` may be used to get all params. + var newValues = filter(toParams, function (val, key) { return changedKeys_1.indexOf(key) !== -1; }); + controllerInstance.uiOnParamsChanged(newValues, $transition$); + } + }; + $scope.$on('$destroy', $transitions.onSuccess({}, paramsUpdated, hookOptions)); + } + // Add component-level hook for uiCanExit + if (isFunction(controllerInstance.uiCanExit)) { + var id_1 = _uiCanExitId++; + var cacheProp_1 = '_uiCanExitIds'; + // Returns true if a redirect transition already answered truthy + var prevTruthyAnswer_1 = function (trans) { + return !!trans && (trans[cacheProp_1] && trans[cacheProp_1][id_1] === true || prevTruthyAnswer_1(trans.redirectedFrom())); + }; + // If a user answered yes, but the transition was later redirected, don't also ask for the new redirect transition + var wrappedHook = function (trans) { + var promise, ids = trans[cacheProp_1] = trans[cacheProp_1] || {}; + if (!prevTruthyAnswer_1(trans)) { + promise = $q.when(controllerInstance.uiCanExit(trans)); + promise.then(function (val) { return ids[id_1] = (val !== false); }); + } + return promise; + }; + var criteria = { exiting: viewState.name }; + $scope.$on('$destroy', $transitions.onBefore(criteria, wrappedHook, hookOptions)); + } +} +ng.module('ui.router.state').directive('uiView', uiView); +ng.module('ui.router.state').directive('uiView', $ViewDirectiveFill); + +/** @module ng1 */ /** */ +/** @hidden */ +function $ViewScrollProvider() { + var useAnchorScroll = false; + this.useAnchorScroll = function () { + useAnchorScroll = true; + }; + this.$get = ['$anchorScroll', '$timeout', function ($anchorScroll, $timeout) { + if (useAnchorScroll) { + return $anchorScroll; + } + return function ($element) { + return $timeout(function () { + $element[0].scrollIntoView(); + }, 0, false); + }; + }]; +} +ng.module('ui.router.state').provider('$uiViewScroll', $ViewScrollProvider); + +/** + * Main entry point for angular 1.x build + * @module ng1 + */ /** */ +var index = "ui.router"; + +exports['default'] = index; +exports.core = index$1; +exports.watchDigests = watchDigests; +exports.getLocals = getLocals; +exports.getNg1ViewConfigFactory = getNg1ViewConfigFactory; +exports.ng1ViewsBuilder = ng1ViewsBuilder; +exports.Ng1ViewConfig = Ng1ViewConfig; +exports.StateProvider = StateProvider; +exports.UrlRouterProvider = UrlRouterProvider; +exports.root = root; +exports.fromJson = fromJson; +exports.toJson = toJson; +exports.forEach = forEach; +exports.extend = extend; +exports.equals = equals; +exports.identity = identity; +exports.noop = noop$1; +exports.createProxyFunctions = createProxyFunctions; +exports.inherit = inherit; +exports.inArray = inArray; +exports._inArray = _inArray; +exports.removeFrom = removeFrom; +exports._removeFrom = _removeFrom; +exports.pushTo = pushTo; +exports._pushTo = _pushTo; +exports.deregAll = deregAll; +exports.defaults = defaults; +exports.mergeR = mergeR; +exports.ancestors = ancestors; +exports.pick = pick; +exports.omit = omit; +exports.pluck = pluck; +exports.filter = filter; +exports.find = find; +exports.mapObj = mapObj; +exports.map = map; +exports.values = values; +exports.allTrueR = allTrueR; +exports.anyTrueR = anyTrueR; +exports.unnestR = unnestR; +exports.flattenR = flattenR; +exports.pushR = pushR; +exports.uniqR = uniqR; +exports.unnest = unnest; +exports.flatten = flatten; +exports.assertPredicate = assertPredicate; +exports.assertMap = assertMap; +exports.assertFn = assertFn; +exports.pairs = pairs; +exports.arrayTuples = arrayTuples; +exports.applyPairs = applyPairs; +exports.tail = tail; +exports.copy = copy; +exports._extend = _extend; +exports.silenceUncaughtInPromise = silenceUncaughtInPromise; +exports.silentRejection = silentRejection; +exports.notImplemented = notImplemented; +exports.services = services; +exports.Glob = Glob; +exports.curry = curry; +exports.compose = compose; +exports.pipe = pipe; +exports.prop = prop; +exports.propEq = propEq; +exports.parse = parse; +exports.not = not; +exports.and = and; +exports.or = or; +exports.all = all; +exports.any = any; +exports.is = is; +exports.eq = eq; +exports.val = val; +exports.invoke = invoke; +exports.pattern = pattern; +exports.isUndefined = isUndefined; +exports.isDefined = isDefined; +exports.isNull = isNull; +exports.isNullOrUndefined = isNullOrUndefined; +exports.isFunction = isFunction; +exports.isNumber = isNumber; +exports.isString = isString; +exports.isObject = isObject; +exports.isArray = isArray; +exports.isDate = isDate; +exports.isRegExp = isRegExp; +exports.isState = isState; +exports.isInjectable = isInjectable; +exports.isPromise = isPromise; +exports.Queue = Queue; +exports.maxLength = maxLength; +exports.padString = padString; +exports.kebobString = kebobString; +exports.functionToString = functionToString; +exports.fnToString = fnToString; +exports.stringify = stringify; +exports.beforeAfterSubstr = beforeAfterSubstr; +exports.hostRegex = hostRegex; +exports.stripFile = stripFile; +exports.splitHash = splitHash; +exports.splitQuery = splitQuery; +exports.splitEqual = splitEqual; +exports.trimHashVal = trimHashVal; +exports.splitOnDelim = splitOnDelim; +exports.joinNeighborsR = joinNeighborsR; +exports.Trace = Trace; +exports.trace = trace; +exports.Param = Param; +exports.ParamTypes = ParamTypes; +exports.StateParams = StateParams; +exports.ParamType = ParamType; +exports.PathNode = PathNode; +exports.PathUtils = PathUtils; +exports.resolvePolicies = resolvePolicies; +exports.defaultResolvePolicy = defaultResolvePolicy; +exports.Resolvable = Resolvable; +exports.NATIVE_INJECTOR_TOKEN = NATIVE_INJECTOR_TOKEN; +exports.ResolveContext = ResolveContext; +exports.resolvablesBuilder = resolvablesBuilder; +exports.StateBuilder = StateBuilder; +exports.StateObject = StateObject; +exports.StateMatcher = StateMatcher; +exports.StateQueueManager = StateQueueManager; +exports.StateRegistry = StateRegistry; +exports.StateService = StateService; +exports.TargetState = TargetState; +exports.HookBuilder = HookBuilder; +exports.matchState = matchState; +exports.RegisteredHook = RegisteredHook; +exports.makeEvent = makeEvent; +exports.Rejection = Rejection; +exports.Transition = Transition; +exports.TransitionHook = TransitionHook; +exports.TransitionEventType = TransitionEventType; +exports.defaultTransOpts = defaultTransOpts; +exports.TransitionService = TransitionService; +exports.UrlMatcher = UrlMatcher; +exports.UrlMatcherFactory = UrlMatcherFactory; +exports.UrlRouter = UrlRouter; +exports.UrlRuleFactory = UrlRuleFactory; +exports.BaseUrlRule = BaseUrlRule; +exports.UrlService = UrlService; +exports.ViewService = ViewService; +exports.UIRouterGlobals = UIRouterGlobals; +exports.UIRouter = UIRouter; +exports.$q = $q; +exports.$injector = $injector; +exports.BaseLocationServices = BaseLocationServices; +exports.HashLocationService = HashLocationService; +exports.MemoryLocationService = MemoryLocationService; +exports.PushStateLocationService = PushStateLocationService; +exports.MemoryLocationConfig = MemoryLocationConfig; +exports.BrowserLocationConfig = BrowserLocationConfig; +exports.keyValsToObjectR = keyValsToObjectR; +exports.getParams = getParams; +exports.parseUrl = parseUrl$1; +exports.buildUrl = buildUrl; +exports.locationPluginFactory = locationPluginFactory; +exports.servicesPlugin = servicesPlugin; +exports.hashLocationPlugin = hashLocationPlugin; +exports.pushStateLocationPlugin = pushStateLocationPlugin; +exports.memoryLocationPlugin = memoryLocationPlugin; +exports.UIRouterPluginBase = UIRouterPluginBase; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); +//# sourceMappingURL=angular-ui-router.js.map diff --git a/feature-toggles/manage/manage-toggles.css b/feature-toggles/manage/manage-toggles.css new file mode 100644 index 000000000..0fd087d93 --- /dev/null +++ b/feature-toggles/manage/manage-toggles.css @@ -0,0 +1,107 @@ +.navbar-content { + height: 100%; + display: grid; + grid-template-rows: auto 1fr; +} + +.content { + display: grid; + padding: 16px; + grid-template-columns: auto auto; + justify-content: space-between; +} + +.content > img { + height: 35px; +} + +.content > button { + border-radius: 50%; + border: none; + background-color: transparent; + color: white; +} + +.large-title, .small-title { + text-align: center; + padding: 8px; +} + +#toggles-box { + max-height: 100%; + overflow-y: auto; +} + +#toggles-box > div { + display: grid; + justify-content: center; + margin: 16px; +} + +.toggle-content { + display: grid; + grid-template-columns: auto 154px 154px 105px; + grid-column-gap: 10px; + grid-template-areas: + "name mobile desktop save"; + align-items: center; +} + +.toggle-content > md-select { + margin: 16px 0; +} + +#name { + grid-area: name; +} + +#mobile { + grid-area: mobile; +} + +#desktop { + grid-area: desktop; +} + +#save { + grid-area: save; +} + +@media screen and (max-width: 599px) { + + #toggles-box > div { + justify-content: stretch; + } + + .toggle-content { + grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr); + grid-template-rows: minmax(40px, 1fr); + grid-template-areas: + "name name" + "mobile desktop" + "save save"; + justify-items: center; + } + + #name { + text-align: center; + } + + #save { + justify-self: stretch; + } + + .large-title { + display: none + } + + #title { + text-align: center; + } +} + +@media screen and (min-width: 600px) { + .small-title { + display: none; + } +} \ No newline at end of file diff --git a/feature-toggles/manage/manage-toggles.html b/feature-toggles/manage/manage-toggles.html new file mode 100644 index 000000000..46fd48796 --- /dev/null +++ b/feature-toggles/manage/manage-toggles.html @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/feature-toggles/manage/manageTogglesController.js b/feature-toggles/manage/manageTogglesController.js new file mode 100644 index 000000000..dadb1e543 --- /dev/null +++ b/feature-toggles/manage/manageTogglesController.js @@ -0,0 +1,59 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + /** + * This controller manages the view that displays all features for the user. + */ + app.controller('ManageTogglesController', ['ManageTogglesService' , 'AuthService', 'MessageService' , function(ManageTogglesService, AuthService, + MessageService) { + + const manageTogglesCtrl = this; + manageTogglesCtrl.isLoading = false; + manageTogglesCtrl.features = []; + + /** + * Function to sign out of application. + */ + manageTogglesCtrl.logout = function() { + AuthService.logout(); + }; + + /** + * This function save the feature modifications. + * @param {Object} feature - Feature to be saved. + */ + manageTogglesCtrl.save = function save(feature) { + feature.isLoading = true; + return ManageTogglesService.saveFeature(feature) + .then(response => { + MessageService.showInfoToast("Alterações salvas com sucesso."); + return response; + }).catch(response => { + MessageService.showErrorToast(response.data.msg); + }).finally(function() { + feature.isLoading = false; + }); + }; + + /** + * Function to get all features from backend. + */ + function loadFeatures() { + return ManageTogglesService.getAllFeatureToggles().then(function(features) { + manageTogglesCtrl.features = features; + return features; + }).catch(response => { + MessageService.showErrorToast(response.data.msg); + }); + } + + /** + * This function initialize the controller by loading all features. + */ + manageTogglesCtrl.$onInit = function() { + return loadFeatures(); + }; + }]); +})(); \ No newline at end of file diff --git a/feature-toggles/manage/manageTogglesService.js b/feature-toggles/manage/manageTogglesService.js new file mode 100644 index 000000000..a120b1e83 --- /dev/null +++ b/feature-toggles/manage/manageTogglesService.js @@ -0,0 +1,29 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + /** + * This service is responsible for loading and changing the + * features through requests to the backend. + */ + app.service('ManageTogglesService', ['HttpService', function(HttpService) { + const service = this; + const URI = '/api/feature-toggles?lang=pt-br'; + + /** + * Function to get all features from backend. + */ + service.getAllFeatureToggles = function getAllFeatureToggles() { + return HttpService.get(URI); + }; + + /** + * Function to save feature. + * @param {Object} feature - feature to be save. + */ + service.saveFeature = function saveFeature(feature) { + return HttpService.put(URI, feature); + }; + }]); +})(); \ No newline at end of file diff --git a/feature-toggles/manage/permission-select.html b/feature-toggles/manage/permission-select.html new file mode 100644 index 000000000..72a28dd55 --- /dev/null +++ b/feature-toggles/manage/permission-select.html @@ -0,0 +1,9 @@ + + + + DESABILITADO + TODOS + TESTE + SUPER USÁRIO + + diff --git a/feature-toggles/manage/permissionSelect.component.js b/feature-toggles/manage/permissionSelect.component.js new file mode 100644 index 000000000..de09739de --- /dev/null +++ b/feature-toggles/manage/permissionSelect.component.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + app.controller('PermissionSelectController', permissionSelectController) + .component('permissionSelect', { + templateUrl: 'app/manage/permission-select.html', + controller: "PermissionSelectController", + controllerAs: 'permissionSelectCtrl', + bindings: { + label: '@', + feature: '=', + attr: '@' + } + }); + + function permissionSelectController() { + const permissionSelectCtrl = this; + + Object.defineProperty(permissionSelectCtrl, 'enable', { + get: () => permissionSelectCtrl.feature[permissionSelectCtrl.attr], + set: value => permissionSelectCtrl.feature[permissionSelectCtrl.attr] = value + }); + } +})(); \ No newline at end of file diff --git a/feature-toggles/manage/permission_select.css b/feature-toggles/manage/permission_select.css new file mode 100644 index 000000000..917093e55 --- /dev/null +++ b/feature-toggles/manage/permission_select.css @@ -0,0 +1,10 @@ +.select-container { + min-width: 140px; + width: 100%; +} + +@media screen and (max-width: 599px) { + .select-container { + margin-bottom: 0; + } +} \ No newline at end of file diff --git a/feature-toggles/test/init.js b/feature-toggles/test/init.js new file mode 100644 index 000000000..f271fb525 --- /dev/null +++ b/feature-toggles/test/init.js @@ -0,0 +1,51 @@ +'use strict'; + +/* +* File used to create perfect scenario before karma tests. +*/ +(function() { + // Initialize Firebase app + firebase.initializeApp({ + apiKey: "MOCK-API_KEY", + authDomain: "eciis-splab.firebaseapp.com", // Your Firebase Auth domain ("*.firebaseapp.com") + databaseURL: "https://eciis-splab.firebaseio.com", // Your Firebase Database URL ("https://*.firebaseio.com") + storageBucket: "eciis-splab.appspot.com", + messagingSenderId: "jdsfkbcbmnweuiyeuiwyhdjskalhdjkhjk" + }); + + var user = { + name : 'User' + }; + + // Create mock of authentication + angular.module('app').run(function (AuthService, UserService) { + var idToken = 'jdsfkbcbmnweuiyeuiwyhdjskalhdjkhjk'; + AuthService.login = function(user) { + UserService.load = function() { + return { + then : function(callback) { + return callback(user); + } + }; + }; + + AuthService.getUserToken = () => { + return { + then: (callback) => callback(idToken) + }; + } + + AuthService.setupUser(idToken, true); + }; + + const originalGetUserToken = AuthService.getUserToken; + + AuthService.useOriginalGetUserToken = () => { + AuthService.getUserToken = originalGetUserToken; + }; + + AuthService.login(user); + + Config.BACKEND_URL = ''; + }); +})(); \ No newline at end of file diff --git a/feature-toggles/test/karma.conf.js b/feature-toggles/test/karma.conf.js new file mode 100644 index 000000000..cd2ab39e1 --- /dev/null +++ b/feature-toggles/test/karma.conf.js @@ -0,0 +1,95 @@ +// Karma configuration +module.exports = function (config) { + config.set({ + + // 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', 'chai-as-promised', 'chai'], + + + // list of files / patterns to load in the browser + files: [ + '../utils/utils.js', + 'node_modules/angular/angular.js', + 'node_modules/angular-animate/angular-animate.js', + 'node_modules/angular-aria/angular-aria.js', + 'node_modules/angular-messages/angular-messages.js', + 'node_modules/angular-material/angular-material.js', + 'node_modules/@uirouter/angularjs/release/angular-ui-router.js', + 'node_modules/lodash/lodash.js', + 'node_modules/angular-mocks/angular-mocks.js', + 'node_modules/firebase/firebase.js', + 'node_modules/angularfire/dist/angularfire.js', + "node_modules/mockfirebase/browser/mockfirebase.js", + '../*.js', + '../*/*.js', + '../*/*/*.js', + 'specs/**/*.js', + ], + + + // list of files to exclude + exclude: [ + "../landingPage/*", + "../sw.js" + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['spec'], + + + // 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: ['ChromeHeadlessNoSandbox'], + + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'] + } + }, + + // 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, + + // if true, it shows console logs + client: { + captureConsole: false + } + }) +} diff --git a/feature-toggles/test/package.json b/feature-toggles/test/package.json new file mode 100644 index 000000000..3efe9a86c --- /dev/null +++ b/feature-toggles/test/package.json @@ -0,0 +1,28 @@ +{ + "devDependencies": { + "@uirouter/angularjs": "^1.0.5", + "angular": "1.6.4", + "angular-animate": "1.6.4", + "angular-aria": "1.6.4", + "angular-material": "1.1.5", + "angular-messages": "1.6.4", + "angular-mocks": "1.6.4", + "angularfire": "^2.3.0", + "jasmine": "2.99.0", + "karma": "^1.7.0", + "karma-chai-plugins": "^0.9.0", + "karma-chrome-launcher": "^2.1.1", + "karma-firefox-launcher": "^1.0.1", + "karma-jasmine": "1.1.0", + "karma-jasmine-html-reporter": "0.2.2", + "karma-spec-reporter": "0.0.31", + "lodash": "^4.17.4", + "mockfirebase": "^0.12.0" + }, + "dependencies": { + "package.json": "^2.0.1" + }, + "engines": { + "yarn": ">= 1.0.0" + } +} diff --git a/feature-toggles/test/specs/auth/authServiceSpec.js b/feature-toggles/test/specs/auth/authServiceSpec.js new file mode 100644 index 000000000..c93de01ff --- /dev/null +++ b/feature-toggles/test/specs/auth/authServiceSpec.js @@ -0,0 +1,144 @@ +'use strict'; + +(describe('Test AuthService', function() { + let authService, userService, userFactory, scope; + + let userTest = { + name : 'User', + accessToken: 'gfdfggfdjdsfkbcbmnweuiyeuiwyhdjskalhdjkhjk', + emailVerified: true + }; + + let firebaseUser = { + accessToken: 'ruioewyuirywieuryiuweyr876324875632487yiue', + getIdToken: async () => firebaseUser.accessToken + }; + + beforeEach(module('app')); + + beforeEach(inject(function(AuthService, UserService, UserFactory, $rootScope) { + authService = AuthService; + userService = UserService; + userFactory = UserFactory; + scope = $rootScope.$new(); + + firebase.auth = () => { + return { + onAuthStateChanged: (callback) => callback(firebaseUser), + signOut: function signOut() {} + }; + }; + + firebase.auth.GoogleAuthProvider = function GoogleAuthProvider() {}; + authService.useOriginalGetUserToken(); + })); + + describe('AuthService setupUser', function() { + + it('should be config user with firebase token', function() { + spyOn(userService, 'load').and.callThrough(); + + authService.setupUser(userTest.accessToken, userTest.emailVerified); + const user = authService.getCurrentUser(); + const new_user = new userFactory.user(userTest); + + expect(userService.load).toHaveBeenCalled(); + expect(user).toEqual(new_user); + }); + }); + + describe('AuthService user informations', function() { + + describe('test getCurrentUser', function() { + it('should be return user logged', function() { + spyOn(userService, 'load').and.callThrough(); + authService.setupUser(userTest.accessToken, userTest.emailVerified); + const user = authService.getCurrentUser(); + const new_user = new userFactory.user(userTest); + expect(user).toEqual(new_user); + }); + }); + + describe('test getUserToken', function() { + it('should be return actualized user token', function(done) { + spyOn(authService, 'save'); + const user = { + accessToken: firebaseUser.accessToken, + getIdToken: async () => user.accessToken + }; + + authService._getIdToken(user); + authService.getUserToken().then(userToken => { + expect(userToken).toEqual(firebaseUser.accessToken); + expect(authService.save).toHaveBeenCalled(); + done(); + }); + + scope.$apply(); + }); + }); + + describe('test isLoggedIn', function() { + it('should be return true', function() { + const isLoggedIn = authService.isLoggedIn(); + expect(isLoggedIn).toEqual(true); + }); + + it('should be return false', function() { + authService.logout(); + const isLoggedIn = authService.isLoggedIn(); + expect(isLoggedIn).toEqual(false); + }); + }); + + describe('test save', function() { + it('should be save user in localStorage', function() { + spyOn(userService, 'load').and.callThrough(); + authService.setupUser(userTest.accessToken, userTest.emailVerified); + + window.localStorage.userInfo = null; + authService.save(); + const userCache = window.localStorage.userInfo; + const new_user = JSON.stringify(userTest); + + expect(userCache).toEqual(new_user); + }); + }); + }); + + describe('_getIdToken', function() { + beforeEach(function() { + authService.setupUser(userTest.accessToken); + authService.resolveTokenPromise = () => {}; + spyOn(authService, 'resolveTokenPromise').and.callFake(() => {}); + }); + + it('should refresh token when the request of new token is successful', function(done) { + const user = { + accessToken: "riuewyirouyweiuryiu21y3iuyiuwyeiudsjikahkjsah", + getIdToken: async () => user.accessToken + }; + const savedResolveTokenPromisse = authService.resolveTokenPromise; + + authService._getIdToken(user).then(function(accessToken) { + expect(accessToken).toEqual(user.accessToken); + expect(savedResolveTokenPromisse).toHaveBeenCalled(); + done(); + }); + }); + + it('should refresh token when the request of new token fail', function(done) { + const user = { + accessToken: "riuewyirouyweiuryiu21y3iuyiuwyeiudsjikahkjsah", + getIdToken: async () => {throw "Network error!"} + }; + const savedResolveTokenPromisse = authService.resolveTokenPromise; + + authService._getIdToken(user).then(function(accessToken) { + expect(accessToken).toEqual(firebaseUser.accessToken); + expect(savedResolveTokenPromisse).toHaveBeenCalled(); + done(); + }); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/auth/loginControllerSpec.js b/feature-toggles/test/specs/auth/loginControllerSpec.js new file mode 100644 index 000000000..bd8381e9c --- /dev/null +++ b/feature-toggles/test/specs/auth/loginControllerSpec.js @@ -0,0 +1,135 @@ +'use strict'; + +(describe('Test LoginController', function() { + + let logginCtrl, httpBackend, scope, createCtrl, state, authService, states, q, messageService; + + const user = { + name: 'Tiago', + state: 'active' + }; + + beforeEach(module('app')); + + beforeEach(inject(function($controller, $httpBackend, $rootScope, STATES, $state, AuthService, $q, MessageService) { + httpBackend = $httpBackend; + scope = $rootScope.$new(); + state = $state; + states = STATES; + authService = AuthService; + q = $q; + messageService = MessageService; + + authService.login(user); + + spyOn(authService, 'isLoggedIn').and.callThrough(); + httpBackend.when('GET', '/signin').respond(200); + + createCtrl = function() { + return $controller('LoginController', { + scope: scope, + AuthService: authService + }); + }; + logginCtrl = createCtrl(); + })); + + afterEach(function() { + httpBackend.verifyNoOutstandingExpectation(); + httpBackend.verifyNoOutstandingRequest(); + }); + + describe('main()', function() { + + it('should change state to manage_features if user is loggedIn', function() { + spyOn(state, 'go').and.callThrough(); + logginCtrl.$onInit(); + expect(authService.isLoggedIn).toHaveBeenCalled(); + expect(state.go).toHaveBeenCalledWith(states.MANAGE_FEATURES); + }); + + it('should not call state.go if user is not loggedIn', function() { + authService.logout(); + spyOn(state, 'go').and.callThrough(); + logginCtrl.$onInit(); + expect(authService.isLoggedIn).toHaveBeenCalled(); + expect(state.go).not.toHaveBeenCalled(); + }); + }); + + describe('isLoadingUser()', function() { + it('should return true if AuthService.isLoadingUser is true', () => { + authService.isLoadingUser = true; + expect(logginCtrl.isLoadingUser()).toBe(true); + }); + + it('should return false if AuthService.isLoadingUser is false', () => { + authService.isLoadingUser = false; + expect(logginCtrl.isLoadingUser()).toBe(false); + }); + }); + + describe('test loginWithGoogle', function() { + it('Should be call state.go if login is successful', function(done) { + spyOn(authService, 'loginWithGoogle').and.callFake(function() { + return q.when(); + }); + spyOn(state, 'go'); + + logginCtrl.loginWithGoogle().then(function() { + expect(authService.loginWithGoogle).toHaveBeenCalled(); + expect(state.go).toHaveBeenCalled(); + done(); + }); + + scope.$apply(); + }); + + it('Should be call messageService.showErrorToast if login is not successful', function(done) { + spyOn(authService, 'loginWithGoogle').and.callFake(function() { + return q.reject('Login failed'); + }); + spyOn(messageService, 'showErrorToast'); + + logginCtrl.loginWithGoogle().then(function() { + expect(authService.loginWithGoogle).toHaveBeenCalled(); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Login failed'); + done(); + }); + + scope.$apply(); + }); + }); + + describe('test loginWithEmailPassword', function() { + it('Should be call state.go if login is successful', function(done) { + spyOn(authService, 'loginWithEmailAndPassword').and.callFake(function() { + return q.when(); + }); + spyOn(state, 'go'); + + logginCtrl.loginWithEmailPassword().then(function() { + expect(authService.loginWithEmailAndPassword).toHaveBeenCalledWith(logginCtrl.user.email, logginCtrl.user.password); + expect(state.go).toHaveBeenCalled(); + done(); + }); + + scope.$apply(); + }); + + it('Should be call messageService.showErrorToast if login is not successful', function(done) { + spyOn(authService, 'loginWithEmailAndPassword').and.callFake(function() { + return q.reject('Login failed'); + }); + spyOn(messageService, 'showErrorToast'); + + logginCtrl.loginWithEmailPassword().then(function() { + expect(authService.loginWithEmailAndPassword).toHaveBeenCalledWith(logginCtrl.user.email, logginCtrl.user.password); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Login failed'); + done(); + }); + + scope.$apply(); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/manage/manageTogglesControllerSpec.js b/feature-toggles/test/specs/manage/manageTogglesControllerSpec.js new file mode 100644 index 000000000..79b0db0b5 --- /dev/null +++ b/feature-toggles/test/specs/manage/manageTogglesControllerSpec.js @@ -0,0 +1,122 @@ +(describe('ManageTogglesConstoller Tests', function() { + beforeEach(module('app')); + + let authService, messageService, manageTogglesServices, manageTogglesCtrl, q, scope; + + const feature = { + 'name': 'edit-inst' + }; + + const otherFature = { + 'name': 'edit-user' + }; + + + beforeEach(inject(function(AuthService, MessageService, ManageTogglesService, $controller, $q, $rootScope) { + authService = AuthService; + manageTogglesServices = ManageTogglesService; + messageService = MessageService; + q = $q; + scope = $rootScope.$new(); + + manageTogglesCtrl = $controller('ManageTogglesController', { + AuthService, + MessageService, + ManageTogglesService + }); + })); + + describe('Test $onInit', function() { + + it('Should be get all features', function(done) { + spyOn(manageTogglesServices, 'getAllFeatureToggles').and.callFake(function() { + return q.when([feature, otherFature]); + }); + + manageTogglesCtrl.$onInit().then(function(response) { + expect(manageTogglesServices.getAllFeatureToggles).toHaveBeenCalled(); + expect(response).toEqual([feature, otherFature]); + done(); + }); + + scope.$apply(); + }); + + it('Should be show error message', function(done) { + spyOn(messageService, 'showErrorToast'); + spyOn(manageTogglesServices, 'getAllFeatureToggles').and.callFake(function() { + return q.reject({ + data: { + msg: 'Request fail' + } + }); + }); + + manageTogglesCtrl.$onInit().then(function() { + expect(messageService.showErrorToast).toHaveBeenCalledWith('Request fail'); + done(); + }); + + scope.$apply(); + }); + }); + + describe('Test logout', function() { + + it('Should be call AuthService.logout', function() { + spyOn(authService, 'logout'); + manageTogglesCtrl.logout(); + expect(authService.logout).toHaveBeenCalled(); + }); + }); + + describe('Test save', function() { + beforeEach(function() { + spyOn(messageService, 'showInfoToast'); + spyOn(messageService, 'showErrorToast'); + }); + + it('Should be call messageService.saveFeature', function(done) { + spyOn(manageTogglesServices, 'saveFeature').and.callFake(function(feature) { + return q.when(feature); + }); + + + const promise = manageTogglesCtrl.save(feature); + + expect(feature.isLoading).toBeTruthy(); + + promise.then(function(response) { + expect(messageService.showInfoToast).toHaveBeenCalledWith("Alterações salvas com sucesso."); + expect(manageTogglesServices.saveFeature).toHaveBeenCalledWith(feature); + expect(response).toEqual(feature); + expect(manageTogglesCtrl.isLoading).toBeFalsy(); + done(); + }); + + scope.$apply(); + }); + + it('Should be call messageService with error message', function(done) { + spyOn(manageTogglesServices, 'saveFeature').and.callFake(function(feature) { + return q.reject({ + data: { + msg: 'Feature not found' + } + }); + }); + + const promise = manageTogglesCtrl.save(feature); + + expect(feature.isLoading).toBeTruthy(); + + promise.then(function() { + expect(messageService.showErrorToast).toHaveBeenCalledWith("Feature not found"); + expect(manageTogglesCtrl.isLoading).toBeFalsy(); + done(); + }); + + scope.$apply(); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/manage/manageTogglesServiceSpec.js b/feature-toggles/test/specs/manage/manageTogglesServiceSpec.js new file mode 100644 index 000000000..ef3a5b5ae --- /dev/null +++ b/feature-toggles/test/specs/manage/manageTogglesServiceSpec.js @@ -0,0 +1,54 @@ +(describe('ManageTogglesservice Tests', function(){ + beforeEach(module('app')); + + let manageTogglesService, httpService, q, scope; + + const URI = '/api/feature-toggles?lang=pt-br'; + const feature = { + 'name': 'edit-inst' + }; + + const otherFature = { + 'name': 'edit-user' + }; + + beforeEach(inject(function(ManageTogglesService, HttpService, $q, $rootScope) { + manageTogglesService = ManageTogglesService; + httpService = HttpService; + q = $q; + scope = $rootScope.$new(); + })); + + describe('Test getAllFeaturesToggles', function() { + + it('Should be return all features', function(done) { + spyOn(httpService, 'get').and.callFake(function() { + return q.when([feature, otherFature]); + }); + + manageTogglesService.getAllFeatureToggles().then(function(response) { + expect(httpService.get).toHaveBeenCalled(); + expect(response).toEqual([feature, otherFature]); + done(); + }); + + scope.$apply(); + }); + }); + + describe('Test saveFeatures', function() { + it('Should be call httpService.put with the feature', function(done) { + spyOn(httpService, 'put').and.callFake(function(url, feature) { + return q.when(feature); + }); + + manageTogglesService.saveFeature(feature).then(function(response) { + expect(httpService.put).toHaveBeenCalledWith(URI, feature); + expect(response).toEqual(feature); + done(); + }); + + scope.$apply(); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/user/userFactorySpec.js b/feature-toggles/test/specs/user/userFactorySpec.js new file mode 100644 index 000000000..e2dce13ee --- /dev/null +++ b/feature-toggles/test/specs/user/userFactorySpec.js @@ -0,0 +1,118 @@ +'use strict'; + +(describe('Test User model', function() { + beforeEach(module('app')); + + let user, createUser; + + const inst = { + color: 'blue', + name: 'inst', + key: '987654321', + photo_url: 'pokaasodsok' + }; + + const other_inst = { + color: 'grey', + name: 'other_inst', + key: '123456789', + parent_institution: '987654321' + }; + + const inviteUser = { + institution_key: "098745", + type_of_invite: "USER", + invitee: "mayzabeel@gmail.com", + status: 'sent' + }; + + const inviteInstitution = { + institution_key: "098745", + type_of_invite: "INSTITUTION", + suggestion_institution_name: "New Institution", + invitee: "mayzabeel@gmail.com", + status: 'sent' + }; + + const userData = { + name: 'Tiago Pereira', + cpf: '111.111.111-11', + email: 'tiago.pereira@ccc.ufcg.edu.br', + institutions: [inst], + follows: [inst], + invites: [inviteUser, inviteInstitution], + permissions: { + 'invite-user': 'dhkajshdiuyd9898d8aduashdh' + } + }; + + beforeEach(inject(function(UserFactory) { + createUser = function() { + var result = new UserFactory.user(userData); + return result; + }; + })); + + describe('User properties', function() { + + beforeEach(function() { + user = createUser(); + }); + + it('username should be Tiago Pereira', function() { + expect(user.name).toEqual('Tiago Pereira'); + }); + + it('cpf should be 111.111.111-11', function() { + expect(user.cpf).toEqual('111.111.111-11'); + }); + + it('email should be tiago.pereira@ccc.ufcg.edu.br', function() { + expect(user.email).toEqual('tiago.pereira@ccc.ufcg.edu.br'); + }); + + it('institutions should contain inst', function() { + expect(user.institutions).toContain(inst); + }); + + it('follows should contain inst key', function() { + expect(user.follows).toContain(inst); + }); + }); + + describe('User functions', function() { + + describe('changeInstitution', function() { + + it('should call JSON stringify', function() { + spyOn(JSON, 'stringify').and.callThrough(); + + userData.institutions = [inst, other_inst]; + user = createUser(); + + expect(user.current_institution).toBe(inst); + + user.changeInstitution(other_inst); + + expect(JSON.stringify).toHaveBeenCalled(); + expect(user.current_institution).toBe(other_inst); + + var cachedUser = JSON.parse(window.localStorage.userInfo); + + expect(cachedUser.current_institution).toEqual(other_inst); + }); + }); + + describe('hasPermission', function() { + it('Should be return true', function() { + user = createUser(); + expect(user.hasPermission('invite-user')).toBeTruthy(); + }); + + it('Should be return false', function() { + user = createUser(); + expect(user.hasPermission('invite-inst')).toBeFalsy(); + }); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/user/userServiceSpec.js b/feature-toggles/test/specs/user/userServiceSpec.js new file mode 100644 index 000000000..4ab83be3e --- /dev/null +++ b/feature-toggles/test/specs/user/userServiceSpec.js @@ -0,0 +1,51 @@ +'use strict'; + +(describe('Test UserService', function () { + let httpBackend, service, $http, scope; + + const user = { + name: 'User', + key: '12345', + state: 'active', + profile: { + 'institutional_email': 'user@ccc.ufcg.edu.br', + 'office': 'developer' + } + }; + + const institution = { + name: 'Splab', + key: '098745', + followers: [user.key], + members: [user.key] + }; + + user.current_institution = institution; + user.follows = [institution.key]; + user.institutions = [institution.key]; + + beforeEach(module('app')); + + beforeEach(inject(function($httpBackend, UserService, HttpService, $rootScope, AuthService) { + httpBackend = $httpBackend; + $http = HttpService; + scope = $rootScope.$new(); + service = UserService; + AuthService.login(user); + })); + + afterEach(function() { + httpBackend.verifyNoOutstandingExpectation(); + httpBackend.verifyNoOutstandingRequest(); + }); + + describe('Test UserService functions', function() { + it('load()', function(done) { + service.load().then(function(data){ + expect(data).toEqual(user); + done(); + }); + }); + + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/utils/httpServiceSpec.js b/feature-toggles/test/specs/utils/httpServiceSpec.js new file mode 100644 index 000000000..46764e5fa --- /dev/null +++ b/feature-toggles/test/specs/utils/httpServiceSpec.js @@ -0,0 +1,52 @@ +'use strict'; + +(describe("Test HttpService", function() { + var httpBackend, httpService; + + beforeEach(module('app')); + beforeEach(inject(function($httpBackend, HttpService) { + httpBackend = $httpBackend; + httpService = HttpService; + })); + + afterEach(function() { + httpBackend.verifyNoOutstandingExpectation(); + httpBackend.verifyNoOutstandingRequest(); + }); + + describe("get()", function() { + it('Should get', function() { + httpService.get('/test'); + + httpBackend.expect('GET', '/test').respond(200); + httpBackend.flush(); + }); + }); + + describe("post()", function() { + it('Should post', function() { + httpService.post('/test'); + + httpBackend.expect('POST', '/test').respond(200); + httpBackend.flush(); + }); + }); + + describe("put()", function() { + it('Should put', function() { + httpService.put('/test'); + + httpBackend.expect('PUT', '/test').respond(200); + httpBackend.flush(); + }); + }); + + describe("delete()", function() { + it('Should delete', function() { + httpService.delete('/test'); + + httpBackend.expect('DELETE', '/test').respond(200); + httpBackend.flush(); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/utils/messageServiceSpec.js b/feature-toggles/test/specs/utils/messageServiceSpec.js new file mode 100644 index 000000000..1fe192b54 --- /dev/null +++ b/feature-toggles/test/specs/utils/messageServiceSpec.js @@ -0,0 +1,45 @@ +'use strict'; + +(describe('Test MessageService', function () { + var httpBackend, service, mdToast; + + beforeEach(module('app')); + + beforeEach(inject(function($httpBackend, MessageService, $mdToast) { + httpBackend = $httpBackend; + mdToast = $mdToast; + service = MessageService; + })); + + describe("showInfoToast", function() { + it('should call mdToast.show', function() { + window.screen = { width: 2000 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showInfoToast(""); + expect(mdToast.show).toHaveBeenCalled(); + }); + + it('should not call mdToast.show', function() { + window.screen = { width: 200 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showInfoToast(""); + expect(mdToast.show).not.toHaveBeenCalled(); + }); + }); + + describe("showErrorToast", function() { + it('should call mdToast.show', function() { + window.screen = { width: 2000 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showErrorToast(""); + expect(mdToast.show).toHaveBeenCalled(); + }); + + it('should call mdToast.show', function() { + window.screen = { width: 200 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showErrorToast(""); + expect(mdToast.show).toHaveBeenCalled(); + }); + }); +})); \ No newline at end of file diff --git a/feature-toggles/test/specs/utils/utilsSpec.js b/feature-toggles/test/specs/utils/utilsSpec.js new file mode 100644 index 000000000..47b69a6f0 --- /dev/null +++ b/feature-toggles/test/specs/utils/utilsSpec.js @@ -0,0 +1,18 @@ +'use strict'; + +(describe('Test Utils', function() { + describe('updateBackendUrl', function () { + + it('should replace the original domain by the local one', function () { + var localDomain = Config.BACKEND_URL; + var otherDomain = 'http://www.other-url'; + var apiResource = '/api/some/resource'; + var config = { url: otherDomain + apiResource }; + Utils.updateBackendUrl(config); + expect(config.url).toEqual(localDomain + apiResource); + }); + }); + +})); + + diff --git a/feature-toggles/test/yarn.lock b/feature-toggles/test/yarn.lock new file mode 100644 index 000000000..66db9ea31 --- /dev/null +++ b/feature-toggles/test/yarn.lock @@ -0,0 +1,4195 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@uirouter/angularjs@^1.0.5": + version "1.0.22" + resolved "https://registry.yarnpkg.com/@uirouter/angularjs/-/angularjs-1.0.22.tgz#581ab38794a2d7c2790851087072c4066b2b6c46" + integrity sha512-d0SvdbXAav+Z6gCJd7gmn2eXEUtO3RvYcSLwtPaE8+7QiWHpSKNfGdD4D3noXhO2yUTz/AwaxsiRFMCwgVI0UQ== + dependencies: + "@uirouter/core" "5.0.23" + +"@uirouter/core@5.0.23": + version "5.0.23" + resolved "https://registry.yarnpkg.com/@uirouter/core/-/core-5.0.23.tgz#363b4bea635a1b48900dc7e65793a65a3b58a79e" + integrity sha512-rwFOH++z/KY8y+h0IOpQ5uC8Nim6E0EBCQrIjhVCr+XKYXgpK+VdtuOLFdogvbJ3AAi5Z7ei00qdEr7Did5CAg== + +Base64@~0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/Base64/-/Base64-0.2.1.tgz#ba3a4230708e186705065e66babdd4c35cf60028" + integrity sha1-ujpCMHCOGGcFBl5mur3Uw1z2ACg= + +JSONStream@^1.0.3: + version "1.3.5" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" + integrity sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ== + dependencies: + jsonparse "^1.2.0" + through ">=2.2.7 <3" + +JSONStream@~0.8.3, JSONStream@~0.8.4: + version "0.8.4" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-0.8.4.tgz#91657dfe6ff857483066132b4618b62e8f4887bd" + integrity sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70= + dependencies: + jsonparse "0.0.5" + through ">=2.2.7 <3" + +MD5@~1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/MD5/-/MD5-1.2.2.tgz#d903c8ec5ba223cd2b80432824881d04bb9841c0" + integrity sha1-2QPI7FuiI80rgEMoJIgdBLuYQcA= + dependencies: + charenc ">= 0.0.1" + crypt ">= 0.0.1" + +abbrev@1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" + integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== + +abs@^1.2.1: + version "1.3.13" + resolved "https://registry.yarnpkg.com/abs/-/abs-1.3.13.tgz#a495e086d51fc1ef4fd3a30ac56c895d98435f1b" + integrity sha512-VgsJF4AZDoxLwTRx+TlZ6gpHfSaRUcg1Vhyruqxzpr6lTmh3JMO9667AHAVUGHUD3Li9QqjX2WaTXR6pkGFU+Q== + dependencies: + ul "^5.0.0" + +accepts@1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.3.tgz#c3ca7434938648c3e0d9c1e328dd68b622c284ca" + integrity sha1-w8p0NJOGSMPg2cHjKN1otiLChMo= + dependencies: + mime-types "~2.1.11" + negotiator "0.6.1" + +accessory@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/accessory/-/accessory-1.1.0.tgz#7833e9839a32ded76d26021f36a41707a520f593" + integrity sha1-eDPpg5oy3tdtJgIfNqQXB6Ug9ZM= + dependencies: + ap "~0.2.0" + balanced-match "~0.2.0" + dot-parts "~1.0.0" + +acorn-dynamic-import@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz#482210140582a36b83c3e342e1cfebcaa9240948" + integrity sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw== + +acorn-node@^1.2.0: + version "1.6.2" + resolved "https://registry.yarnpkg.com/acorn-node/-/acorn-node-1.6.2.tgz#b7d7ceca6f22e6417af933a62cad4de01048d5d2" + integrity sha512-rIhNEZuNI8ibQcL7ANm/mGyPukIaZsRNX9psFNQURyJW0nu6k8wjSDld20z6v2mDBWqX13pIEnk9gGZJHIlEXg== + dependencies: + acorn "^6.0.2" + acorn-dynamic-import "^4.0.0" + acorn-walk "^6.1.0" + xtend "^4.0.1" + +acorn-walk@^6.1.0: + version "6.1.1" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.1.1.tgz#d363b66f5fac5f018ff9c3a1e7b6f8e310cc3913" + integrity sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw== + +acorn@^4.0.3: + version "4.0.13" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" + integrity sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c= + +acorn@^5.2.1: + version "5.7.3" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" + integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + +acorn@^6.0.2: + version "6.0.7" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.7.tgz#490180ce18337270232d9488a44be83d9afb7fd3" + integrity sha512-HNJNgE60C9eOTgn974Tlp3dpLZdUr+SoxxDwPaY9J/kDNOLQTkaDgwBUXAF4SSsrAwD9RpdxuHK/EbuF+W9Ahw== + +after@0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" + integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8= + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU= + +angular-animate@1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/angular-animate/-/angular-animate-1.6.4.tgz#d3eb906d39834f2dfbdd982e6b8d7a3b4d9001d2" + integrity sha1-0+uQbTmDTy373Zgua416O02QAdI= + +angular-aria@1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/angular-aria/-/angular-aria-1.6.4.tgz#c8683666ace196668f68e7220811bdcfc9e106e4" + integrity sha1-yGg2ZqzhlmaPaOciCBG9z8nhBuQ= + +angular-material@1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/angular-material/-/angular-material-1.1.5.tgz#a5450cd8205e15a7691edc389476094cf86d592b" + integrity sha1-pUUM2CBeFadpHtw4lHYJTPhtWSs= + +angular-messages@1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/angular-messages/-/angular-messages-1.6.4.tgz#9ec9c1393293b14de54161d2f849776489e980fe" + integrity sha1-nsnBOTKTsU3lQWHS+El3ZInpgP4= + +angular-mocks@1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/angular-mocks/-/angular-mocks-1.6.4.tgz#47fdf50921cf24fb489f100a8cf2ad99d0538f40" + integrity sha1-R/31CSHPJPtInxAKjPKtmdBTj0A= + +angular@1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/angular/-/angular-1.6.4.tgz#03b7b15c01a0802d7e2cf593240e604054dc77fb" + integrity sha1-A7exXAGggC1+LPWTJA5gQFTcd/s= + +angularfire@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/angularfire/-/angularfire-2.3.0.tgz#c152d12b655cd21a039956015c7dcdfcc4f25da5" + integrity sha1-wVLRK2Vc0hoDmVYBXH3N/MTyXaU= + dependencies: + firebase "3.x.x" + +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= + +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= + +anymatch@^1.3.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a" + integrity sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA== + dependencies: + micromatch "^2.1.5" + normalize-path "^2.0.0" + +ap@~0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/ap/-/ap-0.2.0.tgz#ae0942600b29912f0d2b14ec60c45e8f330b6110" + integrity sha1-rglCYAspkS8NKxTsYMRejzMLYRA= + +aproba@^1.0.3: + version "1.2.0" + resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" + integrity sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw== + +are-we-there-yet@~1.1.2: + version "1.1.5" + resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21" + integrity sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w== + dependencies: + delegates "^1.0.0" + readable-stream "^2.0.6" + +arr-diff@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" + integrity sha1-jzuCf5Vai9ZpaX5KQlasPOrjVs8= + dependencies: + arr-flatten "^1.0.1" + +arr-diff@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" + integrity sha1-1kYQdP6/7HHn4VI1dhoyml3HxSA= + +arr-flatten@^1.0.1, arr-flatten@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" + integrity sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg== + +arr-union@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" + integrity sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ= + +array-slice@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-0.2.3.tgz#dd3cfb80ed7973a75117cdac69b0b99ec86186f5" + integrity sha1-3Tz7gO15c6dRF82sabC5nshhhvU= + +array-unique@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" + integrity sha1-odl8yvy8JiXMcPrc6zalDFiwGlM= + +array-unique@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" + integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg= + +arraybuffer.slice@0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz#f33b2159f0532a3f3107a272c0ccfbd1ad2979ca" + integrity sha1-8zshWfBTKj8xB6JywMz70a0peco= + +asn1.js@^4.0.0: + version "4.10.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0" + integrity sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw== + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +assert@~1.1.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/assert/-/assert-1.1.2.tgz#adaa04c46bb58c6dd1f294da3eb26e6228eb6e44" + integrity sha1-raoExGu1jG3R8pTaPrJuYijrbkQ= + dependencies: + util "0.10.3" + +assertion-error@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + +assign-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" + integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c= + +astw@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/astw/-/astw-2.2.0.tgz#7bd41784d32493987aeb239b6b4e1c57a873b917" + integrity sha1-e9QXhNMkk5h66yOba04cV6hzuRc= + dependencies: + acorn "^4.0.3" + +async-each@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" + integrity sha1-GdOGodntxufByF04iu28xW0zYC0= + +async@~0.2.6: + version "0.2.10" + resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" + integrity sha1-trvgsGdLnXGXCMo43owjfLUmw9E= + +atob@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" + integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== + +backo2@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" + integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + +balanced-match@~0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.2.1.tgz#7bc658b4bed61eee424ad74f75f5c3e2c4df3cc7" + integrity sha1-e8ZYtL7WHu5CStdPdfXD4sTfPMc= + +base64-arraybuffer@0.1.5: + version "0.1.5" + resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" + integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg= + +base64-js@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-0.0.7.tgz#54400dc91d696cec32a8a47902f971522fee8f48" + integrity sha1-VEANyR1pbOwyqKR5AvlxUi/uj0g= + +base64id@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/base64id/-/base64id-1.0.0.tgz#47688cb99bb6804f0e06d3e763b1c32e57d8e6b6" + integrity sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY= + +base@^0.11.1: + version "0.11.2" + resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" + integrity sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg== + dependencies: + cache-base "^1.0.1" + class-utils "^0.3.5" + component-emitter "^1.2.1" + define-property "^1.0.0" + isobject "^3.0.1" + mixin-deep "^1.2.0" + pascalcase "^0.1.1" + +better-assert@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" + integrity sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= + dependencies: + callsite "1.0.0" + +binary-extensions@^1.0.0: + version "1.13.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.0.tgz#9523e001306a32444b907423f1de2164222f6ab1" + integrity sha512-EgmjVLMn22z7eGGv3kcnHwSnJXmFHjISTY9E/S5lIcTD3Oxw05QTcBLNkJFzcb3cNueUdF/IN4U+d78V0zO8Hw== + +blob@0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.4.tgz#bcf13052ca54463f30f9fc7e95b9a47630a94921" + integrity sha1-vPEwUspURj8w+fx+lbmkdjCpSSE= + +bluebird@^3.3.0: + version "3.5.3" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" + integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw== + +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: + version "4.11.8" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" + integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== + +body-parser@^1.16.1: + version "1.18.3" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4" + integrity sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ= + dependencies: + bytes "3.0.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.2" + http-errors "~1.6.3" + iconv-lite "0.4.23" + on-finished "~2.3.0" + qs "6.5.2" + raw-body "2.3.3" + type-is "~1.6.16" + +brace-expansion@^1.0.0, brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +braces@^0.1.2: + version "0.1.5" + resolved "https://registry.yarnpkg.com/braces/-/braces-0.1.5.tgz#c085711085291d8b75fdd74eab0f8597280711e6" + integrity sha1-wIVxEIUpHYt1/ddOqw+FlygHEeY= + dependencies: + expand-range "^0.1.0" + +braces@^1.8.2: + version "1.8.5" + resolved "https://registry.yarnpkg.com/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7" + integrity sha1-uneWLhLf+WnWt2cR6RS3N4V79qc= + dependencies: + expand-range "^1.8.1" + preserve "^0.2.0" + repeat-element "^1.1.2" + +braces@^2.3.1: + version "2.3.2" + resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" + integrity sha512-aNdbnj9P8PjdXU4ybaWLK2IF3jc/EoDYbC7AazW6to3TRsfXxscC9UXOB5iDiEQrkyIbWp2SLQda4+QAa7nc3w== + dependencies: + arr-flatten "^1.1.0" + array-unique "^0.3.2" + extend-shallow "^2.0.1" + fill-range "^4.0.0" + isobject "^3.0.1" + repeat-element "^1.1.2" + snapdragon "^0.8.1" + snapdragon-node "^2.0.1" + split-string "^3.0.2" + to-regex "^3.0.1" + +brorand@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" + integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8= + +browser-pack@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/browser-pack/-/browser-pack-3.2.0.tgz#faa1cbc41487b1acc4747e373e1148adffd0e2d9" + integrity sha1-+qHLxBSHsazEdH43PhFIrf/Q4tk= + dependencies: + JSONStream "~0.8.4" + combine-source-map "~0.3.0" + concat-stream "~1.4.1" + defined "~0.0.0" + through2 "~0.5.1" + umd "^2.1.0" + +browser-resolve@^1.3.0, browser-resolve@^1.7.0: + version "1.11.3" + resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.3.tgz#9b7cbb3d0f510e4cb86bdbd796124d28b5890af6" + integrity sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ== + dependencies: + resolve "1.1.7" + +browserify-aes@^1.0.0, browserify-aes@^1.0.4: + version "1.2.0" + resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.2.0.tgz#326734642f403dabc3003209853bb70ad428ef48" + integrity sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA== + dependencies: + buffer-xor "^1.0.3" + cipher-base "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.3" + inherits "^2.0.1" + safe-buffer "^5.0.1" + +browserify-cipher@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/browserify-cipher/-/browserify-cipher-1.0.1.tgz#8d6474c1b870bfdabcd3bcfcc1934a10e94f15f0" + integrity sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w== + dependencies: + browserify-aes "^1.0.4" + browserify-des "^1.0.0" + evp_bytestokey "^1.0.0" + +browserify-des@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/browserify-des/-/browserify-des-1.0.2.tgz#3af4f1f59839403572f1c66204375f7a7f703e9c" + integrity sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A== + dependencies: + cipher-base "^1.0.1" + des.js "^1.0.0" + inherits "^2.0.1" + safe-buffer "^5.1.2" + +browserify-rsa@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524" + integrity sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ= + dependencies: + bn.js "^4.1.0" + randombytes "^2.0.1" + +browserify-shim@^3.8.0: + version "3.8.14" + resolved "https://registry.yarnpkg.com/browserify-shim/-/browserify-shim-3.8.14.tgz#bf1057026932d3253c75ef7dd714f3b877edec6b" + integrity sha1-vxBXAmky0yU8de991xTzuHft7Gs= + dependencies: + exposify "~0.5.0" + mothership "~0.2.0" + rename-function-calls "~0.1.0" + resolve "~0.6.1" + through "~2.3.4" + +browserify-sign@^4.0.0: + version "4.0.4" + resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.0.4.tgz#aa4eb68e5d7b658baa6bf6a57e630cbd7a93d298" + integrity sha1-qk62jl17ZYuqa/alfmMMvXqT0pg= + dependencies: + bn.js "^4.1.1" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.2" + elliptic "^6.0.0" + inherits "^2.0.1" + parse-asn1 "^5.0.0" + +browserify-zlib@~0.1.2: + version "0.1.4" + resolved "https://registry.yarnpkg.com/browserify-zlib/-/browserify-zlib-0.1.4.tgz#bb35f8a519f600e0fa6b8485241c979d0141fb2d" + integrity sha1-uzX4pRn2AOD6a4SFJByXnQFB+y0= + dependencies: + pako "~0.2.0" + +browserify@^6.3.2: + version "6.3.4" + resolved "https://registry.yarnpkg.com/browserify/-/browserify-6.3.4.tgz#57b5d195cc568139e971302e5cd9d58ddafb54d8" + integrity sha1-V7XRlcxWgTnpcTAuXNnVjdr7VNg= + dependencies: + JSONStream "~0.8.3" + assert "~1.1.0" + browser-pack "^3.2.0" + browser-resolve "^1.3.0" + browserify-zlib "~0.1.2" + buffer "^2.3.0" + builtins "~0.0.3" + commondir "0.0.1" + concat-stream "~1.4.1" + console-browserify "^1.1.0" + constants-browserify "~0.0.1" + crypto-browserify "^3.0.0" + deep-equal "~0.2.1" + defined "~0.0.0" + deps-sort "^1.3.5" + domain-browser "~1.1.0" + duplexer2 "~0.0.2" + events "~1.0.0" + glob "^4.0.5" + http-browserify "^1.4.0" + https-browserify "~0.0.0" + inherits "~2.0.1" + insert-module-globals "^6.1.0" + isarray "0.0.1" + labeled-stream-splicer "^1.0.0" + module-deps "^3.5.0" + os-browserify "~0.1.1" + parents "~0.0.1" + path-browserify "~0.0.0" + process "^0.8.0" + punycode "~1.2.3" + querystring-es3 "~0.2.0" + readable-stream "^1.0.33-1" + resolve "~0.7.1" + shallow-copy "0.0.1" + shasum "^1.0.0" + shell-quote "~0.0.1" + stream-browserify "^1.0.0" + string_decoder "~0.10.0" + subarg "^1.0.0" + syntax-error "^1.1.1" + through2 "^1.0.0" + timers-browserify "^1.0.1" + tty-browserify "~0.0.0" + umd "~2.1.0" + url "~0.10.1" + util "~0.10.1" + vm-browserify "~0.0.1" + xtend "^3.0.0" + +buffer-alloc-unsafe@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0" + integrity sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg== + +buffer-alloc@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/buffer-alloc/-/buffer-alloc-1.2.0.tgz#890dd90d923a873e08e10e5fd51a57e5b7cce0ec" + integrity sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow== + dependencies: + buffer-alloc-unsafe "^1.1.0" + buffer-fill "^1.0.0" + +buffer-equal-constant-time@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk= + +buffer-fill@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" + integrity sha1-+PeLdniYiO858gXNY39o5wISKyw= + +buffer-xor@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" + integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk= + +buffer@^2.3.0: + version "2.8.2" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-2.8.2.tgz#d73c214c0334384dc29b04ee0ff5f5527c7974e7" + integrity sha1-1zwhTAM0OE3CmwTuD/X1Unx5dOc= + dependencies: + base64-js "0.0.7" + ieee754 "^1.1.4" + is-array "^1.0.1" + +builtin-modules@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" + integrity sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8= + +builtins@~0.0.3: + version "0.0.7" + resolved "https://registry.yarnpkg.com/builtins/-/builtins-0.0.7.tgz#355219cd6cf18dbe7c01cc7fd2dce765cfdc549a" + integrity sha1-NVIZzWzxjb58Acx/0tznZc/cVJo= + +bytes@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" + integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg= + +cache-base@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" + integrity sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ== + dependencies: + collection-visit "^1.0.0" + component-emitter "^1.2.1" + get-value "^2.0.6" + has-value "^1.0.0" + isobject "^3.0.1" + set-value "^2.0.0" + to-object-path "^0.3.0" + union-value "^1.0.0" + unset-value "^1.0.0" + +callsite@1.0.0, callsite@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" + integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA= + +camelcase@^1.0.2: + version "1.2.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" + integrity sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk= + +capture-stack-trace@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d" + integrity sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw== + +chai-as-promised@^5.1.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-5.3.0.tgz#09d7a402908aa70dfdbead53e5853fc79d3ef21c" + integrity sha1-CdekApCKpw39vq1T5YU/x50+8hw= + +chai-dom@^1.2.2: + version "1.8.1" + resolved "https://registry.yarnpkg.com/chai-dom/-/chai-dom-1.8.1.tgz#ce7978ac93d623314742aeb6ada86c9e4d8736de" + integrity sha512-ysWinPU3fc+Bp+xMn/u2/PQyk65jnnCZl0alWupUuFFMGaG+KxrUnsoYOgjMDhSKPkm3WqE/5RTnOowIb7asMg== + +chai-jquery@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/chai-jquery/-/chai-jquery-2.1.0.tgz#ce40fb5d853e7886688787f16d14cd9595388563" + integrity sha512-DiKSXcmInlt4d+WC5PkisDL5MsgJPd1lCSfZ3NgeSZJ34CJntEIpPOCdpalH2IhOWHeLpESJaiuHFxX1dpZ6bw== + +chai-things@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/chai-things/-/chai-things-0.2.0.tgz#c55128378f9bb399e994f00052151984ed6ebe70" + integrity sha1-xVEoN4+bs5nplPAAUhUZhO1uvnA= + +chai@^3.4.1: + version "3.5.0" + resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247" + integrity sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc= + dependencies: + assertion-error "^1.0.1" + deep-eql "^0.1.3" + type-detect "^1.0.0" + +"charenc@>= 0.0.1": + version "0.0.2" + resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" + integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc= + +chokidar@^1.4.1: + version "1.7.0" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468" + integrity sha1-eY5ol3gVHIB2tLNg5e3SjNortGg= + dependencies: + anymatch "^1.3.0" + async-each "^1.0.0" + glob-parent "^2.0.0" + inherits "^2.0.1" + is-binary-path "^1.0.0" + is-glob "^2.0.0" + path-is-absolute "^1.0.0" + readdirp "^2.0.0" + optionalDependencies: + fsevents "^1.0.0" + +chownr@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494" + integrity sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g== + +cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.4.tgz#8760e4ecc272f4c363532f926d874aae2c1397de" + integrity sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q== + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +class-utils@^0.3.5: + version "0.3.6" + resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" + integrity sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg== + dependencies: + arr-union "^3.1.0" + define-property "^0.2.5" + isobject "^3.0.0" + static-extend "^0.1.1" + +code-point-at@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" + integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= + +collection-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0" + integrity sha1-S8A3PBZLwykbTTaMgpzxqApZ3KA= + dependencies: + map-visit "^1.0.0" + object-visit "^1.0.0" + +colors@^1.1.0, colors@^1.1.2: + version "1.3.3" + resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d" + integrity sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg== + +combine-lists@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/combine-lists/-/combine-lists-1.0.1.tgz#458c07e09e0d900fc28b70a3fec2dacd1d2cb7f6" + integrity sha1-RYwH4J4NkA/Ci3Cj/sLazR0st/Y= + dependencies: + lodash "^4.5.0" + +combine-source-map@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/combine-source-map/-/combine-source-map-0.3.0.tgz#d9e74f593d9cd43807312cb5d846d451efaa9eb7" + integrity sha1-2edPWT2c1DgHMSy12EbUUe+qnrc= + dependencies: + convert-source-map "~0.3.0" + inline-source-map "~0.3.0" + source-map "~0.1.31" + +combine-source-map@~0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/combine-source-map/-/combine-source-map-0.6.1.tgz#9b4a09c316033d768e0f11e029fa2730e079ad96" + integrity sha1-m0oJwxYDPXaODxHgKfonMOB5rZY= + dependencies: + convert-source-map "~1.1.0" + inline-source-map "~0.5.0" + lodash.memoize "~3.0.3" + source-map "~0.4.2" + +commondir@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/commondir/-/commondir-0.0.1.tgz#89f00fdcd51b519c578733fec563e6a6da7f5be2" + integrity sha1-ifAP3NUbUZxXhzP+xWPmptp/W+I= + +component-bind@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" + integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E= + +component-emitter@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.1.2.tgz#296594f2753daa63996d2af08d15a95116c9aec3" + integrity sha1-KWWU8nU9qmOZbSrwjRWpURbJrsM= + +component-emitter@1.2.1, component-emitter@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" + integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY= + +component-inherit@0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" + integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM= + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +concat-stream@~1.4.1, concat-stream@~1.4.5: + version "1.4.11" + resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.4.11.tgz#1dc9f666f2621da9c618b1e7f8f3b2ff70b5f76f" + integrity sha512-X3JMh8+4je3U1cQpG87+f9lXHDrqcb2MVLg9L7o8b1UZ0DzhRrUpdn65ttzu10PpJPPI3MQNkis+oha6TSA9Mw== + dependencies: + inherits "~2.0.1" + readable-stream "~1.1.9" + typedarray "~0.0.5" + +connect@^3.6.0: + version "3.6.6" + resolved "https://registry.yarnpkg.com/connect/-/connect-3.6.6.tgz#09eff6c55af7236e137135a72574858b6786f524" + integrity sha1-Ce/2xVr3I24TcTWnJXSFi2eG9SQ= + dependencies: + debug "2.6.9" + finalhandler "1.1.0" + parseurl "~1.3.2" + utils-merge "1.0.1" + +console-browserify@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" + integrity sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA= + dependencies: + date-now "^0.1.4" + +console-control-strings@^1.0.0, console-control-strings@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" + integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= + +constants-browserify@~0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-0.0.1.tgz#92577db527ba6c4cf0a4568d84bc031f441e21f2" + integrity sha1-kld9tSe6bEzwpFaNhLwDH0QeIfI= + +content-type@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" + integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== + +convert-source-map@~0.3.0: + version "0.3.5" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-0.3.5.tgz#f1d802950af7dd2631a1febe0596550c86ab3190" + integrity sha1-8dgClQr33SYxof6+BZZVDIarMZA= + +convert-source-map@~1.1.0: + version "1.1.3" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.1.3.tgz#4829c877e9fe49b3161f3bf3673888e204699860" + integrity sha1-SCnId+n+SbMWHzvzZziI4gRpmGA= + +cookie@0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" + integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s= + +copy-descriptor@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" + integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= + +core-js@^2.2.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.3.tgz#4b70938bdffdaf64931e66e2db158f0892289c49" + integrity sha512-l00tmFFZOBHtYhN4Cz7k32VM7vTn3rE2ANjQDxdEN6zmXZ/xq1jQuutnmHvMG1ZJ7xd72+TA5YpUK8wz3rWsfQ== + +core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= + +create-ecdh@^4.0.0: + version "4.0.3" + resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff" + integrity sha512-GbEHQPMOswGpKXM9kCWVrremUcBmjteUaQ01T9rkKCPDXfUHX0IoP9LpHYo2NPFampa4e+/pFDc3jQdxrxQLaw== + dependencies: + bn.js "^4.1.0" + elliptic "^6.0.0" + +create-error-class@^3.0.1: + version "3.0.2" + resolved "https://registry.yarnpkg.com/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6" + integrity sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y= + dependencies: + capture-stack-trace "^1.0.0" + +create-hash@^1.1.0, create-hash@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.2.0.tgz#889078af11a63756bcfb59bd221996be3a9ef196" + integrity sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg== + dependencies: + cipher-base "^1.0.1" + inherits "^2.0.1" + md5.js "^1.3.4" + ripemd160 "^2.0.1" + sha.js "^2.4.0" + +create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: + version "1.1.7" + resolved "https://registry.yarnpkg.com/create-hmac/-/create-hmac-1.1.7.tgz#69170c78b3ab957147b2b8b04572e47ead2243ff" + integrity sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg== + dependencies: + cipher-base "^1.0.3" + create-hash "^1.1.0" + inherits "^2.0.1" + ripemd160 "^2.0.0" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +"crypt@>= 0.0.1": + version "0.0.2" + resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" + integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs= + +crypto-browserify@^3.0.0: + version "3.12.0" + resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec" + integrity sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg== + dependencies: + browserify-cipher "^1.0.0" + browserify-sign "^4.0.0" + create-ecdh "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.0" + diffie-hellman "^5.0.0" + inherits "^2.0.1" + pbkdf2 "^3.0.3" + public-encrypt "^4.0.0" + randombytes "^2.0.0" + randomfill "^1.0.3" + +custom-event@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/custom-event/-/custom-event-1.0.1.tgz#5d02a46850adf1b4a317946a3928fccb5bfd0425" + integrity sha1-XQKkaFCt8bSjF5RqOSj8y1v9BCU= + +date-now@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" + integrity sha1-6vQ5/U1ISK105cx9vvIAZyueNFs= + +debug@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" + integrity sha1-+HBX6ZWxofauaklgZkE3vFbwOdo= + dependencies: + ms "0.7.1" + +debug@2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.3.3.tgz#40c453e67e6e13c901ddec317af8986cda9eff8c" + integrity sha1-QMRT5n5uE8kB3ewxeviYbNqe/4w= + dependencies: + ms "0.7.2" + +debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +debug@=3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + +decamelize@^1.0.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA= + +decode-uri-component@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" + integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= + +deep-eql@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" + integrity sha1-71WKyrjeJSBs1xOQbXTlaTDrafI= + dependencies: + type-detect "0.1.1" + +deep-equal@~0.2.1: + version "0.2.2" + resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-0.2.2.tgz#84b745896f34c684e98f2ce0e42abaf43bba017d" + integrity sha1-hLdFiW80xoTpjyzg5Cq69Du6AX0= + +deep-extend@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== + +deffy@^2.2.1, deffy@^2.2.2: + version "2.2.3" + resolved "https://registry.yarnpkg.com/deffy/-/deffy-2.2.3.tgz#16671c969a8fc447c76dd6bb0d265dd2d1b9c361" + integrity sha512-c5JD8Z6V1aBWVzn1+aELL97R1pHCwEjXeU3hZXdigkZkxb9vhgFP162kAxGXl992TtAg0btwQyx7d54CqcQaXQ== + dependencies: + typpy "^2.0.0" + +define-property@^0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116" + integrity sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY= + dependencies: + is-descriptor "^0.1.0" + +define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-1.0.0.tgz#769ebaaf3f4a63aad3af9e8d304c9bbe79bfb0e6" + integrity sha1-dp66rz9KY6rTr56NMEybvnm/sOY= + dependencies: + is-descriptor "^1.0.0" + +define-property@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/define-property/-/define-property-2.0.2.tgz#d459689e8d654ba77e02a817f8710d702cb16e9d" + integrity sha512-jwK2UV4cnPpbcG7+VRARKTZPUWowwXA8bzH5NP6ud0oeAxyYPuGZUAC7hMugpCdz4BeSZl2Dl9k66CHJ/46ZYQ== + dependencies: + is-descriptor "^1.0.2" + isobject "^3.0.1" + +defined@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" + integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM= + +defined@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/defined/-/defined-0.0.0.tgz#f35eea7d705e933baf13b2f03b3f83d921403b3e" + integrity sha1-817qfXBekzuvE7LwOz+D2SFAOz4= + +delegates@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" + integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= + +depd@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= + +deps-sort@^1.3.5: + version "1.3.9" + resolved "https://registry.yarnpkg.com/deps-sort/-/deps-sort-1.3.9.tgz#29dfff53e17b36aecae7530adbbbf622c2ed1a71" + integrity sha1-Kd//U+F7Nq7K51MK27v2IsLtGnE= + dependencies: + JSONStream "^1.0.3" + shasum "^1.0.0" + subarg "^1.0.0" + through2 "^1.0.0" + +des.js@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc" + integrity sha1-wHTS4qpqipoH29YfmhXCzYPsjsw= + dependencies: + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +detect-libc@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" + integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= + +detective@^4.0.0, detective@^4.5.0: + version "4.7.1" + resolved "https://registry.yarnpkg.com/detective/-/detective-4.7.1.tgz#0eca7314338442febb6d65da54c10bb1c82b246e" + integrity sha512-H6PmeeUcZloWtdt4DAkFyzFL94arpHr3NOwwmVILFiy+9Qd4JTxxXrzfyGk/lmct2qVGBwTSwSXagqu2BxmWig== + dependencies: + acorn "^5.2.1" + defined "^1.0.0" + +detective@~3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/detective/-/detective-3.1.0.tgz#77782444ab752b88ca1be2e9d0a0395f1da25eed" + integrity sha1-d3gkRKt1K4jKG+Lp0KA5Xx2iXu0= + dependencies: + escodegen "~1.1.0" + esprima-fb "3001.1.0-dev-harmony-fb" + +di@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/di/-/di-0.0.1.tgz#806649326ceaa7caa3306d75d985ea2748ba913c" + integrity sha1-gGZJMmzqp8qjMG112YXqJ0i6kTw= + +diff@^3.1.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== + +diffie-hellman@^5.0.0: + version "5.0.3" + resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875" + integrity sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg== + dependencies: + bn.js "^4.1.0" + miller-rabin "^4.0.0" + randombytes "^2.0.0" + +dom-serialize@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/dom-serialize/-/dom-serialize-2.2.1.tgz#562ae8999f44be5ea3076f5419dcd59eb43ac95b" + integrity sha1-ViromZ9Evl6jB29UGdzVnrQ6yVs= + dependencies: + custom-event "~1.0.0" + ent "~2.2.0" + extend "^3.0.0" + void-elements "^2.0.0" + +dom-storage@^2.0.2: + version "2.1.0" + resolved "https://registry.yarnpkg.com/dom-storage/-/dom-storage-2.1.0.tgz#00fb868bc9201357ea243c7bcfd3304c1e34ea39" + integrity sha512-g6RpyWXzl0RR6OTElHKBl7nwnK87GUyZMYC7JWsB/IA73vpqK2K6LT39x4VepLxlSsWBFrPVLnsSR5Jyty0+2Q== + +domain-browser@~1.1.0: + version "1.1.7" + resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" + integrity sha1-hnqksJP6oF8d4IwG9NeyH9+GmLw= + +dot-parts@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/dot-parts/-/dot-parts-1.0.1.tgz#884bd7bcfc3082ffad2fe5db53e494d8f3e0743f" + integrity sha1-iEvXvPwwgv+tL+XbU+SU2PPgdD8= + +duplexer2@0.0.2, duplexer2@~0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.0.2.tgz#c614dcf67e2fb14995a91711e5a617e8a60a31db" + integrity sha1-xhTc9n4vsUmVqRcR5aYX6KYKMds= + dependencies: + readable-stream "~1.1.9" + +duplexer2@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1" + integrity sha1-ixLauHjA1p4+eJEFFmKjL8a93ME= + dependencies: + readable-stream "^2.0.2" + +ecdsa-sig-formatter@1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz#1c595000f04a8897dfb85000892a0f4c33af86c3" + integrity sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM= + dependencies: + safe-buffer "^5.0.1" + +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= + +elliptic@^6.0.0: + version "6.4.1" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.1.tgz#c2d0b7776911b86722c632c3c06c60f2f819939a" + integrity sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ== + dependencies: + bn.js "^4.4.0" + brorand "^1.0.1" + hash.js "^1.0.0" + hmac-drbg "^1.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.0" + +encodeurl@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= + +engine.io-client@1.8.3: + version "1.8.3" + resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-1.8.3.tgz#1798ed93451246453d4c6f635d7a201fe940d5ab" + integrity sha1-F5jtk0USRkU9TG9jXXogH+lA1as= + dependencies: + component-emitter "1.2.1" + component-inherit "0.0.3" + debug "2.3.3" + engine.io-parser "1.3.2" + has-cors "1.1.0" + indexof "0.0.1" + parsejson "0.0.3" + parseqs "0.0.5" + parseuri "0.0.5" + ws "1.1.2" + xmlhttprequest-ssl "1.5.3" + yeast "0.1.2" + +engine.io-parser@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-1.3.2.tgz#937b079f0007d0893ec56d46cb220b8cb435220a" + integrity sha1-k3sHnwAH0Ik+xW1GyyILjLQ1Igo= + dependencies: + after "0.8.2" + arraybuffer.slice "0.0.6" + base64-arraybuffer "0.1.5" + blob "0.0.4" + has-binary "0.1.7" + wtf-8 "1.0.0" + +engine.io@1.8.3: + version "1.8.3" + resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-1.8.3.tgz#8de7f97895d20d39b85f88eeee777b2bd42b13d4" + integrity sha1-jef5eJXSDTm4X4ju7nd7K9QrE9Q= + dependencies: + accepts "1.3.3" + base64id "1.0.0" + cookie "0.3.1" + debug "2.3.3" + engine.io-parser "1.3.2" + ws "1.1.2" + +ent@~2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/ent/-/ent-2.2.0.tgz#e964219325a21d05f44466a2f686ed6ce5f5dd1d" + integrity sha1-6WQhkyWiHQX0RGai9obtbOX13R0= + +err@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/err/-/err-1.1.1.tgz#eb928e2e11a316648f782833d0f97258ba43c2f8" + integrity sha1-65KOLhGjFmSPeCgz0PlyWLpDwvg= + dependencies: + typpy "^2.2.0" + +error-ex@^1.2.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" + integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g== + dependencies: + is-arrayish "^0.2.1" + +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= + +escape-string-regexp@^1.0.3: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= + +escodegen@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.1.0.tgz#c663923f6e20aad48d0c0fa49f31c6d4f49360cf" + integrity sha1-xmOSP24gqtSNDA+knzHG1PSTYM8= + dependencies: + esprima "~1.0.4" + estraverse "~1.5.0" + esutils "~1.0.0" + optionalDependencies: + source-map "~0.1.30" + +esprima-fb@3001.1.0-dev-harmony-fb: + version "3001.1.0-dev-harmony-fb" + resolved "https://registry.yarnpkg.com/esprima-fb/-/esprima-fb-3001.0001.0000-dev-harmony-fb.tgz#b77d37abcd38ea0b77426bb8bc2922ce6b426411" + integrity sha1-t303q8046gt3Qmu4vCkizmtCZBE= + +esprima@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-1.0.4.tgz#9f557e08fc3b4d26ece9dd34f8fbf476b62585ad" + integrity sha1-n1V+CPw7TSbs6d00+Pv0drYlha0= + +estraverse@~1.5.0: + version "1.5.1" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.5.1.tgz#867a3e8e58a9f84618afb6c2ddbcd916b7cbaf71" + integrity sha1-hno+jlip+EYYr7bC3bzZFrfLr3E= + +esutils@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-1.0.0.tgz#8151d358e20c8acc7fb745e7472c0025fe496570" + integrity sha1-gVHTWOIMisx/t0XnRywAJf5JZXA= + +eventemitter3@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" + integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA== + +events@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/events/-/events-1.0.2.tgz#75849dcfe93d10fb057c30055afdbd51d06a8e24" + integrity sha1-dYSdz+k9EPsFfDAFWv29UdBqjiQ= + +evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz#7fcbdb198dc71959432efe13842684e0525acb02" + integrity sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA== + dependencies: + md5.js "^1.3.4" + safe-buffer "^5.1.1" + +exec-limiter@^3.0.0: + version "3.2.12" + resolved "https://registry.yarnpkg.com/exec-limiter/-/exec-limiter-3.2.12.tgz#8957ee926ee1f3b5a0954325408aef8561aecb50" + integrity sha512-2Bj2X3UmPQHIPtYkDW5epEHn1aTtGxP30x8Be6IzXzQzyuavlOdKI4wT56iEt9UUfvI421AHAHHnV+lBIvCcVA== + dependencies: + limit-it "^3.0.0" + typpy "^2.1.0" + +exit@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" + integrity sha1-BjJjj42HfMghB9MKD/8aF8uhzQw= + +expand-braces@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/expand-braces/-/expand-braces-0.1.2.tgz#488b1d1d2451cb3d3a6b192cfc030f44c5855fea" + integrity sha1-SIsdHSRRyz06axks/AMPRMWFX+o= + dependencies: + array-slice "^0.2.3" + array-unique "^0.2.1" + braces "^0.1.2" + +expand-brackets@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b" + integrity sha1-3wcoTjQqgHzXM6xa9yQR5YHRF3s= + dependencies: + is-posix-bracket "^0.1.0" + +expand-brackets@^2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622" + integrity sha1-t3c14xXOMPa27/D4OwQVGiJEliI= + dependencies: + debug "^2.3.3" + define-property "^0.2.5" + extend-shallow "^2.0.1" + posix-character-classes "^0.1.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +expand-range@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/expand-range/-/expand-range-0.1.1.tgz#4cb8eda0993ca56fa4f41fc42f3cbb4ccadff044" + integrity sha1-TLjtoJk8pW+k9B/ELzy7TMrf8EQ= + dependencies: + is-number "^0.1.1" + repeat-string "^0.2.2" + +expand-range@^1.8.1: + version "1.8.2" + resolved "https://registry.yarnpkg.com/expand-range/-/expand-range-1.8.2.tgz#a299effd335fe2721ebae8e257ec79644fc85337" + integrity sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc= + dependencies: + fill-range "^2.1.0" + +exposify@~0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/exposify/-/exposify-0.5.0.tgz#f92d0094c265b3f553e1fa456a03a1883d1059cc" + integrity sha1-+S0AlMJls/VT4fpFagOhiD0QWcw= + dependencies: + globo "~1.1.0" + map-obj "~1.0.1" + replace-requires "~1.0.3" + through2 "~0.4.0" + transformify "~0.1.1" + +extend-shallow@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" + integrity sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8= + dependencies: + is-extendable "^0.1.0" + +extend-shallow@^3.0.0, extend-shallow@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-3.0.2.tgz#26a71aaf073b39fb2127172746131c2704028db8" + integrity sha1-Jqcarwc7OfshJxcnRhMcJwQCjbg= + dependencies: + assign-symbols "^1.0.0" + is-extendable "^1.0.1" + +extend@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" + integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== + +extglob@^0.3.1: + version "0.3.2" + resolved "https://registry.yarnpkg.com/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1" + integrity sha1-Lhj/PS9JqydlzskCPwEdqo2DSaE= + dependencies: + is-extglob "^1.0.0" + +extglob@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/extglob/-/extglob-2.0.4.tgz#ad00fe4dc612a9232e8718711dc5cb5ab0285543" + integrity sha512-Nmb6QXkELsuBr24CJSkilo6UHHgbekK5UiZgfE6UHD3Eb27YC6oD+bhcT+tJ6cl8dmsgdQxnWlcry8ksBIBLpw== + dependencies: + array-unique "^0.3.2" + define-property "^1.0.0" + expand-brackets "^2.1.4" + extend-shallow "^2.0.1" + fragment-cache "^0.2.1" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +faye-websocket@0.9.3: + version "0.9.3" + resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.9.3.tgz#482a505b0df0ae626b969866d3bd740cdb962e83" + integrity sha1-SCpQWw3wrmJrlphm0710DNuWLoM= + dependencies: + websocket-driver ">=0.5.1" + +filename-regex@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" + integrity sha1-wcS5vuPglyXdsQa3XB4wH+LxiyY= + +fill-range@^2.1.0: + version "2.2.4" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.4.tgz#eb1e773abb056dcd8df2bfdf6af59b8b3a936565" + integrity sha512-cnrcCbj01+j2gTG921VZPnHbjmdAf8oQV/iGeV2kZxGSyfYjjTyY79ErsK1WJWMpw6DaApEX72binqJE+/d+5Q== + dependencies: + is-number "^2.1.0" + isobject "^2.0.0" + randomatic "^3.0.0" + repeat-element "^1.1.2" + repeat-string "^1.5.2" + +fill-range@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" + integrity sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc= + dependencies: + extend-shallow "^2.0.1" + is-number "^3.0.0" + repeat-string "^1.6.1" + to-regex-range "^2.1.0" + +finalhandler@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.0.tgz#ce0b6855b45853e791b2fcc680046d88253dd7f5" + integrity sha1-zgtoVbRYU+eRsvzGgARtiCU91/U= + dependencies: + debug "2.6.9" + encodeurl "~1.0.1" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.2" + statuses "~1.3.1" + unpipe "~1.0.0" + +find-parent-dir@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54" + integrity sha1-M8RLQpqysvBkYpnF+fcY83b/jVQ= + +firebase-auto-ids@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/firebase-auto-ids/-/firebase-auto-ids-1.1.0.tgz#378ffb8590888c37eb2dd8b704659ad0f49f9061" + integrity sha1-N4/7hZCIjDfrLdi3BGWa0PSfkGE= + +firebase@3.x.x: + version "3.9.0" + resolved "https://registry.yarnpkg.com/firebase/-/firebase-3.9.0.tgz#c4237f50f58eeb25081b1839d6cbf175f8f7ed9b" + integrity sha1-xCN/UPWO6yUIGxg51svxdfj37Zs= + dependencies: + dom-storage "^2.0.2" + faye-websocket "0.9.3" + jsonwebtoken "^7.3.0" + promise-polyfill "^6.0.2" + xmlhttprequest "^1.8.0" + +follow-redirects@^1.0.0: + version "1.6.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.6.1.tgz#514973c44b5757368bad8bddfe52f81f015c94cb" + integrity sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ== + dependencies: + debug "=3.1.0" + +for-in@^1.0.1, for-in@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" + integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA= + +for-own@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.5.tgz#5265c681a4f294dabbf17c9509b6763aa84510ce" + integrity sha1-UmXGgaTylNq78XyVCbZ2OqhFEM4= + dependencies: + for-in "^1.0.1" + +formatio@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.2.0.tgz#f3b2167d9068c4698a8d51f4f760a39a54d818eb" + integrity sha1-87IWfZBoxGmKjVH092CjmlTYGOs= + dependencies: + samsam "1.x" + +fragment-cache@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19" + integrity sha1-QpD60n8T6Jvn8zeZxrxaCr//DRk= + dependencies: + map-cache "^0.2.2" + +fs-access@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/fs-access/-/fs-access-1.0.1.tgz#d6a87f262271cefebec30c553407fb995da8777a" + integrity sha1-1qh/JiJxzv6+wwxVNAf7mV2od3o= + dependencies: + null-check "^1.0.0" + +fs-minipass@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d" + integrity sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ== + dependencies: + minipass "^2.2.1" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +fsevents@^1.0.0: + version "1.2.7" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.7.tgz#4851b664a3783e52003b3c66eb0eee1074933aa4" + integrity sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw== + dependencies: + nan "^2.9.2" + node-pre-gyp "^0.10.0" + +function.name@^1.0.3: + version "1.0.12" + resolved "https://registry.yarnpkg.com/function.name/-/function.name-1.0.12.tgz#34eec84476d9fb67977924a4cdcb98ec85695726" + integrity sha512-C7Tu+rAFrWW5RjXqtKtXp2xOdCujq+4i8ZH3w0uz/xrYHBwXZrPt96x8cDAEHrIjeyEv/Jm6iDGyqupbaVQTlw== + dependencies: + noop6 "^1.0.1" + +gauge@~2.7.3: + version "2.7.4" + resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" + integrity sha1-LANAXHU4w51+s3sxcCLjJfsBi/c= + dependencies: + aproba "^1.0.3" + console-control-strings "^1.0.0" + has-unicode "^2.0.0" + object-assign "^4.1.0" + signal-exit "^3.0.0" + string-width "^1.0.1" + strip-ansi "^3.0.1" + wide-align "^1.1.0" + +get-value@^2.0.3, get-value@^2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" + integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg= + +git-package-json@^1.4.0: + version "1.4.9" + resolved "https://registry.yarnpkg.com/git-package-json/-/git-package-json-1.4.9.tgz#5386d9e62e97d8b9390fd4d4000872516e3b3552" + integrity sha512-F88a40RBqCS6S7layrE4LIhX5TIVYyUJRYxZjAPPLfCZu9zf0R5B3l3wIY8A7hFb3xAU6Df/AHVMoBQ9SaR1Jw== + dependencies: + deffy "^2.2.1" + err "^1.1.1" + gry "^5.0.0" + normalize-package-data "^2.3.5" + oargv "^3.4.1" + one-by-one "^3.1.0" + r-json "^1.2.1" + r-package-json "^1.0.0" + tmp "0.0.28" + +git-source@^1.1.0: + version "1.1.9" + resolved "https://registry.yarnpkg.com/git-source/-/git-source-1.1.9.tgz#c5a0aeb2e2be31a2dcacc856eb3c92b77baa3d87" + integrity sha512-LRWKxFrt1lIrEAdRMrCk9sGbEYQdf3TwDe9pEwR8DMau+2dljQjqqwITJqhYIbA0TkFaxatOXzLhBWW89ZMO7w== + dependencies: + git-url-parse "^5.0.1" + +git-up@^1.0.0: + version "1.2.1" + resolved "https://registry.yarnpkg.com/git-up/-/git-up-1.2.1.tgz#264480a006b1d84261ac1fe09a3a5169c57ea19d" + integrity sha1-JkSAoAax2EJhrB/gmjpRacV+oZ0= + dependencies: + is-ssh "^1.0.0" + parse-url "^1.0.0" + +git-url-parse@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-5.0.1.tgz#fe3d79c6746ae05048cfa508c81e79dddbba3843" + integrity sha1-/j15xnRq4FBIz6UIyB553du6OEM= + dependencies: + git-up "^1.0.0" + +glob-base@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" + integrity sha1-27Fk9iIbHAscz4Kuoyi0l98Oo8Q= + dependencies: + glob-parent "^2.0.0" + is-glob "^2.0.0" + +glob-parent@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-2.0.0.tgz#81383d72db054fcccf5336daa902f182f6edbb28" + integrity sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg= + dependencies: + is-glob "^2.0.0" + +glob@^4.0.5: + version "4.5.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f" + integrity sha1-xstz0yJsHv7wTePFbQEvAzd+4V8= + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "^2.0.1" + once "^1.3.0" + +glob@^7.0.6, glob@^7.1.1, glob@^7.1.3: + version "7.1.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" + integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +globo@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/globo/-/globo-1.1.0.tgz#0d26098955dea422eb2001b104898b0a101caaf3" + integrity sha1-DSYJiVXepCLrIAGxBImLChAcqvM= + dependencies: + accessory "~1.1.0" + is-defined "~1.0.0" + ternary "~1.0.0" + +got@^5.0.0: + version "5.7.1" + resolved "https://registry.yarnpkg.com/got/-/got-5.7.1.tgz#5f81635a61e4a6589f180569ea4e381680a51f35" + integrity sha1-X4FjWmHkplifGAVp6k44FoClHzU= + dependencies: + create-error-class "^3.0.1" + duplexer2 "^0.1.4" + is-redirect "^1.0.0" + is-retry-allowed "^1.0.0" + is-stream "^1.0.0" + lowercase-keys "^1.0.0" + node-status-codes "^1.0.0" + object-assign "^4.0.1" + parse-json "^2.1.0" + pinkie-promise "^2.0.0" + read-all-stream "^3.0.0" + readable-stream "^2.0.5" + timed-out "^3.0.0" + unzip-response "^1.0.2" + url-parse-lax "^1.0.0" + +graceful-fs@^4.1.11, graceful-fs@^4.1.2: + version "4.1.15" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" + integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA== + +gry@^5.0.0: + version "5.0.8" + resolved "https://registry.yarnpkg.com/gry/-/gry-5.0.8.tgz#73c0d246fba4ce6e7924779670088a7d67222e7a" + integrity sha512-meq9ZjYVpLzZh3ojhTg7IMad9grGsx6rUUKHLqPnhLXzJkRQvEL2U3tQpS5/WentYTtHtxkT3Ew/mb10D6F6/g== + dependencies: + abs "^1.2.1" + exec-limiter "^3.0.0" + one-by-one "^3.0.0" + ul "^5.0.0" + +has-binary@0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/has-binary/-/has-binary-0.1.7.tgz#68e61eb16210c9545a0a5cce06a873912fe1e68c" + integrity sha1-aOYesWIQyVRaClzOBqhzkS/h5ow= + dependencies: + isarray "0.0.1" + +has-cors@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" + integrity sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk= + +has-require@~1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/has-require/-/has-require-1.2.2.tgz#921675ab130dbd9768fc8da8f1a8e242dfa41774" + integrity sha1-khZ1qxMNvZdo/I2o8ajiQt+kF3Q= + dependencies: + escape-string-regexp "^1.0.3" + +has-unicode@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" + integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= + +has-value@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" + integrity sha1-ex9YutpiyoJ+wKIHgCVlSEWZXh8= + dependencies: + get-value "^2.0.3" + has-values "^0.1.4" + isobject "^2.0.0" + +has-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-value/-/has-value-1.0.0.tgz#18b281da585b1c5c51def24c930ed29a0be6b177" + integrity sha1-GLKB2lhbHFxR3vJMkw7SmgvmsXc= + dependencies: + get-value "^2.0.6" + has-values "^1.0.0" + isobject "^3.0.0" + +has-values@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/has-values/-/has-values-0.1.4.tgz#6d61de95d91dfca9b9a02089ad384bff8f62b771" + integrity sha1-bWHeldkd/Km5oCCJrThL/49it3E= + +has-values@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-values/-/has-values-1.0.0.tgz#95b0b63fec2146619a6fe57fe75628d5a39efe4f" + integrity sha1-lbC2P+whRmGab+V/51Yo1aOe/k8= + dependencies: + is-number "^3.0.0" + kind-of "^4.0.0" + +hash-base@^3.0.0: + version "3.0.4" + resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.0.4.tgz#5fc8686847ecd73499403319a6b0a3f3f6ae4918" + integrity sha1-X8hoaEfs1zSZQDMZprCj8/auSRg= + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +hash.js@^1.0.0, hash.js@^1.0.3: + version "1.1.7" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" + integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA== + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.1" + +hmac-drbg@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" + integrity sha1-0nRXAQJabHdabFRXk+1QL8DGSaE= + dependencies: + hash.js "^1.0.3" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.1" + +hoek@2.x.x: + version "2.16.3" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" + integrity sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0= + +hosted-git-info@^2.1.4: + version "2.7.1" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" + integrity sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w== + +http-browserify@^1.4.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/http-browserify/-/http-browserify-1.7.0.tgz#33795ade72df88acfbfd36773cefeda764735b20" + integrity sha1-M3la3nLfiKz7/TZ3PO/tp2RzWyA= + dependencies: + Base64 "~0.2.0" + inherits "~2.0.1" + +http-errors@1.6.3, http-errors@~1.6.3: + version "1.6.3" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d" + integrity sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0= + dependencies: + depd "~1.1.2" + inherits "2.0.3" + setprototypeof "1.1.0" + statuses ">= 1.4.0 < 2" + +http-parser-js@>=0.4.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.0.tgz#d65edbede84349d0dc30320815a15d39cc3cbbd8" + integrity sha512-cZdEF7r4gfRIq7ezX9J0T+kQmJNOub71dWbgAXVHDct80TKP4MCETtZQ31xyv38UwgzkWPYF/Xc0ge55dW9Z9w== + +http-proxy@^1.13.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a" + integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g== + dependencies: + eventemitter3 "^3.0.0" + follow-redirects "^1.0.0" + requires-port "^1.0.0" + +https-browserify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82" + integrity sha1-P5E2XKvmC3ftDruiS0VOPgnZWoI= + +iconv-lite@0.4.23: + version "0.4.23" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" + integrity sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +iconv-lite@^0.4.4: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +ieee754@^1.1.4: + version "1.1.12" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.12.tgz#50bf24e5b9c8bb98af4964c941cdb0918da7b60b" + integrity sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA== + +ignore-walk@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8" + integrity sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ== + dependencies: + minimatch "^3.0.4" + +indexof@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" + integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= + +inherits@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" + integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE= + +ini@~1.3.0: + version "1.3.5" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" + integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + +inline-source-map@~0.3.0: + version "0.3.1" + resolved "https://registry.yarnpkg.com/inline-source-map/-/inline-source-map-0.3.1.tgz#a528b514e689fce90db3089e870d92f527acb5eb" + integrity sha1-pSi1FOaJ/OkNswiehw2S9Sestes= + dependencies: + source-map "~0.3.0" + +inline-source-map@~0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/inline-source-map/-/inline-source-map-0.5.0.tgz#4a4c5dd8e4fb5e9b3cda60c822dfadcaee66e0af" + integrity sha1-Skxd2OT7Xps82mDIIt+tyu5m4K8= + dependencies: + source-map "~0.4.0" + +insert-module-globals@^6.1.0: + version "6.6.3" + resolved "https://registry.yarnpkg.com/insert-module-globals/-/insert-module-globals-6.6.3.tgz#20638e29a30f9ed1ca2e3a825fbc2cba5246ddfc" + integrity sha1-IGOOKaMPntHKLjqCX7wsulJG3fw= + dependencies: + JSONStream "^1.0.3" + combine-source-map "~0.6.1" + concat-stream "~1.4.1" + is-buffer "^1.1.0" + lexical-scope "^1.2.0" + process "~0.11.0" + through2 "^1.0.0" + xtend "^4.0.0" + +is-accessor-descriptor@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6" + integrity sha1-qeEss66Nh2cn7u84Q/igiXtcmNY= + dependencies: + kind-of "^3.0.2" + +is-accessor-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz#169c2f6d3df1f992618072365c9b0ea1f6878656" + integrity sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ== + dependencies: + kind-of "^6.0.0" + +is-array@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-array/-/is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a" + integrity sha1-6YUMwsyGDDvAl36EzPDdRkWEJ5o= + +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= + +is-binary-path@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" + integrity sha1-dfFmQrSA8YenEcgUFh/TpKdlWJg= + dependencies: + binary-extensions "^1.0.0" + +is-buffer@^1.1.0, is-buffer@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" + integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== + +is-builtin-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" + integrity sha1-VAVy0096wxGfj3bDDLwbHgN6/74= + dependencies: + builtin-modules "^1.0.0" + +is-data-descriptor@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" + integrity sha1-C17mSDiOLIYCgueT8YVv7D8wG1Y= + dependencies: + kind-of "^3.0.2" + +is-data-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz#d84876321d0e7add03990406abbbbd36ba9268c7" + integrity sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ== + dependencies: + kind-of "^6.0.0" + +is-defined@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-defined/-/is-defined-1.0.0.tgz#1f07ca67d571f594c4b14415a45f7bef88f92bf5" + integrity sha1-HwfKZ9Vx9ZTEsUQVpF9774j5K/U= + +is-descriptor@^0.1.0: + version "0.1.6" + resolved "https://registry.yarnpkg.com/is-descriptor/-/is-descriptor-0.1.6.tgz#366d8240dde487ca51823b1ab9f07a10a78251ca" + integrity sha512-avDYr0SB3DwO9zsMov0gKCESFYqCnE4hq/4z3TdUlukEy5t9C0YRq7HLrsN52NAcqXKaepeCD0n+B0arnVG3Hg== + dependencies: + is-accessor-descriptor "^0.1.6" + is-data-descriptor "^0.1.4" + kind-of "^5.0.0" + +is-descriptor@^1.0.0, is-descriptor@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-descriptor/-/is-descriptor-1.0.2.tgz#3b159746a66604b04f8c81524ba365c5f14d86ec" + integrity sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg== + dependencies: + is-accessor-descriptor "^1.0.0" + is-data-descriptor "^1.0.0" + kind-of "^6.0.2" + +is-dotfile@^1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1" + integrity sha1-pqLzL/0t+wT1yiXs0Pa4PPeYoeE= + +is-equal-shallow@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz#2238098fc221de0bcfa5d9eac4c45d638aa1c534" + integrity sha1-IjgJj8Ih3gvPpdnqxMRdY4qhxTQ= + dependencies: + is-primitive "^2.0.0" + +is-extendable@^0.1.0, is-extendable@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" + integrity sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik= + +is-extendable@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-1.0.1.tgz#a7470f9e426733d81bd81e1155264e3a3507cab4" + integrity sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA== + dependencies: + is-plain-object "^2.0.4" + +is-extglob@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0" + integrity sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA= + +is-fullwidth-code-point@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb" + integrity sha1-754xOG8DGn8NZDr4L95QxFfvAMs= + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= + +is-glob@^2.0.0, is-glob@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863" + integrity sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM= + dependencies: + is-extglob "^1.0.0" + +is-number@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-0.1.1.tgz#69a7af116963d47206ec9bd9b48a14216f1e3806" + integrity sha1-aaevEWlj1HIG7JvZtIoUIW8eOAY= + +is-number@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" + integrity sha1-Afy7s5NGOlSPL0ZszhbezknbkI8= + dependencies: + kind-of "^3.0.2" + +is-number@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" + integrity sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU= + dependencies: + kind-of "^3.0.2" + +is-number@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-4.0.0.tgz#0026e37f5454d73e356dfe6564699867c6a7f0ff" + integrity sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ== + +is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677" + integrity sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og== + dependencies: + isobject "^3.0.1" + +is-posix-bracket@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" + integrity sha1-MzTceXdDaOkvAW5vvAqI9c1ua8Q= + +is-primitive@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" + integrity sha1-IHurkWOEmcB7Kt8kCkGochADRXU= + +is-redirect@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24" + integrity sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ= + +is-retry-allowed@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34" + integrity sha1-EaBgVotnM5REAz0BJaYaINVk+zQ= + +is-ssh@^1.0.0, is-ssh@^1.3.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.1.tgz#f349a8cadd24e65298037a522cf7520f2e81a0f3" + integrity sha512-0eRIASHZt1E68/ixClI8bp2YK2wmBPVWEismTs6M+M099jKgrzl/3E976zIbImSIob48N2/XGe9y7ZiYdImSlg== + dependencies: + protocols "^1.1.0" + +is-stream@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" + integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= + +is-windows@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== + +isarray@0.0.1, isarray@~0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + +isarray@1.0.0, isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= + +isbinaryfile@^3.0.0: + version "3.0.3" + resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-3.0.3.tgz#5d6def3edebf6e8ca8cae9c30183a804b5f8be80" + integrity sha512-8cJBL5tTd2OS0dM4jz07wQd5g0dCCqIhUxPIGtZfa5L6hWlvV5MHTITy/DBAsF+Oe2LS1X3krBUhNwaGUWpWxw== + dependencies: + buffer-alloc "^1.2.0" + +isemail@1.x.x: + version "1.2.0" + resolved "https://registry.yarnpkg.com/isemail/-/isemail-1.2.0.tgz#be03df8cc3e29de4d2c5df6501263f1fa4595e9a" + integrity sha1-vgPfjMPineTSxd9lASY/H6RZXpo= + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +isobject@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" + integrity sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk= + dependencies: + isarray "1.0.0" + +isobject@^3.0.0, isobject@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" + integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8= + +iterate-object@^1.1.0: + version "1.3.3" + resolved "https://registry.yarnpkg.com/iterate-object/-/iterate-object-1.3.3.tgz#c58e60f7f0caefa2d382027a484b215988a7a296" + integrity sha512-DximWbkke36cnrSfNJv6bgcB2QOMV9PRD2FiowwzCoMsh8RupFLdbNIzWe+cVDWT+NIMNJgGlB1dGxP6kpzGtA== + +jasmine-core@~2.99.0: + version "2.99.1" + resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.99.1.tgz#e6400df1e6b56e130b61c4bcd093daa7f6e8ca15" + integrity sha1-5kAN8ea1bhMLYcS80JPap/boyhU= + +jasmine@2.99.0: + version "2.99.0" + resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-2.99.0.tgz#8ca72d102e639b867c6489856e0e18a9c7aa42b7" + integrity sha1-jKctEC5jm4Z8ZImFbg4YqceqQrc= + dependencies: + exit "^0.1.2" + glob "^7.0.6" + jasmine-core "~2.99.0" + +joi@^6.10.1: + version "6.10.1" + resolved "https://registry.yarnpkg.com/joi/-/joi-6.10.1.tgz#4d50c318079122000fe5f16af1ff8e1917b77e06" + integrity sha1-TVDDGAeRIgAP5fFq8f+OGRe3fgY= + dependencies: + hoek "2.x.x" + isemail "1.x.x" + moment "2.x.x" + topo "1.x.x" + +json-stable-stringify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45" + integrity sha1-YRwj6BTbN1Un34URk9tZ3Sryf0U= + dependencies: + jsonify "~0.0.0" + +json3@3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" + integrity sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE= + +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM= + +jsonparse@0.0.5: + version "0.0.5" + resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-0.0.5.tgz#330542ad3f0a654665b778f3eb2d9a9fa507ac64" + integrity sha1-MwVCrT8KZUZlt3jz6y2an6UHrGQ= + +jsonparse@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" + integrity sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA= + +jsonwebtoken@^7.3.0: + version "7.4.3" + resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz#77f5021de058b605a1783fa1283e99812e645638" + integrity sha1-d/UCHeBYtgWheD+hKD6ZgS5kVjg= + dependencies: + joi "^6.10.1" + jws "^3.1.4" + lodash.once "^4.0.0" + ms "^2.0.0" + xtend "^4.0.1" + +jwa@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.2.0.tgz#606da70c1c6d425cad329c77c99f2df2a981489a" + integrity sha512-Grku9ZST5NNQ3hqNUodSkDfEBqAmGA1R8yiyPHOnLzEKI0GaCQC/XhFmsheXYuXzFQJdILbh+lYBiliqG5R/Vg== + dependencies: + buffer-equal-constant-time "1.0.1" + ecdsa-sig-formatter "1.0.10" + safe-buffer "^5.0.1" + +jws@^3.1.4: + version "3.2.1" + resolved "https://registry.yarnpkg.com/jws/-/jws-3.2.1.tgz#d79d4216a62c9afa0a3d5e8b5356d75abdeb2be5" + integrity sha512-bGA2omSrFUkd72dhh05bIAN832znP4wOU3lfuXtRBuGTbsmNmDXMQg28f0Vsxaxgk4myF5YkKQpz6qeRpMgX9g== + dependencies: + jwa "^1.2.0" + safe-buffer "^5.0.1" + +karma-chai-plugins@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/karma-chai-plugins/-/karma-chai-plugins-0.9.0.tgz#b2a1a7e807f0b1bb19fb66c4744963ba5c31aa7d" + integrity sha1-sqGn6AfwsbsZ+2bEdEljulwxqn0= + dependencies: + chai "^3.4.1" + chai-as-promised "^5.1.0" + chai-dom "^1.2.2" + chai-jquery "^2.0.0" + chai-things "^0.2.0" + sinon "^2.1.0" + sinon-chai "^2.8.0" + +karma-chrome-launcher@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz#cf1b9d07136cc18fe239327d24654c3dbc368acf" + integrity sha512-uf/ZVpAabDBPvdPdveyk1EPgbnloPvFFGgmRhYLTDH7gEB4nZdSBk8yTU47w1g/drLSx5uMOkjKk7IWKfWg/+w== + dependencies: + fs-access "^1.0.0" + which "^1.2.1" + +karma-firefox-launcher@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/karma-firefox-launcher/-/karma-firefox-launcher-1.1.0.tgz#2c47030452f04531eb7d13d4fc7669630bb93339" + integrity sha512-LbZ5/XlIXLeQ3cqnCbYLn+rOVhuMIK9aZwlP6eOLGzWdo1UVp7t6CN3DP4SafiRLjexKwHeKHDm0c38Mtd3VxA== + +karma-jasmine-html-reporter@0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/karma-jasmine-html-reporter/-/karma-jasmine-html-reporter-0.2.2.tgz#48a8e5ef18807617ee2b5e33c1194c35b439524c" + integrity sha1-SKjl7xiAdhfuK14zwRlMNbQ5Ukw= + dependencies: + karma-jasmine "^1.0.2" + +karma-jasmine@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/karma-jasmine/-/karma-jasmine-1.1.0.tgz#22e4c06bf9a182e5294d1f705e3733811b810acf" + integrity sha1-IuTAa/mhguUpTR9wXjczgRuBCs8= + +karma-jasmine@^1.0.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/karma-jasmine/-/karma-jasmine-1.1.2.tgz#394f2b25ffb4a644b9ada6f22d443e2fd08886c3" + integrity sha1-OU8rJf+0pkS5rabyLUQ+L9CIhsM= + +karma-spec-reporter@0.0.31: + version "0.0.31" + resolved "https://registry.yarnpkg.com/karma-spec-reporter/-/karma-spec-reporter-0.0.31.tgz#4830dc7148a155c7d7a186e632339a0d80fadec3" + integrity sha1-SDDccUihVcfXoYbmMjOaDYD63sM= + dependencies: + colors "^1.1.2" + +karma@^1.7.0: + version "1.7.1" + resolved "https://registry.yarnpkg.com/karma/-/karma-1.7.1.tgz#85cc08e9e0a22d7ce9cca37c4a1be824f6a2b1ae" + integrity sha512-k5pBjHDhmkdaUccnC7gE3mBzZjcxyxYsYVaqiL2G5AqlfLyBO5nw2VdNK+O16cveEPd/gIOWULH7gkiYYwVNHg== + dependencies: + bluebird "^3.3.0" + body-parser "^1.16.1" + chokidar "^1.4.1" + colors "^1.1.0" + combine-lists "^1.0.0" + connect "^3.6.0" + core-js "^2.2.0" + di "^0.0.1" + dom-serialize "^2.2.0" + expand-braces "^0.1.1" + glob "^7.1.1" + graceful-fs "^4.1.2" + http-proxy "^1.13.0" + isbinaryfile "^3.0.0" + lodash "^3.8.0" + log4js "^0.6.31" + mime "^1.3.4" + minimatch "^3.0.2" + optimist "^0.6.1" + qjobs "^1.1.4" + range-parser "^1.2.0" + rimraf "^2.6.0" + safe-buffer "^5.0.1" + socket.io "1.7.3" + source-map "^0.5.3" + tmp "0.0.31" + useragent "^2.1.12" + +kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" + integrity sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ= + dependencies: + is-buffer "^1.1.5" + +kind-of@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-4.0.0.tgz#20813df3d712928b207378691a45066fae72dd57" + integrity sha1-IIE989cSkosgc3hpGkUGb65y3Vc= + dependencies: + is-buffer "^1.1.5" + +kind-of@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d" + integrity sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw== + +kind-of@^6.0.0, kind-of@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" + integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA== + +labeled-stream-splicer@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/labeled-stream-splicer/-/labeled-stream-splicer-1.0.2.tgz#4615331537784981e8fd264e1f3a434c4e0ddd65" + integrity sha1-RhUzFTd4SYHo/SZOHzpDTE4N3WU= + dependencies: + inherits "^2.0.1" + isarray "~0.0.1" + stream-splicer "^1.1.0" + +lexical-scope@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/lexical-scope/-/lexical-scope-1.2.0.tgz#fcea5edc704a4b3a8796cdca419c3a0afaf22df4" + integrity sha1-/Ope3HBKSzqHls3KQZw6CvryLfQ= + dependencies: + astw "^2.0.0" + +limit-it@^3.0.0: + version "3.2.9" + resolved "https://registry.yarnpkg.com/limit-it/-/limit-it-3.2.9.tgz#bf4bb2fb435217c512a7177791b4bdf8a855f282" + integrity sha512-3cAf+D47VdMrrzLpV3wIyEHoAACc7FonHMz+I8onocXdnWD2zBeicse851NZ9TUeCEyuBM35Cx82mpdx1WLm2A== + dependencies: + typpy "^2.0.0" + +lodash.memoize@~3.0.3: + version "3.0.4" + resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-3.0.4.tgz#2dcbd2c287cbc0a55cc42328bd0c736150d53e3f" + integrity sha1-LcvSwofLwKVcxCMovQxzYVDVPj8= + +lodash.once@^4.0.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" + integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= + +lodash@^3.8.0: + version "3.10.1" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" + integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y= + +lodash@^4.17.4, lodash@^4.5.0: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== + +lodash@~2.4.1: + version "2.4.2" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-2.4.2.tgz#fadd834b9683073da179b3eae6d9c0d15053f73e" + integrity sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4= + +log4js@^0.6.31: + version "0.6.38" + resolved "https://registry.yarnpkg.com/log4js/-/log4js-0.6.38.tgz#2c494116695d6fb25480943d3fc872e662a522fd" + integrity sha1-LElBFmldb7JUgJQ9P8hy5mKlIv0= + dependencies: + readable-stream "~1.0.2" + semver "~4.3.3" + +lolex@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.6.0.tgz#3a9a0283452a47d7439e72731b9e07d7386e49f6" + integrity sha1-OpoCg0UqR9dDnnJzG54H1zhuSfY= + +lowercase-keys@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" + integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA== + +lru-cache@4.1.x: + version "4.1.5" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" + integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== + dependencies: + pseudomap "^1.0.2" + yallist "^2.1.2" + +map-cache@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" + integrity sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8= + +map-obj@~1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d" + integrity sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0= + +map-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" + integrity sha1-7Nyo8TFE5mDxtb1B8S80edmN+48= + dependencies: + object-visit "^1.0.0" + +math-random@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.4.tgz#5dd6943c938548267016d4e34f057583080c514c" + integrity sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A== + +md5.js@^1.3.4: + version "1.3.5" + resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" + integrity sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg== + dependencies: + hash-base "^3.0.0" + inherits "^2.0.1" + safe-buffer "^5.1.2" + +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= + +micromatch@^2.1.5: + version "2.3.11" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" + integrity sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU= + dependencies: + arr-diff "^2.0.0" + array-unique "^0.2.1" + braces "^1.8.2" + expand-brackets "^0.1.4" + extglob "^0.3.1" + filename-regex "^2.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.1" + kind-of "^3.0.2" + normalize-path "^2.0.1" + object.omit "^2.0.0" + parse-glob "^3.0.4" + regex-cache "^0.4.2" + +micromatch@^3.1.10: + version "3.1.10" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" + integrity sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg== + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + braces "^2.3.1" + define-property "^2.0.2" + extend-shallow "^3.0.2" + extglob "^2.0.4" + fragment-cache "^0.2.1" + kind-of "^6.0.2" + nanomatch "^1.2.9" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.2" + +miller-rabin@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d" + integrity sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA== + dependencies: + bn.js "^4.0.0" + brorand "^1.0.1" + +mime-db@~1.37.0: + version "1.37.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.37.0.tgz#0b6a0ce6fdbe9576e25f1f2d2fde8830dc0ad0d8" + integrity sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg== + +mime-types@~2.1.11, mime-types@~2.1.18: + version "2.1.21" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.21.tgz#28995aa1ecb770742fe6ae7e58f9181c744b3f96" + integrity sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg== + dependencies: + mime-db "~1.37.0" + +mime@^1.3.4: + version "1.6.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== + +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" + integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== + +minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" + integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= + +minimatch@^2.0.1: + version "2.0.10" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-2.0.10.tgz#8d087c39c6b38c001b97fca7ce6d0e1e80afbac7" + integrity sha1-jQh8OcazjAAbl/ynzm0OHoCvusc= + dependencies: + brace-expansion "^1.0.0" + +minimatch@^3.0.2, minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= + +minimist@^1.1.0, minimist@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= + +minimist@~0.0.1: + version "0.0.10" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" + integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8= + +minipass@^2.2.1, minipass@^2.3.4: + version "2.3.5" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.5.tgz#cacebe492022497f656b0f0f51e2682a9ed2d848" + integrity sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA== + dependencies: + safe-buffer "^5.1.2" + yallist "^3.0.0" + +minizlib@^1.1.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.2.1.tgz#dd27ea6136243c7c880684e8672bb3a45fd9b614" + integrity sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA== + dependencies: + minipass "^2.2.1" + +mixin-deep@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" + integrity sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ== + dependencies: + for-in "^1.0.2" + is-extendable "^1.0.1" + +mkdirp@^0.5.0, mkdirp@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= + dependencies: + minimist "0.0.8" + +mockfirebase@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/mockfirebase/-/mockfirebase-0.12.0.tgz#7212ced74587f62253687b065371eaaa05567e1b" + integrity sha1-chLO10WH9iJTaHsGU3HqqgVWfhs= + dependencies: + MD5 "~1.2.1" + browserify "^6.3.2" + browserify-shim "^3.8.0" + firebase-auto-ids "~1.1.0" + lodash "~2.4.1" + +module-deps@^3.5.0: + version "3.9.1" + resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-3.9.1.tgz#ea75caf9199090d25b0d5512b5acacb96e7f87f3" + integrity sha1-6nXK+RmQkNJbDVUStaysuW5/h/M= + dependencies: + JSONStream "^1.0.3" + browser-resolve "^1.7.0" + concat-stream "~1.4.5" + defined "^1.0.0" + detective "^4.0.0" + duplexer2 "0.0.2" + inherits "^2.0.1" + parents "^1.0.0" + readable-stream "^1.1.13" + resolve "^1.1.3" + stream-combiner2 "~1.0.0" + subarg "^1.0.0" + through2 "^1.0.0" + xtend "^4.0.0" + +moment@2.x.x: + version "2.24.0" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" + integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg== + +mothership@~0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/mothership/-/mothership-0.2.0.tgz#93d48a2fbc3e50e2a5fc8ed586f5bc44c65f9a99" + integrity sha1-k9SKL7w+UOKl/I7VhvW8RMZfmpk= + dependencies: + find-parent-dir "~0.3.0" + +ms@0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" + integrity sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg= + +ms@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" + integrity sha1-riXPJRKziFodldfwN4aNhDESR2U= + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +ms@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" + integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== + +nan@^2.9.2: + version "2.12.1" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552" + integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw== + +nanomatch@^1.2.9: + version "1.2.13" + resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" + integrity sha512-fpoe2T0RbHwBTBUOftAfBPaDEi06ufaUai0mE6Yn1kacc3SnTErfb/h+X94VXzI64rKFHYImXSvdwGGCmwOqCA== + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + define-property "^2.0.2" + extend-shallow "^3.0.2" + fragment-cache "^0.2.1" + is-windows "^1.0.2" + kind-of "^6.0.2" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +native-promise-only@^0.8.1: + version "0.8.1" + resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11" + integrity sha1-IKMYwwy0X3H+et+/eyHJnBRy7xE= + +needle@^2.2.1: + version "2.2.4" + resolved "https://registry.yarnpkg.com/needle/-/needle-2.2.4.tgz#51931bff82533b1928b7d1d69e01f1b00ffd2a4e" + integrity sha512-HyoqEb4wr/rsoaIDfTH2aVL9nWtQqba2/HvMv+++m8u0dz808MaagKILxtfeSN7QU7nvbQ79zk3vYOJp9zsNEA== + dependencies: + debug "^2.1.2" + iconv-lite "^0.4.4" + sax "^1.2.4" + +negotiator@0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" + integrity sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk= + +node-pre-gyp@^0.10.0: + version "0.10.3" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" + integrity sha512-d1xFs+C/IPS8Id0qPTZ4bUT8wWryfR/OzzAFxweG+uLN85oPzyo2Iw6bVlLQ/JOdgNonXLCoRyqDzDWq4iw72A== + dependencies: + detect-libc "^1.0.2" + mkdirp "^0.5.1" + needle "^2.2.1" + nopt "^4.0.1" + npm-packlist "^1.1.6" + npmlog "^4.0.2" + rc "^1.2.7" + rimraf "^2.6.1" + semver "^5.3.0" + tar "^4" + +node-status-codes@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f" + integrity sha1-WuVUHQJGRdMqWPzdyc7s6nrjrC8= + +noop6@^1.0.1: + version "1.0.8" + resolved "https://registry.yarnpkg.com/noop6/-/noop6-1.0.8.tgz#eff06e2e5b3621e9e5618f389d6a2294f76e64ad" + integrity sha512-+Al5csMVc40I8xRfJsyBcN1IbpyvebOuQmMfxdw+AL6ECELey12ANgNTRhMfTwNIDU4W9W0g8EHLcsb3+3qPFA== + +nopt@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d" + integrity sha1-0NRoWv1UFRk8jHUFYC0NF81kR00= + dependencies: + abbrev "1" + osenv "^0.1.4" + +normalize-package-data@^2.3.5: + version "2.4.2" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.2.tgz#6b2abd85774e51f7936f1395e45acb905dc849b2" + integrity sha512-YcMnjqeoUckXTPKZSAsPjUPLxH85XotbpqK3w4RyCwdFQSU5FxxBys8buehkSfg0j9fKvV1hn7O0+8reEgkAiw== + dependencies: + hosted-git-info "^2.1.4" + is-builtin-module "^1.0.0" + semver "2 || 3 || 4 || 5" + validate-npm-package-license "^3.0.1" + +normalize-path@^2.0.0, normalize-path@^2.0.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" + integrity sha1-GrKLVW4Zg2Oowab35vogE3/mrtk= + dependencies: + remove-trailing-separator "^1.0.1" + +npm-bundled@^1.0.1: + version "1.0.5" + resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979" + integrity sha512-m/e6jgWu8/v5niCUKQi9qQl8QdeEduFA96xHDDzFGqly0OOjI7c+60KM/2sppfnUU9JJagf+zs+yGhqSOFj71g== + +npm-packlist@^1.1.6: + version "1.2.0" + resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.2.0.tgz#55a60e793e272f00862c7089274439a4cc31fc7f" + integrity sha512-7Mni4Z8Xkx0/oegoqlcao/JpPCPEMtUvsmB0q7mgvlMinykJLSRTYuFqoQLYgGY8biuxIeiHO+QNJKbCfljewQ== + dependencies: + ignore-walk "^3.0.1" + npm-bundled "^1.0.1" + +npmlog@^4.0.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" + integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg== + dependencies: + are-we-there-yet "~1.1.2" + console-control-strings "~1.1.0" + gauge "~2.7.3" + set-blocking "~2.0.0" + +null-check@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd" + integrity sha1-l33/1xdgErnsMNKjnbXPcqBDnt0= + +number-is-nan@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" + integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= + +oargv@^3.4.1: + version "3.4.9" + resolved "https://registry.yarnpkg.com/oargv/-/oargv-3.4.9.tgz#f49d09473ef74d14530b2bc0977d88018014e207" + integrity sha512-24Eatdf7OGezTAU0Yw3HaoO9x+GTFnmBkuFHfWEQtVsIKbD7VMHhyIlDMtxxUxfZKPBPHYsTo8UgGwKr4ySewA== + dependencies: + iterate-object "^1.1.0" + ul "^5.0.0" + +obj-def@^1.0.0: + version "1.0.7" + resolved "https://registry.yarnpkg.com/obj-def/-/obj-def-1.0.7.tgz#6ceb66fc4664dc260b7777d06173066573850661" + integrity sha512-ahx1PnGDpovRglgczxsKtoYhPhrhYEG1rs3WklAHMTk29DyStqsrGDVISOIGZLF+ewK4m5CFZNuZXIXRQwZUMg== + dependencies: + deffy "^2.2.2" + +object-assign@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" + integrity sha1-ejs9DpgGPUP0wD8uiubNUahog6A= + +object-assign@^4.0.1, object-assign@^4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= + +object-component@0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" + integrity sha1-8MaapQ78lbhmwYb0AKM3acsvEpE= + +object-copy@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" + integrity sha1-fn2Fi3gb18mRpBupde04EnVOmYw= + dependencies: + copy-descriptor "^0.1.0" + define-property "^0.2.5" + kind-of "^3.0.3" + +object-keys@~0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-0.4.0.tgz#28a6aae7428dd2c3a92f3d95f21335dd204e0336" + integrity sha1-KKaq50KN0sOpLz2V8hM13SBOAzY= + +object-visit@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/object-visit/-/object-visit-1.0.1.tgz#f79c4493af0c5377b59fe39d395e41042dd045bb" + integrity sha1-95xEk68MU3e1n+OdOV5BBC3QRbs= + dependencies: + isobject "^3.0.0" + +object.omit@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" + integrity sha1-Gpx0SCnznbuFjHbKNXmuKlTr0fo= + dependencies: + for-own "^0.1.4" + is-extendable "^0.1.1" + +object.pick@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" + integrity sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c= + dependencies: + isobject "^3.0.1" + +on-finished@~2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" + integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc= + dependencies: + ee-first "1.1.1" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +one-by-one@^3.0.0, one-by-one@^3.1.0: + version "3.2.7" + resolved "https://registry.yarnpkg.com/one-by-one/-/one-by-one-3.2.7.tgz#16400cfdeb52cda4ccc7e67361808f1938602150" + integrity sha512-EFE5hyHMGPcesACi1tT6HRmMK23Q74ujX2gjhfGD9qMkz7CxD1AJd5TmBHIEEzuL7h7hKwWh9n9hJ5ClQJnO/Q== + dependencies: + obj-def "^1.0.0" + sliced "^1.0.1" + +optimist@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" + integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY= + dependencies: + minimist "~0.0.1" + wordwrap "~0.0.2" + +optimist@~0.3.5: + version "0.3.7" + resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.3.7.tgz#c90941ad59e4273328923074d2cf2e7cbc6ec0d9" + integrity sha1-yQlBrVnkJzMokjB00s8ufLxuwNk= + dependencies: + wordwrap "~0.0.2" + +options@>=0.0.5: + version "0.0.6" + resolved "https://registry.yarnpkg.com/options/-/options-0.0.6.tgz#ec22d312806bb53e731773e7cdaefcf1c643128f" + integrity sha1-7CLTEoBrtT5zF3Pnza788cZDEo8= + +os-browserify@~0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.1.2.tgz#49ca0293e0b19590a5f5de10c7f265a617d8fe54" + integrity sha1-ScoCk+CxlZCl9d4Qx/JlphfY/lQ= + +os-homedir@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" + integrity sha1-/7xJiDNuDoM94MFox+8VISGqf7M= + +os-tmpdir@^1.0.0, os-tmpdir@~1.0.1, os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + +osenv@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410" + integrity sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g== + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.0" + +package-json-path@^1.0.0: + version "1.0.8" + resolved "https://registry.yarnpkg.com/package-json-path/-/package-json-path-1.0.8.tgz#2ce9ce41843e913df00d4b670fea1084b712b5ed" + integrity sha512-8OCXvm2TmEYoWC7e9AswLC0eoKY3RGbkupbiWa2vaTFaH4vEE3Kr+oeefLVm/7N4me2gYh5SjQYsdwAZLkL87g== + dependencies: + abs "^1.2.1" + +package-json@^2.3.1: + version "2.4.0" + resolved "https://registry.yarnpkg.com/package-json/-/package-json-2.4.0.tgz#0d15bd67d1cbbddbb2ca222ff2edb86bcb31a8bb" + integrity sha1-DRW9Z9HLvduyyiIv8u24a8sxqLs= + dependencies: + got "^5.0.0" + registry-auth-token "^3.0.1" + registry-url "^3.0.3" + semver "^5.1.0" + +package.json@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/package.json/-/package.json-2.0.1.tgz#f886059d2a49ed076e64883695d73b2b46d21d6d" + integrity sha1-+IYFnSpJ7QduZIg2ldc7K0bSHW0= + dependencies: + git-package-json "^1.4.0" + git-source "^1.1.0" + package-json "^2.3.1" + +pako@~0.2.0: + version "0.2.9" + resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" + integrity sha1-8/dSL073gjSNqBYbrZ7P1Rv4OnU= + +parents@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parents/-/parents-1.0.1.tgz#fedd4d2bf193a77745fe71e371d73c3307d9c751" + integrity sha1-/t1NK/GTp3dF/nHjcdc8MwfZx1E= + dependencies: + path-platform "~0.11.15" + +parents@~0.0.1: + version "0.0.3" + resolved "https://registry.yarnpkg.com/parents/-/parents-0.0.3.tgz#fa212f024d9fa6318dbb6b4ce676c8be493b9c43" + integrity sha1-+iEvAk2fpjGNu2tM5nbIvkk7nEM= + dependencies: + path-platform "^0.0.1" + +parse-asn1@^5.0.0: + version "5.1.3" + resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.3.tgz#1600c6cc0727365d68b97f3aa78939e735a75204" + integrity sha512-VrPoetlz7B/FqjBLD2f5wBVZvsZVLnRUrxVLfRYhGXCODa/NWE4p3Wp+6+aV3ZPL3KM7/OZmxDIwwijD7yuucg== + dependencies: + asn1.js "^4.0.0" + browserify-aes "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.0" + pbkdf2 "^3.0.3" + safe-buffer "^5.1.1" + +parse-glob@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c" + integrity sha1-ssN2z7EfNVE7rdFz7wu246OIORw= + dependencies: + glob-base "^0.3.0" + is-dotfile "^1.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.0" + +parse-json@^2.1.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" + integrity sha1-9ID0BDTvgHQfhGkJn43qGPVaTck= + dependencies: + error-ex "^1.2.0" + +parse-url@^1.0.0: + version "1.3.11" + resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-1.3.11.tgz#57c15428ab8a892b1f43869645c711d0e144b554" + integrity sha1-V8FUKKuKiSsfQ4aWRccR0OFEtVQ= + dependencies: + is-ssh "^1.3.0" + protocols "^1.4.0" + +parsejson@0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/parsejson/-/parsejson-0.0.3.tgz#ab7e3759f209ece99437973f7d0f1f64ae0e64ab" + integrity sha1-q343WfIJ7OmUN5c/fQ8fZK4OZKs= + dependencies: + better-assert "~1.0.0" + +parseqs@0.0.5: + version "0.0.5" + resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" + integrity sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0= + dependencies: + better-assert "~1.0.0" + +parseuri@0.0.5: + version "0.0.5" + resolved "https://registry.yarnpkg.com/parseuri/-/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" + integrity sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo= + dependencies: + better-assert "~1.0.0" + +parseurl@~1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3" + integrity sha1-/CidTtiZMRlGDBViUyYs3I3mW/M= + +pascalcase@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" + integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= + +patch-text@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/patch-text/-/patch-text-1.0.2.tgz#4bf36e65e51733d6e98f0cf62e09034daa0348ac" + integrity sha1-S/NuZeUXM9bpjwz2LgkDTaoDSKw= + +path-browserify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" + integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ== + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + +path-platform@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.0.1.tgz#b5585d7c3c463d89aa0060d86611cf1afd617e2a" + integrity sha1-tVhdfDxGPYmqAGDYZhHPGv1hfio= + +path-platform@~0.11.15: + version "0.11.15" + resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2" + integrity sha1-6GQhf3TDaFDwhSt43Hv31KVyG/I= + +path-to-regexp@^1.7.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d" + integrity sha1-Wf3g9DW62suhA6hOnTvGTpa5k30= + dependencies: + isarray "0.0.1" + +pbkdf2@^3.0.3: + version "3.0.17" + resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6" + integrity sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA== + dependencies: + create-hash "^1.1.2" + create-hmac "^1.1.4" + ripemd160 "^2.0.1" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +pinkie-promise@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" + integrity sha1-ITXW36ejWMBprJsXh3YogihFD/o= + dependencies: + pinkie "^2.0.0" + +pinkie@^2.0.0: + version "2.0.4" + resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" + integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA= + +posix-character-classes@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" + integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= + +prepend-http@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" + integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= + +preserve@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" + integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= + +process-nextick-args@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa" + integrity sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw== + +process@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/process/-/process-0.8.0.tgz#7bbaf7187fe6ded3fd5be0cb6103fba9cacb9798" + integrity sha1-e7r3GH/m3tP9W+DLYQP7qcrLl5g= + +process@~0.11.0: + version "0.11.10" + resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" + integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= + +promise-polyfill@^6.0.2: + version "6.1.0" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.1.0.tgz#dfa96943ea9c121fca4de9b5868cb39d3472e057" + integrity sha1-36lpQ+qcEh/KTem1hoyznTRy4Fc= + +protocols@^1.1.0, protocols@^1.4.0: + version "1.4.7" + resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.7.tgz#95f788a4f0e979b291ffefcf5636ad113d037d32" + integrity sha512-Fx65lf9/YDn3hUX08XUc0J8rSux36rEsyiv21ZGUC1mOyeM3lTRpZLcrm8aAolzS4itwVfm7TAPyxC2E5zd6xg== + +pseudomap@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= + +public-encrypt@^4.0.0: + version "4.0.3" + resolved "https://registry.yarnpkg.com/public-encrypt/-/public-encrypt-4.0.3.tgz#4fcc9d77a07e48ba7527e7cbe0de33d0701331e0" + integrity sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q== + dependencies: + bn.js "^4.1.0" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + parse-asn1 "^5.0.0" + randombytes "^2.0.1" + safe-buffer "^5.1.2" + +punycode@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" + integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0= + +punycode@~1.2.3: + version "1.2.4" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.2.4.tgz#54008ac972aec74175def9cba6df7fa9d3918740" + integrity sha1-VACKyXKux0F13vnLpt9/qdORh0A= + +qjobs@^1.1.4: + version "1.2.0" + resolved "https://registry.yarnpkg.com/qjobs/-/qjobs-1.2.0.tgz#c45e9c61800bd087ef88d7e256423bdd49e5d071" + integrity sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg== + +qs@6.5.2: + version "6.5.2" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" + integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== + +querystring-es3@~0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" + integrity sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM= + +querystring@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" + integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA= + +r-json@^1.2.1: + version "1.2.9" + resolved "https://registry.yarnpkg.com/r-json/-/r-json-1.2.9.tgz#0637da3485b0b4492e9ffae85796f8b2f373f600" + integrity sha512-E5u25XBE7PpZmH5XwtthAmNvSLMTygDQMpcPtCTUBdvwPaqgIYJrxlRQJhG55Sgz7uC0Tuyh5nqNrsDT3uiefA== + +r-package-json@^1.0.0: + version "1.0.8" + resolved "https://registry.yarnpkg.com/r-package-json/-/r-package-json-1.0.8.tgz#cdcb1f9994e920a1ede6cc9ce474e839b30794ef" + integrity sha512-y+dKPLBYKcNMY8pNy+m8YLUqeGsEhhOu0wrqfu1yr8yGX+08CzMq2uUV5GSkGA21GcaIyt6lQAiSoD+DFf3/ag== + dependencies: + package-json-path "^1.0.0" + r-json "^1.2.1" + +randomatic@^3.0.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" + integrity sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw== + dependencies: + is-number "^4.0.0" + kind-of "^6.0.0" + math-random "^1.0.1" + +randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: + version "2.0.6" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.6.tgz#d302c522948588848a8d300c932b44c24231da80" + integrity sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A== + dependencies: + safe-buffer "^5.1.0" + +randomfill@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/randomfill/-/randomfill-1.0.4.tgz#c92196fc86ab42be983f1bf31778224931d61458" + integrity sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw== + dependencies: + randombytes "^2.0.5" + safe-buffer "^5.1.0" + +range-parser@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" + integrity sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4= + +raw-body@2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.3.tgz#1b324ece6b5706e153855bc1148c65bb7f6ea0c3" + integrity sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw== + dependencies: + bytes "3.0.0" + http-errors "1.6.3" + iconv-lite "0.4.23" + unpipe "1.0.0" + +rc@^1.0.1, rc@^1.1.6, rc@^1.2.7: + version "1.2.8" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" + integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== + dependencies: + deep-extend "^0.6.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~2.0.1" + +read-all-stream@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/read-all-stream/-/read-all-stream-3.1.0.tgz#35c3e177f2078ef789ee4bfafa4373074eaef4fa" + integrity sha1-NcPhd/IHjveJ7kv6+kNzB06u9Po= + dependencies: + pinkie-promise "^2.0.0" + readable-stream "^2.0.0" + +"readable-stream@>=1.1.13-1 <1.2.0-0", readable-stream@^1.0.27-1, readable-stream@^1.0.33-1, readable-stream@^1.1.13, readable-stream@^1.1.13-1, readable-stream@~1.1.9: + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + integrity sha1-fPTFTvZI44EwhMY23SB54WbAgdk= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +readable-stream@^2.0.0, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6: + version "2.3.6" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" + integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw== + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~2.0.0" + safe-buffer "~5.1.1" + string_decoder "~1.1.1" + util-deprecate "~1.0.1" + +readable-stream@~1.0.17, readable-stream@~1.0.2: + version "1.0.34" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" + integrity sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +readable-wrap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/readable-wrap/-/readable-wrap-1.0.0.tgz#3b5a211c631e12303a54991c806c17e7ae206bff" + integrity sha1-O1ohHGMeEjA6VJkcgGwX564ga/8= + dependencies: + readable-stream "^1.1.13-1" + +readdirp@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.2.1.tgz#0e87622a3325aa33e892285caf8b4e846529a525" + integrity sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ== + dependencies: + graceful-fs "^4.1.11" + micromatch "^3.1.10" + readable-stream "^2.0.2" + +regex-cache@^0.4.2: + version "0.4.4" + resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" + integrity sha512-nVIZwtCjkC9YgvWkpM55B5rBhBYRZhAaJbgcFYXXsHnbZ9UZI9nnVWYZpBlCqv9ho2eZryPnWrZGsOdPwVWXWQ== + dependencies: + is-equal-shallow "^0.1.3" + +regex-not@^1.0.0, regex-not@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" + integrity sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A== + dependencies: + extend-shallow "^3.0.2" + safe-regex "^1.1.0" + +registry-auth-token@^3.0.1: + version "3.3.2" + resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.2.tgz#851fd49038eecb586911115af845260eec983f20" + integrity sha512-JL39c60XlzCVgNrO+qq68FoNb56w/m7JYvGR2jT5iR1xBrUA3Mfx5Twk5rqTThPmQKMWydGmq8oFtDlxfrmxnQ== + dependencies: + rc "^1.1.6" + safe-buffer "^5.0.1" + +registry-url@^3.0.3: + version "3.1.0" + resolved "https://registry.yarnpkg.com/registry-url/-/registry-url-3.1.0.tgz#3d4ef870f73dde1d77f0cf9a381432444e174942" + integrity sha1-PU74cPc93h138M+aOBQyRE4XSUI= + dependencies: + rc "^1.0.1" + +remove-trailing-separator@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" + integrity sha1-wkvOKig62tW8P1jg1IJJuSN52O8= + +rename-function-calls@~0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/rename-function-calls/-/rename-function-calls-0.1.1.tgz#7f83369c007a3007f6abe3033ccf81686a108e01" + integrity sha1-f4M2nAB6MAf2q+MDPM+BaGoQjgE= + dependencies: + detective "~3.1.0" + +repeat-element@^1.1.2: + version "1.1.3" + resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.3.tgz#782e0d825c0c5a3bb39731f84efee6b742e6b1ce" + integrity sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g== + +repeat-string@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-0.2.2.tgz#c7a8d3236068362059a7e4651fc6884e8b1fb4ae" + integrity sha1-x6jTI2BoNiBZp+RlH8aITosftK4= + +repeat-string@^1.5.2, repeat-string@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" + integrity sha1-jcrkcOHIirwtYA//Sndihtp15jc= + +replace-requires@~1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/replace-requires/-/replace-requires-1.0.4.tgz#014b7330b6b9e2557b71043b66fb02660c3bf667" + integrity sha1-AUtzMLa54lV7cQQ7ZvsCZgw79mc= + dependencies: + detective "^4.5.0" + has-require "~1.2.1" + patch-text "~1.0.2" + xtend "~4.0.0" + +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= + +resolve-url@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" + integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= + +resolve@1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" + integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= + +resolve@^1.1.3: + version "1.10.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba" + integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg== + dependencies: + path-parse "^1.0.6" + +resolve@~0.3.0: + version "0.3.1" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-0.3.1.tgz#34c63447c664c70598d1c9b126fc43b2a24310a4" + integrity sha1-NMY0R8ZkxwWY0cmxJvxDsqJDEKQ= + +resolve@~0.6.1: + version "0.6.3" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-0.6.3.tgz#dd957982e7e736debdf53b58a4dd91754575dd46" + integrity sha1-3ZV5gufnNt699TtYpN2RdUV13UY= + +resolve@~0.7.1: + version "0.7.4" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-0.7.4.tgz#395a9ef9e873fbfe12bd14408bd91bb936003d69" + integrity sha1-OVqe+ehz+/4SvRRAi9kbuTYAPWk= + +ret@~0.1.10: + version "0.1.15" + resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" + integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== + +rfile@~1.0, rfile@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/rfile/-/rfile-1.0.0.tgz#59708cf90ca1e74c54c3cfc5c36fdb9810435261" + integrity sha1-WXCM+Qyh50xUw8/Fw2/bmBBDUmE= + dependencies: + callsite "~1.0.0" + resolve "~0.3.0" + +rimraf@^2.6.0, rimraf@^2.6.1: + version "2.6.3" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" + integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== + dependencies: + glob "^7.1.3" + +ripemd160@^2.0.0, ripemd160@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" + integrity sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA== + dependencies: + hash-base "^3.0.0" + inherits "^2.0.1" + +ruglify@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ruglify/-/ruglify-1.0.0.tgz#dc8930e2a9544a274301cc9972574c0d0986b675" + integrity sha1-3Ikw4qlUSidDAcyZcldMDQmGtnU= + dependencies: + rfile "~1.0" + uglify-js "~2.2" + +safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.2" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + +safe-regex@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e" + integrity sha1-QKNmnzsHfR6UPURinhV91IAjvy4= + dependencies: + ret "~0.1.10" + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +samsam@1.x, samsam@^1.1.3: + version "1.3.0" + resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.3.0.tgz#8d1d9350e25622da30de3e44ba692b5221ab7c50" + integrity sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg== + +sax@^1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" + integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== + +"semver@2 || 3 || 4 || 5", semver@^5.1.0, semver@^5.3.0: + version "5.6.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004" + integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg== + +semver@~4.3.3: + version "4.3.6" + resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da" + integrity sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto= + +set-blocking@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" + integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= + +set-value@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/set-value/-/set-value-0.4.3.tgz#7db08f9d3d22dc7f78e53af3c3bf4666ecdfccf1" + integrity sha1-fbCPnT0i3H945Trzw79GZuzfzPE= + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.1" + to-object-path "^0.3.0" + +set-value@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/set-value/-/set-value-2.0.0.tgz#71ae4a88f0feefbbf52d1ea604f3fb315ebb6274" + integrity sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg== + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.3" + split-string "^3.0.1" + +setprototypeof@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656" + integrity sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ== + +sha.js@^2.4.0, sha.js@^2.4.8, sha.js@~2.4.4: + version "2.4.11" + resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.11.tgz#37a5cf0b81ecbc6943de109ba2960d1b26584ae7" + integrity sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ== + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +shallow-copy@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/shallow-copy/-/shallow-copy-0.0.1.tgz#415f42702d73d810330292cc5ee86eae1a11a170" + integrity sha1-QV9CcC1z2BAzApLMXuhurhoRoXA= + +shasum@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/shasum/-/shasum-1.0.2.tgz#e7012310d8f417f4deb5712150e5678b87ae565f" + integrity sha1-5wEjENj0F/TetXEhUOVni4euVl8= + dependencies: + json-stable-stringify "~0.0.0" + sha.js "~2.4.4" + +shell-quote@~0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-0.0.1.tgz#1a41196f3c0333c482323593d6886ecf153dd986" + integrity sha1-GkEZbzwDM8SCMjWT1ohuzxU92YY= + +signal-exit@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= + +sinon-chai@^2.8.0: + version "2.14.0" + resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-2.14.0.tgz#da7dd4cc83cd6a260b67cca0f7a9fdae26a1205d" + integrity sha512-9stIF1utB0ywNHNT7RgiXbdmen8QDCRsrTjw+G9TgKt1Yexjiv8TOWZ6WHsTPz57Yky3DIswZvEqX8fpuHNDtQ== + +sinon@^2.1.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.4.1.tgz#021fd64b54cb77d9d2fb0d43cdedfae7629c3a36" + integrity sha512-vFTrO9Wt0ECffDYIPSP/E5bBugt0UjcBQOfQUMh66xzkyPEnhl/vM2LRZi2ajuTdkH07sA6DzrM6KvdvGIH8xw== + dependencies: + diff "^3.1.0" + formatio "1.2.0" + lolex "^1.6.0" + native-promise-only "^0.8.1" + path-to-regexp "^1.7.0" + samsam "^1.1.3" + text-encoding "0.6.4" + type-detect "^4.0.0" + +sliced@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/sliced/-/sliced-1.0.1.tgz#0b3a662b5d04c3177b1926bea82b03f837a2ef41" + integrity sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E= + +snapdragon-node@^2.0.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" + integrity sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw== + dependencies: + define-property "^1.0.0" + isobject "^3.0.0" + snapdragon-util "^3.0.1" + +snapdragon-util@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/snapdragon-util/-/snapdragon-util-3.0.1.tgz#f956479486f2acd79700693f6f7b805e45ab56e2" + integrity sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ== + dependencies: + kind-of "^3.2.0" + +snapdragon@^0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/snapdragon/-/snapdragon-0.8.2.tgz#64922e7c565b0e14204ba1aa7d6964278d25182d" + integrity sha512-FtyOnWN/wCHTVXOMwvSv26d+ko5vWlIDD6zoUJ7LW8vh+ZBC8QdljveRP+crNrtBwioEUWy/4dMtbBjA4ioNlg== + dependencies: + base "^0.11.1" + debug "^2.2.0" + define-property "^0.2.5" + extend-shallow "^2.0.1" + map-cache "^0.2.2" + source-map "^0.5.6" + source-map-resolve "^0.5.0" + use "^3.1.0" + +socket.io-adapter@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-0.5.0.tgz#cb6d4bb8bec81e1078b99677f9ced0046066bb8b" + integrity sha1-y21LuL7IHhB4uZZ3+c7QBGBmu4s= + dependencies: + debug "2.3.3" + socket.io-parser "2.3.1" + +socket.io-client@1.7.3: + version "1.7.3" + resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-1.7.3.tgz#b30e86aa10d5ef3546601c09cde4765e381da377" + integrity sha1-sw6GqhDV7zVGYBwJzeR2Xjgdo3c= + dependencies: + backo2 "1.0.2" + component-bind "1.0.0" + component-emitter "1.2.1" + debug "2.3.3" + engine.io-client "1.8.3" + has-binary "0.1.7" + indexof "0.0.1" + object-component "0.0.3" + parseuri "0.0.5" + socket.io-parser "2.3.1" + to-array "0.1.4" + +socket.io-parser@2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-2.3.1.tgz#dd532025103ce429697326befd64005fcfe5b4a0" + integrity sha1-3VMgJRA85Clpcya+/WQAX8/ltKA= + dependencies: + component-emitter "1.1.2" + debug "2.2.0" + isarray "0.0.1" + json3 "3.3.2" + +socket.io@1.7.3: + version "1.7.3" + resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-1.7.3.tgz#b8af9caba00949e568e369f1327ea9be9ea2461b" + integrity sha1-uK+cq6AJSeVo42nxMn6pvp6iRhs= + dependencies: + debug "2.3.3" + engine.io "1.8.3" + has-binary "0.1.7" + object-assign "4.1.0" + socket.io-adapter "0.5.0" + socket.io-client "1.7.3" + socket.io-parser "2.3.1" + +source-map-resolve@^0.5.0: + version "0.5.2" + resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.2.tgz#72e2cc34095543e43b2c62b2c4c10d4a9054f259" + integrity sha512-MjqsvNwyz1s0k81Goz/9vRBe9SZdB09Bdw+/zYyO+3CuPk6fouTaxscHkgtE8jKvf01kVfl8riHzERQ/kefaSA== + dependencies: + atob "^2.1.1" + decode-uri-component "^0.2.0" + resolve-url "^0.2.1" + source-map-url "^0.4.0" + urix "^0.1.0" + +source-map-url@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" + integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM= + +source-map@0.1.34: + version "0.1.34" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.1.34.tgz#a7cfe89aec7b1682c3b198d0acfb47d7d090566b" + integrity sha1-p8/omux7FoLDsZjQrPtH19CQVms= + dependencies: + amdefine ">=0.0.4" + +source-map@^0.5.3, source-map@^0.5.6: + version "0.5.7" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" + integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= + +source-map@~0.1.30, source-map@~0.1.31, source-map@~0.1.7: + version "0.1.43" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346" + integrity sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y= + dependencies: + amdefine ">=0.0.4" + +source-map@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.3.0.tgz#8586fb9a5a005e5b501e21cd18b6f21b457ad1f9" + integrity sha1-hYb7mloAXltQHiHNGLbyG0V60fk= + dependencies: + amdefine ">=0.0.4" + +source-map@~0.4.0, source-map@~0.4.2: + version "0.4.4" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" + integrity sha1-66T12pwNyZneaAMti092FzZSA2s= + dependencies: + amdefine ">=0.0.4" + +spdx-correct@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.0.tgz#fb83e504445268f154b074e218c87c003cd31df4" + integrity sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q== + dependencies: + spdx-expression-parse "^3.0.0" + spdx-license-ids "^3.0.0" + +spdx-exceptions@^2.1.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz#2ea450aee74f2a89bfb94519c07fcd6f41322977" + integrity sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA== + +spdx-expression-parse@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz#99e119b7a5da00e05491c9fa338b7904823b41d0" + integrity sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg== + dependencies: + spdx-exceptions "^2.1.0" + spdx-license-ids "^3.0.0" + +spdx-license-ids@^3.0.0: + version "3.0.3" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz#81c0ce8f21474756148bbb5f3bfc0f36bf15d76e" + integrity sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g== + +split-string@^3.0.1, split-string@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" + integrity sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw== + dependencies: + extend-shallow "^3.0.0" + +static-extend@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" + integrity sha1-YICcOcv/VTNyJv1eC1IPNB8ftcY= + dependencies: + define-property "^0.2.5" + object-copy "^0.1.0" + +"statuses@>= 1.4.0 < 2": + version "1.5.0" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" + integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= + +statuses@~1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" + integrity sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4= + +stream-browserify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-1.0.0.tgz#bf9b4abfb42b274d751479e44e0ff2656b6f1193" + integrity sha1-v5tKv7QrJ011FHnkTg/yZWtvEZM= + dependencies: + inherits "~2.0.1" + readable-stream "^1.0.27-1" + +stream-combiner2@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/stream-combiner2/-/stream-combiner2-1.0.2.tgz#ba72a6b50cbfabfa950fc8bc87604bd01eb60671" + integrity sha1-unKmtQy/q/qVD8i8h2BL0B62BnE= + dependencies: + duplexer2 "~0.0.2" + through2 "~0.5.1" + +stream-splicer@^1.1.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/stream-splicer/-/stream-splicer-1.3.2.tgz#3c0441be15b9bf4e226275e6dc83964745546661" + integrity sha1-PARBvhW5v04iYnXm3IOWR0VUZmE= + dependencies: + indexof "0.0.1" + inherits "^2.0.1" + isarray "~0.0.1" + readable-stream "^1.1.13-1" + readable-wrap "^1.0.0" + through2 "^1.0.0" + +string-width@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + integrity sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M= + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +"string-width@^1.0.2 || 2": + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + +string_decoder@~0.10.0, string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= + +string_decoder@~1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" + integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg== + dependencies: + safe-buffer "~5.1.0" + +strip-ansi@^3.0.0, strip-ansi@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + integrity sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8= + dependencies: + ansi-regex "^2.0.0" + +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= + dependencies: + ansi-regex "^3.0.0" + +strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= + +subarg@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" + integrity sha1-9izxdYHplrSPyWVpn1TAauJouNI= + dependencies: + minimist "^1.1.0" + +syntax-error@^1.1.1: + version "1.4.0" + resolved "https://registry.yarnpkg.com/syntax-error/-/syntax-error-1.4.0.tgz#2d9d4ff5c064acb711594a3e3b95054ad51d907c" + integrity sha512-YPPlu67mdnHGTup2A8ff7BC2Pjq0e0Yp/IyTFN03zWO0RcK07uLcbi7C2KpGR2FvWbaB0+bfE27a+sBKebSo7w== + dependencies: + acorn-node "^1.2.0" + +tar@^4: + version "4.4.8" + resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.8.tgz#b19eec3fde2a96e64666df9fdb40c5ca1bc3747d" + integrity sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ== + dependencies: + chownr "^1.1.1" + fs-minipass "^1.2.5" + minipass "^2.3.4" + minizlib "^1.1.1" + mkdirp "^0.5.0" + safe-buffer "^5.1.2" + yallist "^3.0.2" + +ternary@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ternary/-/ternary-1.0.0.tgz#45702725608c9499d46a9610e9b0e49ff26f789e" + integrity sha1-RXAnJWCMlJnUapYQ6bDkn/JveJ4= + +text-encoding@0.6.4: + version "0.6.4" + resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19" + integrity sha1-45mpgiV6J22uQou5KEXLcb3CbRk= + +through2@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/through2/-/through2-1.1.1.tgz#0847cbc4449f3405574dbdccd9bb841b83ac3545" + integrity sha1-CEfLxESfNAVXTb3M2buEG4OsNUU= + dependencies: + readable-stream ">=1.1.13-1 <1.2.0-0" + xtend ">=4.0.0 <4.1.0-0" + +through2@~0.4.0: + version "0.4.2" + resolved "https://registry.yarnpkg.com/through2/-/through2-0.4.2.tgz#dbf5866031151ec8352bb6c4db64a2292a840b9b" + integrity sha1-2/WGYDEVHsg1K7bE22SiKSqEC5s= + dependencies: + readable-stream "~1.0.17" + xtend "~2.1.1" + +through2@~0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/through2/-/through2-0.5.1.tgz#dfdd012eb9c700e2323fd334f38ac622ab372da7" + integrity sha1-390BLrnHAOIyP9M084rGIqs3Lac= + dependencies: + readable-stream "~1.0.17" + xtend "~3.0.0" + +"through@>=2.2.7 <3", through@~2.3.4: + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= + +timed-out@^3.0.0: + version "3.1.3" + resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-3.1.3.tgz#95860bfcc5c76c277f8f8326fd0f5b2e20eba217" + integrity sha1-lYYL/MXHbCd/j4Mm/Q9bLiDrohc= + +timers-browserify@^1.0.1: + version "1.4.2" + resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-1.4.2.tgz#c9c58b575be8407375cb5e2462dacee74359f41d" + integrity sha1-ycWLV1voQHN1y14kYtrO50NZ9B0= + dependencies: + process "~0.11.0" + +tmp@0.0.28: + version "0.0.28" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.28.tgz#172735b7f614ea7af39664fa84cf0de4e515d120" + integrity sha1-Fyc1t/YU6nrzlmT6hM8N5OUV0SA= + dependencies: + os-tmpdir "~1.0.1" + +tmp@0.0.31: + version "0.0.31" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7" + integrity sha1-jzirlDjhcxXl29izZX6L+yd65Kc= + dependencies: + os-tmpdir "~1.0.1" + +tmp@0.0.x: + version "0.0.33" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + +to-array@0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" + integrity sha1-F+bBH3PdTz10zaek/zI46a2b+JA= + +to-object-path@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" + integrity sha1-KXWIt7Dn4KwI4E5nL4XB9JmeF68= + dependencies: + kind-of "^3.0.2" + +to-regex-range@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" + integrity sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg= + dependencies: + is-number "^3.0.0" + repeat-string "^1.6.1" + +to-regex@^3.0.1, to-regex@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce" + integrity sha512-FWtleNAtZ/Ki2qtqej2CXTOayOH9bHDQF+Q48VpWyDXjbYxA4Yz8iDB31zXOBUlOHHKidDbqGVrTUvQMPmBGBw== + dependencies: + define-property "^2.0.2" + extend-shallow "^3.0.2" + regex-not "^1.0.2" + safe-regex "^1.1.0" + +topo@1.x.x: + version "1.1.0" + resolved "https://registry.yarnpkg.com/topo/-/topo-1.1.0.tgz#e9d751615d1bb87dc865db182fa1ca0a5ef536d5" + integrity sha1-6ddRYV0buH3IZdsYL6HKCl71NtU= + dependencies: + hoek "2.x.x" + +transformify@~0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/transformify/-/transformify-0.1.2.tgz#9a4f42a154433dd727b80575428a3c9e5489ebf1" + integrity sha1-mk9CoVRDPdcnuAV1Qoo8nlSJ6/E= + dependencies: + readable-stream "~1.1.9" + +tty-browserify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" + integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw== + +type-detect@0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" + integrity sha1-C6XsKohWQORw6k6FBZcZANrFiCI= + +type-detect@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2" + integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI= + +type-detect@^4.0.0: + version "4.0.8" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + +type-is@~1.6.16: + version "1.6.16" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194" + integrity sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q== + dependencies: + media-typer "0.3.0" + mime-types "~2.1.18" + +typedarray@~0.0.5: + version "0.0.6" + resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" + integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= + +typpy@^2.0.0, typpy@^2.1.0, typpy@^2.2.0, typpy@^2.3.4: + version "2.3.11" + resolved "https://registry.yarnpkg.com/typpy/-/typpy-2.3.11.tgz#21a0d22c96fb646306e08b6c669ad43608e1b3b9" + integrity sha512-Jh/fykZSaxeKO0ceMAs6agki9T5TNA9kiIR6fzKbvafKpIw8UlNlHhzuqKyi5lfJJ5VojJOx9tooIbyy7vHV/g== + dependencies: + function.name "^1.0.3" + +uglify-js@~2.2: + version "2.2.5" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.2.5.tgz#a6e02a70d839792b9780488b7b8b184c095c99c7" + integrity sha1-puAqcNg5eSuXgEiLe4sYTAlcmcc= + dependencies: + optimist "~0.3.5" + source-map "~0.1.7" + +uglify-js@~2.4.0: + version "2.4.24" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.4.24.tgz#fad5755c1e1577658bb06ff9ab6e548c95bebd6e" + integrity sha1-+tV1XB4Vd2WLsG/5q25UjJW+vW4= + dependencies: + async "~0.2.6" + source-map "0.1.34" + uglify-to-browserify "~1.0.0" + yargs "~3.5.4" + +uglify-to-browserify@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" + integrity sha1-bgkk1r2mta/jSeOabWMoUKD4grc= + +ul@^5.0.0: + version "5.2.14" + resolved "https://registry.yarnpkg.com/ul/-/ul-5.2.14.tgz#560abd28d0f9762010b0e7a84a56e7208166f61a" + integrity sha512-VaIRQZ5nkEd8VtI3OYo5qNbhHQuBtPtu5k5GrYaKCmcP1H+FkuWtS+XFTSU1oz5GiuAg2FJL5ka8ufr9zdm8eg== + dependencies: + deffy "^2.2.2" + typpy "^2.3.4" + +ultron@1.0.x: + version "1.0.2" + resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.0.2.tgz#ace116ab557cd197386a4e88f4685378c8b2e4fa" + integrity sha1-rOEWq1V80Zc4ak6I9GhTeMiy5Po= + +umd@^2.1.0, umd@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/umd/-/umd-2.1.0.tgz#4a6307b762f17f02d201b5fa154e673396c263cf" + integrity sha1-SmMHt2LxfwLSAbX6FU5nM5bCY88= + dependencies: + rfile "~1.0.0" + ruglify "~1.0.0" + through "~2.3.4" + uglify-js "~2.4.0" + +union-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4" + integrity sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ= + dependencies: + arr-union "^3.1.0" + get-value "^2.0.6" + is-extendable "^0.1.1" + set-value "^0.4.3" + +unpipe@1.0.0, unpipe@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= + +unset-value@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" + integrity sha1-g3aHP30jNRef+x5vw6jtDfyKtVk= + dependencies: + has-value "^0.3.1" + isobject "^3.0.0" + +unzip-response@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-1.0.2.tgz#b984f0877fc0a89c2c773cc1ef7b5b232b5b06fe" + integrity sha1-uYTwh3/AqJwsdzzB73tbIytbBv4= + +urix@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" + integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI= + +url-parse-lax@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73" + integrity sha1-evjzA2Rem9eaJy56FKxovAYJ2nM= + dependencies: + prepend-http "^1.0.1" + +url@~0.10.1: + version "0.10.3" + resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64" + integrity sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ= + dependencies: + punycode "1.3.2" + querystring "0.2.0" + +use@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" + integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== + +useragent@^2.1.12: + version "2.3.0" + resolved "https://registry.yarnpkg.com/useragent/-/useragent-2.3.0.tgz#217f943ad540cb2128658ab23fc960f6a88c9972" + integrity sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw== + dependencies: + lru-cache "4.1.x" + tmp "0.0.x" + +util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= + +util@0.10.3: + version "0.10.3" + resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" + integrity sha1-evsa/lCAUkZInj23/g7TeTNqwPk= + dependencies: + inherits "2.0.1" + +util@~0.10.1: + version "0.10.4" + resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901" + integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A== + dependencies: + inherits "2.0.3" + +utils-merge@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" + integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= + +validate-npm-package-license@^3.0.1: + version "3.0.4" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" + integrity sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== + dependencies: + spdx-correct "^3.0.0" + spdx-expression-parse "^3.0.0" + +vm-browserify@~0.0.1: + version "0.0.4" + resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73" + integrity sha1-XX6kW7755Kb/ZflUOOCofDV9WnM= + dependencies: + indexof "0.0.1" + +void-elements@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" + integrity sha1-wGavtYK7HLQSjWDqkjkulNXp2+w= + +websocket-driver@>=0.5.1: + version "0.7.0" + resolved "https://registry.yarnpkg.com/websocket-driver/-/websocket-driver-0.7.0.tgz#0caf9d2d755d93aee049d4bdd0d3fe2cca2a24eb" + integrity sha1-DK+dLXVdk67gSdS90NP+LMoqJOs= + dependencies: + http-parser-js ">=0.4.0" + websocket-extensions ">=0.1.1" + +websocket-extensions@>=0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29" + integrity sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg== + +which@^1.2.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +wide-align@^1.1.0: + version "1.1.3" + resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" + integrity sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA== + dependencies: + string-width "^1.0.2 || 2" + +window-size@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" + integrity sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0= + +wordwrap@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" + integrity sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8= + +wordwrap@~0.0.2: + version "0.0.3" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" + integrity sha1-o9XabNXAvAAI03I0u68b7WMFkQc= + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + +ws@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/ws/-/ws-1.1.2.tgz#8a244fa052401e08c9886cf44a85189e1fd4067f" + integrity sha1-iiRPoFJAHgjJiGz0SoUYnh/UBn8= + dependencies: + options ">=0.0.5" + ultron "1.0.x" + +wtf-8@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wtf-8/-/wtf-8-1.0.0.tgz#392d8ba2d0f1c34d1ee2d630f15d0efb68e1048a" + integrity sha1-OS2LotDxw00e4tYw8V0O+2jhBIo= + +xmlhttprequest-ssl@1.5.3: + version "1.5.3" + resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.3.tgz#185a888c04eca46c3e4070d99f7b49de3528992d" + integrity sha1-GFqIjATspGw+QHDZn3tJ3jUomS0= + +xmlhttprequest@^1.8.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" + integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= + +"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" + integrity sha1-pcbVMr5lbiPbgg77lDofBJmNY68= + +xtend@^3.0.0, xtend@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-3.0.0.tgz#5cce7407baf642cba7becda568111c493f59665a" + integrity sha1-XM50B7r2Qsunvs2laBEcST9ZZlo= + +xtend@~2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-2.1.2.tgz#6efecc2a4dad8e6962c4901b337ce7ba87b5d28b" + integrity sha1-bv7MKk2tjmlixJAbM3znuoe10os= + dependencies: + object-keys "~0.4.0" + +yallist@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" + integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= + +yallist@^3.0.0, yallist@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" + integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A== + +yargs@~3.5.4: + version "3.5.4" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.5.4.tgz#d8aff8f665e94c34bd259bdebd1bfaf0ddd35361" + integrity sha1-2K/49mXpTDS9JZvevRv68N3TU2E= + dependencies: + camelcase "^1.0.2" + decamelize "^1.0.0" + window-size "0.1.0" + wordwrap "0.0.2" + +yeast@0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" + integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= diff --git a/feature-toggles/user/userFactory.js b/feature-toggles/user/userFactory.js new file mode 100644 index 000000000..2f2555827 --- /dev/null +++ b/feature-toggles/user/userFactory.js @@ -0,0 +1,46 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + app.factory('UserFactory', () => { + + /** + * User model. + * @param {*} data - data of user. + */ + function User(data) { + data = data || {}; + _.extend(this, data); + + if (!this.current_institution) { + this.changeInstitution(); + } + } + + /** + * This function modifies the user's current institution. + * @param {Object} institution - institution to be change. + */ + User.prototype.changeInstitution = function changeInstitution(institution) { + if (this.institutions && this.institutions.length > 0) { + institution = institution || this.institutions[0]; + this.current_institution = _.find(this.institutions, {'key': institution.key}); + window.localStorage.userInfo = JSON.stringify(this); + } + }; + + /** + * This function checks whether the user has the permission passed by parameter. + * @param {String} permissionType - permission to be checked. + */ + User.prototype.hasPermission = function hasPermission(permissionType) { + return permissionType in this.permissions; + }; + + + return { + user: User + }; + }); +})(); \ No newline at end of file diff --git a/feature-toggles/user/userService.js b/feature-toggles/user/userService.js new file mode 100644 index 000000000..009e9074f --- /dev/null +++ b/feature-toggles/user/userService.js @@ -0,0 +1,14 @@ +(function() { + 'use strict'; + + var app = angular.module("app"); + + app.service("UserService", function UserService(HttpService) { + var service = this; + var USER_URI = "/api/user"; + + service.load = function load() { + return HttpService.get(USER_URI); + }; + }); +})(); \ No newline at end of file diff --git a/feature-toggles/utils/httpService.js b/feature-toggles/utils/httpService.js new file mode 100644 index 000000000..9b1e472ef --- /dev/null +++ b/feature-toggles/utils/httpService.js @@ -0,0 +1,43 @@ +(function () { + 'use strict'; + + const app = angular.module('app'); + + app.service('HttpService', function HttpService($http) { + const service = this; + + const POST = 'POST'; + const GET = 'GET'; + const PUT = 'PUT'; + const DELETE = 'DELETE'; + const PATCH = 'PATCH'; + + service.get = function getMethod(url) { + return request(GET, url); + }; + + service.post = function postMethod(url, data) { + return request(POST, url, data); + }; + + service.put = function putMethod(url, data) { + return request(PUT, url, data); + }; + + service.delete = function deleteMethod(url) { + return request(DELETE, url); + }; + + service.patch = function patchMethod(url, data) { + return request(PATCH, url, data); + }; + + function request(method, url, data) { + return $http({ + method, + url, + data + }).then(response => response.data); + } + }); +})(); \ No newline at end of file diff --git a/feature-toggles/utils/loadCircleDirective.js b/feature-toggles/utils/loadCircleDirective.js new file mode 100644 index 000000000..64c50b67a --- /dev/null +++ b/feature-toggles/utils/loadCircleDirective.js @@ -0,0 +1,26 @@ +(function() { + "use strict"; + + const app = angular.module("app"); + + app.controller("LoadController", function($scope){ + $scope.addLayoutFill ? + document.getElementById("element").classList.add("fill-screen") : ""; + }); + + app.directive("loadCircle", function() { + return { + restrict: 'E', + scope: { + addLayoutFill: '=' + }, + controller: "LoadController", + controlerAs: "ctrl", + template: '
    ' + + '
    ' + + '' + + '
    ' + + '
    ' + }; + }); +})(); \ No newline at end of file diff --git a/feature-toggles/utils/messageService.js b/feature-toggles/utils/messageService.js new file mode 100644 index 000000000..cb3821f1f --- /dev/null +++ b/feature-toggles/utils/messageService.js @@ -0,0 +1,39 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + app.service('MessageService', ['$mdToast', function($mdToast) { + const service = this; + const SCREEN_SIZES = { + SMARTPHONE: 475 + }; + + /** + * This function displays a small dialog containing the received message per parameter. + * @param {String} message - Message to show + */ + function showToast(message) { + $mdToast.show( + $mdToast.simple() + .textContent(message) + .action('FECHAR') + .highlightAction(true) + .hideDelay(5000) + .position('bottom right') + ); + }; + + /** Show toast with infomation message when not in mobile. + */ + service.showInfoToast = function showInfoToast(message){ + !Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE) && showToast(message); + } + + /** Show toast with error message. + */ + service.showErrorToast = function showErrorToast(message){ + showToast(message); + } + }]); +})(); \ No newline at end of file diff --git a/feature-toggles/utils/statesConstants.js b/feature-toggles/utils/statesConstants.js new file mode 100644 index 000000000..1360ccd23 --- /dev/null +++ b/feature-toggles/utils/statesConstants.js @@ -0,0 +1,10 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + app.constant('STATES', { + MANAGE_FEATURES: "manage-features", + SIGNIN: 'signin' + }); +})(); \ No newline at end of file diff --git a/feature-toggles/utils/utils.js b/feature-toggles/utils/utils.js new file mode 100644 index 000000000..fd6f4c5e3 --- /dev/null +++ b/feature-toggles/utils/utils.js @@ -0,0 +1,28 @@ +'use strict'; + +var Utils = { + + /** + * This function indicate if the current screen size are smaller than the screen passed by parameter. + * @param {number} the screen size that will be compared. + * @returns {boolean} True if the screen is smaller or equal to the parameter and false in otherwise. + */ + isMobileScreen: function isMobileScreen(mobileScreenSize) { + if (mobileScreenSize) { + return screen.width <= mobileScreenSize; + } + return screen.width <= 960; + }, + + /** + * Replaces the original backend domain by the local one + * @param {object} config configutarion object + */ + updateBackendUrl : function updateBackendUrl(config) { + var restApiUrl = Config.BACKEND_URL; + + var restApiRegex = new RegExp('^.*?/api/(.*)$'); + + config.url = config.url.replace(restApiRegex, restApiUrl + '/api/$1'); + } +}; \ No newline at end of file diff --git a/frontend/app.js b/frontend/app.js index 9af06e33b..4126e70a9 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -62,6 +62,15 @@ } } }) + .state(STATES.SEARCH_EVENT, { + url: "/search_event", + views: { + user_content: { + templateUrl: "app/search/search_event.html", + controller: "SearchEventController as searchCtrl" + } + } + }) .state(STATES.HOME, { url: "/", views: { @@ -75,17 +84,17 @@ views: { user_content: { templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/institutions.html", - "app/institution/registered_institutions_mobile.html", 450), + "app/institution/registered_institutions_mobile.html", SCREEN_SIZES.SMARTPHONE), controller: "AllInstitutionsController as allInstitutionsCtrl" } } }) .state(STATES.EVENTS, { - url: "/events", + url: "/events?institutionKey", views: { user_content: { templateUrl: Utils.selectFieldBasedOnScreenSize("app/event/events.html", - "app/event/events_mobile.html", 475), + "app/event/events_mobile.html", SCREEN_SIZES.SMARTPHONE), controller: "EventController as eventCtrl", } } @@ -108,13 +117,16 @@ url: "/inviteInstitution", views: { user_content: { - templateUrl: "app/invites/invite_institution.html", + templateUrl: Utils.selectFieldBasedOnScreenSize( + "app/invites/invite_institution.html", + "app/invites/invite_institution_mobile.html", + SCREEN_SIZES.SMARTPHONE), controller: "InviteInstitutionController as inviteInstCtrl" } } }) .state(STATES.CONFIG_PROFILE, { - url: "/config_profile", + url: "/config_profile/:userKey", views: { user_content: { templateUrl: Utils.selectFieldBasedOnScreenSize( @@ -159,11 +171,23 @@ views: { institution_content: { templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/followers.html", - "app/institution/followers_mobile.html", 475), + "app/institution/followers_mobile.html", SCREEN_SIZES.SMARTPHONE), controller: "FollowersInstController as followersCtrl" } } }) + .state(STATES.INST_DESCRIPTION, { + url: "/institution/:institutionKey/description", + views: { + institution_content: { + templateUrl: "app/institution/descriptionInst/description_inst.html", + controller: "DescriptionInstController as descriptionCtrl" + } + }, + params: { + institution: undefined + } + }) .state(STATES.INST_EVENTS, { url: "/institution/:institutionKey/institution_events", views: { @@ -178,7 +202,7 @@ views: { institution_content: { templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/members.html", - "app/institution/members_mobile.html", 475), + "app/institution/members_mobile.html", SCREEN_SIZES.SMARTPHONE), controller: "ManagementMembersController as membersCtrl" } } @@ -188,7 +212,7 @@ views: { institution_content: { templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/registration_data.html", - "app/institution/registration_data_mobile.html", 475), + "app/institution/registration_data_mobile.html", SCREEN_SIZES.SMARTPHONE), controller: "InstitutionController as institutionCtrl" } } @@ -223,20 +247,42 @@ url: "/institution/:institutionKey", views: { content: { - templateUrl: "app/institution/management_institution_page.html", + templateUrl: "app/institution/manageInstitution/management_institution_page.html", controller: "InstitutionController as institutionCtrl" } } }) + .state(STATES.MANAGE_INST_MENU_MOB, { + url: "/menu", + views: { + content_manage_institution: { + templateUrl: "app/institution/manageInstMenu/manage_institution_menu.html", + controller: "ManageInstMenuController as manageInstMenuCtrl" + } + } + }) .state(STATES.MANAGE_INST_MEMBERS, { url: "/managementMembers", views: { content_manage_institution: { - templateUrl: "app/institution/management_members.html", + templateUrl: Utils.selectFieldBasedOnScreenSize( + "app/institution/manageMembers/management_members.html", + "app/institution/manageMembers/management_members_mobile.html", + SCREEN_SIZES.SMARTPHONE + ), controller: "ManagementMembersController as manageMemberCtrl" } } }) + .state(STATES.MANAGE_INST_LINKS, { + url: "/links", + views: { + content_manage_institution: { + templateUrl: "app/institution/manageInstitution/management_institution_mobile.html", + controller: "InviteInstHierarchieController as inviteInstHierCtrl" + } + } + }) .state(STATES.EVENT_DETAILS, { url: "/event/:eventKey/details", views: { @@ -250,8 +296,11 @@ url: "/edit", views: { content_manage_institution: { - templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/edit_info.html", - "app/institution/edit_info_mobile.html", 475) + templateUrl: Utils.selectFieldBasedOnScreenSize( + "app/institution/editInfo/edit_info.html", + "app/institution/editInfo/edit_info_mobile.html", + SCREEN_SIZES.SMARTPHONE + ) } } }) @@ -268,8 +317,8 @@ url: "/:key/new_invite", views: { main: { - templateUrl: "app/invites/new_invite_page.html", - controller: "NewInviteController as newInviteCtrl" + templateUrl: "app/invites/new_invite_page.html", + controller: "NewInviteController as newInviteCtrl" } } }) @@ -297,8 +346,9 @@ url: "/create_institution_form", views: { main: { - templateUrl: "app/institution/create_inst_form.html", - controller: "ConfigInstController as configInstCtrl" + templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/create_inst_form.html", + "app/institution/create_inst_form_mobile.html"), + controller: Utils.selectFieldBasedOnScreenSize("ConfigInstController as configInstCtrl", "CreateInvitedInstitutionController as ctrl"), } }, params: { @@ -515,7 +565,11 @@ */ app.run(function mobileInterceptor($transitions, $state, STATES, SCREEN_SIZES) { const permitted_routes = [ - STATES.CREATE_EVENT + STATES.CREATE_EVENT, + STATES.SEARCH_EVENT, + STATES.INST_DESCRIPTION, + STATES.MANAGE_INST_LINKS, + STATES.MANAGE_INST_MENU_MOB ]; $transitions.onStart({ @@ -559,6 +613,35 @@ }); }); + app.run(function featureToggleInterceptor(FeatureToggleService, MapStateToFeatureService, $transitions, STATES, MessageService) { + + $transitions.onBefore({ + to: function(state) { + const stateName = state.name; + return MapStateToFeatureService.containsFeature(stateName); + } + }, function (transition) { + const targetStateName = transition.to().name; + + return FeatureToggleService.isEnabled(MapStateToFeatureService.getFeatureByState(targetStateName)).then(function(enabled) { + if (enabled) { + return transition; + } else { + return transition.router.stateService.target(STATES.ERROR, { + "msg": "Desculpa! Este recurso ainda não está disponível.", + "status": "403" + }); + } + }).catch(function(message) { + MessageService.showErrorToast(message); + return transition.router.stateService.target(STATES.ERROR, { + "msg": "Desculpa! Este recurso ainda não está disponível.", + "status": "403" + }); + }); + }); + }); + function initServiceWorker() { if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js').then(function (registration) { diff --git a/frontend/auth/authService.js b/frontend/auth/authService.js index b242af4aa..87e90e30b 100644 --- a/frontend/auth/authService.js +++ b/frontend/auth/authService.js @@ -3,8 +3,8 @@ var app = angular.module("app"); - app.service("AuthService", function AuthService($q, $state, $window, UserService, - MessageService, PushNotificationService, STATES) { + app.service("AuthService", ['$q', '$state', '$window', 'UserService', 'MessageService', 'STATES', + function AuthService($q, $state, $window, UserService, MessageService, STATES) { var service = this; var authObj = firebase.auth(); @@ -114,7 +114,7 @@ configUser(userLoaded, firebaseUser); deferred.resolve(userInfo); }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); deferred.reject(error); }); return deferred.promise; @@ -130,9 +130,7 @@ if (user.emailVerified) { return user.getIdToken(true).then(function(idToken) { return service.setupUser(idToken, user.emailVerified).then(function success(userInfo) { - return PushNotificationService.requestNotificationPermission(service.getCurrentUser()).finally(() => { - return userInfo; - }); + return userInfo; }); }); } else { @@ -162,7 +160,7 @@ deferred.resolve(userInfo); }); }).catch(function(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); deferred.reject(error); }); return deferred.promise; @@ -201,7 +199,7 @@ service.save(); deferred.resolve(userInfo); }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); deferred.reject(error); }); return deferred.promise; @@ -259,5 +257,5 @@ } init(); - }); + }]); })(); \ No newline at end of file diff --git a/frontend/auth/loginController.js b/frontend/auth/loginController.js index 3784d8e2c..046956c15 100644 --- a/frontend/auth/loginController.js +++ b/frontend/auth/loginController.js @@ -26,7 +26,7 @@ promise.then(function success() { redirectTo(redirectPath); }).catch(function(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); return promise; }; @@ -43,7 +43,7 @@ redirectTo(redirectPath); } ).catch(function(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; diff --git a/frontend/auth/resetPasswordController.js b/frontend/auth/resetPasswordController.js index 96dab4546..aa69fd3c8 100644 --- a/frontend/auth/resetPasswordController.js +++ b/frontend/auth/resetPasswordController.js @@ -20,7 +20,7 @@ resetCtrl.emailSent = true; $scope.$apply(); }).catch(_ => { - MessageService.showToast("Ocorreu um erro, verifique seu e-mail e tente novamente"); + MessageService.showErrorToast("Ocorreu um erro, verifique seu e-mail e tente novamente"); }); }; diff --git a/frontend/auth/signupDirective.js b/frontend/auth/signupDirective.js index 7dd2b5456..bfcae9a52 100644 --- a/frontend/auth/signupDirective.js +++ b/frontend/auth/signupDirective.js @@ -14,7 +14,7 @@ } var newUser = controller.newUser; if (newUser.password !== newUser.verifypassword) { - MessageService.showToast("Senhas incompatíveis"); + MessageService.showErrorToast("Senhas incompatíveis"); return; } AuthService.signupWithEmailAndPassword( diff --git a/frontend/comment/comment.component.js b/frontend/comment/comment.component.js index 2b1d6f656..be6aa01a9 100644 --- a/frontend/comment/comment.component.js +++ b/frontend/comment/comment.component.js @@ -61,7 +61,7 @@ .then(function () { commentCtrl.addLike(); }).catch(function () { - MessageService.showToast("Não foi possível curtir o comentário"); + MessageService.showErrorToast("Não foi possível curtir o comentário"); }).finally(function () { commentCtrl.saving = false; }); @@ -73,7 +73,7 @@ .then(function sucess() { commentCtrl.removeLike(); }).catch(function error() { - MessageService.showToast("Não foi possível descurtir o comentário"); + MessageService.showErrorToast("Não foi possível descurtir o comentário"); }).finally(function() { commentCtrl.saving = false; }); @@ -88,7 +88,7 @@ ).then(function success(data) { commentCtrl.comment.replies[data.id] = data; }).catch(function error() { - MessageService.showToast("Não foi possível responder ao comentário"); + MessageService.showErrorToast("Não foi possível responder ao comentário"); }).finally(function() { commentCtrl.newReply = null; commentCtrl.saving = false; @@ -100,7 +100,7 @@ CommentService.deleteReply(commentCtrl.post.key, commentCtrl.comment.id, commentCtrl.replyId) .then(function success() { delete commentCtrl.comment.replies[commentCtrl.replyId]; - MessageService.showToast('Comentário excluído com sucesso'); + MessageService.showInfoToast('Comentário excluído com sucesso'); }); }; @@ -108,7 +108,7 @@ CommentService.deleteComment(commentCtrl.post.key, commentCtrl.comment.id).then( function success() { commentCtrl.post.deleteComment(commentCtrl.comment.id); - MessageService.showToast('Comentário excluído com sucesso'); + MessageService.showInfoToast('Comentário excluído com sucesso'); }); }; @@ -118,7 +118,7 @@ ).then(function () { commentCtrl.onDelete(); }).catch(function () { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); }; diff --git a/frontend/email/EmailService.js b/frontend/email/EmailService.js new file mode 100644 index 000000000..e6d677733 --- /dev/null +++ b/frontend/email/EmailService.js @@ -0,0 +1,24 @@ +(function () { + 'use strict'; + + angular.module("app").service('EmailService', ["HttpService", function emailService(HttpService) { + const emailService = this; + + emailService.STATE_LINK_EMAIL_API_URI = "/api/email/current-state"; + + /** + * Make a post request to the backend to send a state link by email. + * It receives the state link that will be sent. + * + * @param stateLink the state link that will be sent. + * @returns The post request to the backend. + */ + emailService.sendStateLink = (stateLink) => { + return HttpService.post(emailService.STATE_LINK_EMAIL_API_URI, { + "data": { + "state-link": Config.FRONTEND_URL + stateLink + } + }); + }; + }]); +})(); \ No newline at end of file diff --git a/frontend/email/stateLinkRequest/StateLinkRequestService.js b/frontend/email/stateLinkRequest/StateLinkRequestService.js new file mode 100644 index 000000000..0e97f8682 --- /dev/null +++ b/frontend/email/stateLinkRequest/StateLinkRequestService.js @@ -0,0 +1,43 @@ +(function () { + 'use strict'; + + angular.module("app").service('StateLinkRequestService', ['$mdDialog', function StateLinkRequestService($mdDialog) { + const StateLinkRequestService = this; + + /** + * It shows a dialog that will ask the user if it wants to receive the link of the state + * by email. It is used in pages that has big forms to be filled. + * + * @param stateLink the state link that will be sent by email. + * @param previousState the state that the user will comeback if it accepts to receive + * the email. + */ + StateLinkRequestService.showLinkRequestDialog = (stateLink, previousState) => { + $mdDialog.show({ + templateUrl: "app/email/stateLinkRequest/stateLinkRequestDialog.html", + clickOutsideToClose:true, + locals: { + stateLink: stateLink, + previousState: previousState, + }, + controller: [ + 'EmailService', + '$state', + 'stateLink', + 'previousState', + StateLinkRequestController, + ], + controllerAs: 'ctrl' + }); + }; + + function StateLinkRequestController(EmailService, $state, stateLink, previousState) { + const ctrl = this; + + ctrl.sendStateLink = () => { + EmailService.sendStateLink(stateLink); + $state.go(previousState); + }; + } + }]); +})(); \ No newline at end of file diff --git a/frontend/email/stateLinkRequest/stateLinkConstants.js b/frontend/email/stateLinkRequest/stateLinkConstants.js new file mode 100644 index 000000000..0a0cf085b --- /dev/null +++ b/frontend/email/stateLinkRequest/stateLinkConstants.js @@ -0,0 +1,9 @@ +(function () { + 'use strict'; + + angular.module("app").constant('STATE_LINKS', { + 'CREATE_EVENT': '/events', + 'MANAGE_INSTITUTION': '/institution/INSTITUTION_KEY/edit', + 'INVITE_INSTITUTION': '/inviteInstitution' + }); +})(); \ No newline at end of file diff --git a/frontend/email/stateLinkRequest/stateLinkRequestDialog.html b/frontend/email/stateLinkRequest/stateLinkRequestDialog.html new file mode 100644 index 000000000..b87ae0cde --- /dev/null +++ b/frontend/email/stateLinkRequest/stateLinkRequestDialog.html @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/frontend/error/error.html b/frontend/error/error.html index 5981c35b0..137877e25 100644 --- a/frontend/error/error.html +++ b/frontend/error/error.html @@ -1,5 +1,5 @@ -
    +
    @@ -36,4 +36,9 @@
    +
    + + + +
    \ No newline at end of file diff --git a/frontend/error/errorController.js b/frontend/error/errorController.js index 379e5388c..b6498d7f9 100644 --- a/frontend/error/errorController.js +++ b/frontend/error/errorController.js @@ -16,5 +16,9 @@ errorCtrl.goToReport = function goToReport() { $window.open("http://support.plataformacis.org/report"); } + + errorCtrl.isMobileScreen = () => Utils.isMobileScreen(); + + errorCtrl.getMobileMsg = () => "Erro " + errorCtrl.status + ": " + errorCtrl.msg; }); })(); \ No newline at end of file diff --git a/frontend/event/canceledEventHeader.component.js b/frontend/event/canceledEventHeader.component.js new file mode 100644 index 000000000..8ae316bc6 --- /dev/null +++ b/frontend/event/canceledEventHeader.component.js @@ -0,0 +1,27 @@ +"use strict"; + +(function() { + + function CanceledEventController() { + const canceledEventCtrl = this; + + /** + * Get the first name of who modified the event by last + */ + canceledEventCtrl.getNameOfLastModified = () => { + return _.first(canceledEventCtrl.event.last_modified_by.split(" ")); + }; + + }; + + angular + .module("app") + .component("canceledEventHeader", { + templateUrl: 'app/event/canceled_event_header.html', + controller: [CanceledEventController], + controllerAs: 'canceledEventCtrl', + bindings: { + event: '<', + } + }); +})(); \ No newline at end of file diff --git a/frontend/event/canceled_event_header.html b/frontend/event/canceled_event_header.html new file mode 100644 index 000000000..3dbb824cc --- /dev/null +++ b/frontend/event/canceled_event_header.html @@ -0,0 +1,8 @@ + + highlight_off +
    +
    ESTE EVENTO FOI CANCELADO
    +
    por {{canceledEventCtrl.getNameOfLastModified()}} • + {{canceledEventCtrl.event.last_modified_date | amUtc | amLocal | amCalendar:referenceTime:formats}}
    +
    +
    \ No newline at end of file diff --git a/frontend/event/create_event.html b/frontend/event/create_event.html index d45027df8..58c12dbbf 100644 --- a/frontend/event/create_event.html +++ b/frontend/event/create_event.html @@ -1,9 +1,5 @@
    -
    - - keyboard_arrow_left - -
    +
    -
    -
    @@ -158,8 +158,8 @@ + ng-change="createEventCtrl.changeUrlLink(videoUrl, createEventCtrl.videoUrls)" + name="video" validate-youtube-link-directive/>
    Link do Youtube inválido.
    @@ -178,7 +178,7 @@ + ng-change="createEventCtrl.changeUrlLink(usefulLink, createEventCtrl.usefulLinks)" type="url"/> @@ -215,7 +215,7 @@

    Inserir foto de capa

    Cancelar - + {{createEventCtrl.lastStep() ? "publicar" : "avançar"}}
    diff --git a/frontend/event/event.css b/frontend/event/event.css index 027165ed0..b6555e71a 100644 --- a/frontend/event/event.css +++ b/frontend/event/event.css @@ -140,8 +140,16 @@ } .centralized-event-content, .event-day-properties { - margin-left: auto; - margin-right: auto; + margin: 0; +} + +.centralized-event-content { + display: flex; + justify-content: center; +} + +.event-content-grid { + display: grid; } #menu-button { @@ -206,7 +214,7 @@ .events-grid { display: grid; grid-template-columns: 20% 78% auto; - grid-template-rows: 9em auto; + grid-template-rows: auto; align-items: initial; margin: 0; } @@ -238,6 +246,7 @@ .events-day-position { grid-column-start: 1; grid-column-end: 2; + justify-self: center; } .event-position { @@ -245,7 +254,7 @@ grid-column-end: 3; } - .event-preview-image { + .event-preview-image, .event-preview-without-image { max-height: 8em; height: 8em; max-width: 100%; @@ -255,6 +264,10 @@ background-color: #009688; } + .event-preview-without-image { + max-height: 3.5em; + } + .event-preview-border { border-left: 0.55em solid; } @@ -314,6 +327,10 @@ width: 6em; } + .select-container { + justify-content: center; + } + .create-event-mobile-top-bar { height: 3em; width: 100%; @@ -481,7 +498,7 @@ } .create-event-grid-inst { - grid-template-rows: 3em 3em auto; + grid-template-rows: 3.5em 3.5em auto; } .create-event-form-second-line { @@ -510,6 +527,60 @@ color:#009688; } + .event-canceled-tag, .event-canceled-icon { + color: white; + } + + .event-canceled-icon { + width: 1.5em; + height: 2em; + font-size: 2.5em; + margin-top: 0.4em; + margin-left: 0.3em; + } + + .event-canceled-tag { + margin-right: 2em; + margin-left: -1em; + margin-top: 1.4em; + font-size: 0.9em; + } + + .event-canceled-subtitle { + font-size: 0.65em; + margin-top: -1.9em; + margin-left: -1.25em; + } + + @media screen and (max-width: 400px) { + .event-canceled-tag { + font-size: 0.8em; + } + } + + @media screen and (max-width: 360px) { + .event-canceled-tag { + margin-top: 1.7em; + font-size: 0.75em; + } + } + + @media screen and (max-width: 330px) { + .event-canceled-tag { + margin-right: 1em; + margin-top: 2.1em; + font-size: 0.69em; + } + + .event-canceled-subtitle { + font-size: 0.55em; + } + + .event-canceled-icon { + margin-left: 0.2em; + } + } + @media screen and (min-height: 600px) { .event-links-fields { max-height: 13em; diff --git a/frontend/event/event.js b/frontend/event/event.js index 5334477d2..6af6e5a95 100644 --- a/frontend/event/event.js +++ b/frontend/event/event.js @@ -25,3 +25,11 @@ Event.prototype.convertDate = function(){ } }; +Event.prototype.addFollower = function (userKey) { + this.followers.push(userKey); +}; + +Event.prototype.removeFollower = function (userKey) { + this.followers = this.followers.filter(currentFollower => {currentFollower !== userKey}); +}; + diff --git a/frontend/event/eventCard.component.js b/frontend/event/eventCard.component.js new file mode 100644 index 000000000..60b8e9e32 --- /dev/null +++ b/frontend/event/eventCard.component.js @@ -0,0 +1,37 @@ +"use strict"; + +(function() { + + function EventCardController(AuthService) { + const eventCardCtrl = this; + + eventCardCtrl.user = AuthService.getCurrentUser(); + + /** + * Get the color of institutional profile of the user + */ + eventCardCtrl.getProfileColor = () => { + const profile = _.filter(eventCardCtrl.user.institution_profiles, function(prof) { + return prof.institution_key === eventCardCtrl.event.institution_key; + }); + return _.get(_.first(profile), 'color', 'teal'); + }; + + eventCardCtrl.$onInit = () => { + const address = eventCardCtrl.event.address; + if (_.isString(address)) + eventCardCtrl.event.address = JSON.parse(address); + }; + }; + + angular + .module("app") + .component("eventCard", { + templateUrl: 'app/event/event_card.html', + controller: ['AuthService', EventCardController], + controllerAs: 'eventCardCtrl', + bindings: { + event: '<', + } + }); +})(); \ No newline at end of file diff --git a/frontend/event/eventController.js b/frontend/event/eventController.js index c95a9a371..83e82e915 100644 --- a/frontend/event/eventController.js +++ b/frontend/event/eventController.js @@ -2,7 +2,7 @@ (function() { var app = angular.module('app'); - app.controller("EventController", function EventController(EventService, $state, $mdDialog, AuthService, $q, STATES, SCREEN_SIZES) { + app.controller("EventController", function EventController(EventService, $state, $mdDialog, AuthService, $q, STATES, SCREEN_SIZES, InstitutionService, $filter) { const eventCtrl = this; let content = document.getElementById("content"); @@ -17,14 +17,24 @@ eventCtrl.selectedYear = null; eventCtrl.user = AuthService.getCurrentUser(); eventCtrl.isLoadingEvents = true; + eventCtrl.isFiltering = false; + eventCtrl.institutionsFilter = []; eventCtrl.loadMoreEvents = function loadMoreEvents() { - if (eventCtrl._moreEvents) { - const getEventsFunction = eventCtrl.institutionKey ? EventService.getInstEvents : EventService.getEvents; - return eventCtrl._loadEvents(getEventsFunction, - _.get(eventCtrl.selectedMonth, 'month'), - eventCtrl.selectedYear); + const getEventsFunction = (eventCtrl.institutionKey) ? + EventService.getInstEvents : EventService.getEvents; + const params = (eventCtrl.institutionKey) ? + { + page: eventCtrl._actualPage, + institutionKey:eventCtrl.institutionKey + } : + { + page: eventCtrl._actualPage, + month: _.get(eventCtrl.selectedMonth, 'month'), + year: eventCtrl.selectedYear + }; + return eventCtrl._loadEvents(getEventsFunction, params); } return $q.when(); }; @@ -35,13 +45,12 @@ * Get events from backend * @param {*} deferred The promise to resolve before get events from backend * @param {*} getEvents The function received to call and get events - * @param {*} month The month to filter the get of events - * @param {*} year The year to filter the get of events + * @param {*} params The params used of service * @private */ - eventCtrl._loadEvents = (getEvents, month, year) => { - return getEvents({ page: eventCtrl._actualPage, institutionKey: eventCtrl.institutionKey, - month: month, year: year}).then(function success(response) { + eventCtrl._loadEvents = (getEvents, params) => { + return getEvents(params) + .then(function success(response) { eventCtrl._actualPage += 1; eventCtrl._moreEvents = response.next; @@ -53,13 +62,22 @@ eventCtrl.events.push(event); }); } + + if (Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE) && !eventCtrl.institutionKey) { + eventCtrl.events = eventCtrl.events.filter(event => { + const institution = _.find(eventCtrl.institutionsFilter, institution => institution.name === event.institution_name); + return institution && institution.enable; + }); + } else { + eventCtrl.events = $filter('filter')(eventCtrl.events, eventCtrl.institutionKey); + } eventCtrl.isLoadingEvents = false; eventCtrl._getEventsByDay(); }, function error() { $state.go(STATES.HOME); }); - } + }; eventCtrl.newEvent = function newEvent(event) { if(Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE)) { @@ -106,18 +124,7 @@ * @param {object} event - The current event */ eventCtrl.goToEvent = (event) => { - $state.go(STATES.EVENT_DETAILS, { eventKey: event.key }); - }; - - /** - * Get the color of institutional profile of the user - * @param {object} event - The current event - */ - eventCtrl.getProfileColor = (event) => { - const profile = _.filter(eventCtrl.user.institution_profiles, function(prof) { - return prof.institution_key === event.institution_key; - }); - return _.get(_.first(profile), 'color', 'teal'); + event.state !== 'deleted' && $state.go(STATES.EVENT_DETAILS, { eventKey: event.key }); }; /** @@ -171,8 +178,8 @@ * @private */ eventCtrl._getEventsByDay = () => { + eventCtrl.eventsByDay = []; if(eventCtrl.events.length > 0 && eventCtrl.selectedMonth) { - eventCtrl.eventsByDay = []; let eventsByDay = {}; _.forEach(eventCtrl.events, function(event) { eventCtrl._distributeEvents(event, eventsByDay); @@ -213,7 +220,7 @@ eventCtrl.loadMoreEvents(); }); }; - + /** * Generate the menuItems that will live in the middle of the toolbar. */ @@ -251,10 +258,13 @@ title: 'Atualizar', action: () => { eventCtrl._moreEvents = true; eventCtrl._actualPage = 0; eventCtrl.events = []; eventCtrl.loadMoreEvents()} }, - { - title: 'Filtrar por instituição', action: () => {} - } - ] + ]; + + if (!eventCtrl.institutionKey) { + toolbarMenuGeneralOptions.options.push({ + title: 'Filtrar por instituição', action: () => {eventCtrl.isFiltering = true;} + }); + } return toolbarMenuGeneralOptions; }; @@ -267,15 +277,53 @@ eventCtrl.toolbarItems = eventCtrl._getToolbarMobileMenuItems(); }; + /** + * This function applies the modifications made + * to the event filter by institution, + * reloading events and filtering. + */ + eventCtrl.confirmFilter = function confirmFilter() { + eventCtrl.events = []; + eventCtrl._actualPage = 0; + eventCtrl._moreEvents = true; + eventCtrl.isLoadingEvents = true; + eventCtrl.cancelFilter(); + return eventCtrl.loadMoreEvents(); + }; + + /** + * This function cancels the filter run. + */ + eventCtrl.cancelFilter = function cancelFilter() { + eventCtrl.isFiltering = false; + }; + eventCtrl.$onInit = () => { eventCtrl.institutionKey = $state.params.institutionKey; + getCurrentInstitution(); + if(Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE)) { eventCtrl._getMonths().then(() => { eventCtrl.setupToolbarFields(); }); + + eventCtrl.institutionsFilter = eventCtrl.user.follows.map(institution => { + return { + name: institution.name, + enable: true + }; + }); } else { eventCtrl.loadMoreEvents(); } }; + + function getCurrentInstitution() { + if (!_.isNil(eventCtrl.institutionKey)) { + InstitutionService.getInstitution(eventCtrl.institutionKey).then((institutionData) => { + eventCtrl.institution = new Institution(institutionData); + }); + } + } }); })(); \ No newline at end of file diff --git a/frontend/event/eventDetailsDirective.js b/frontend/event/eventDetailsDirective.js index 9a2e4f9c5..dabc51eaa 100644 --- a/frontend/event/eventDetailsDirective.js +++ b/frontend/event/eventDetailsDirective.js @@ -3,7 +3,7 @@ var app = angular.module('app'); app.controller("EventDetailsController", function EventDetailsController(MessageService, EventService, - $state, $mdDialog, AuthService, STATES, SCREEN_SIZES) { + $state, $mdDialog, AuthService, STATES, SCREEN_SIZES, ngClipboard) { var eventCtrl = this; @@ -11,36 +11,41 @@ eventCtrl.isLoadingEvents = true; eventCtrl.showImage = true; - eventCtrl.share = function share(ev, event) { + + eventCtrl.share = function share(ev) { $mdDialog.show({ controller: "SharePostController", controllerAs: "sharePostCtrl", - templateUrl: 'app/post/share_post_dialog.html', + templateUrl: Utils.selectFieldBasedOnScreenSize( + 'app/post/share_post_dialog.html', + 'app/post/share_post_dialog_mobile.html' + ), parent: angular.element(document.body), targetEvent: ev, clickOutsideToClose: true, locals: { user: eventCtrl.user, - post: event, + post: eventCtrl.event, addPost: false } }); }; - eventCtrl.confirmDeleteEvent = function confirmDeleteEvent(ev, event) { + eventCtrl.confirmDeleteEvent = function confirmDeleteEvent(ev) { var dialog = MessageService.showConfirmationDialog(ev, 'Excluir Evento', 'Este evento será removido.'); dialog.then(function () { - deleteEvent(event); + deleteEvent(eventCtrl.event); }, function () { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); }; - function deleteEvent(event) { - let promise = EventService.deleteEvent(event); + function deleteEvent() { + let promise = EventService.deleteEvent(eventCtrl.event); promise.then(function success() { - MessageService.showToast('Evento removido com sucesso!'); + MessageService.showInfoToast('Evento removido com sucesso!'); eventCtrl.event.state = "deleted"; + $state.go(STATES.EVENTS); }); return promise; } @@ -51,10 +56,13 @@ } }; - eventCtrl.canChange = function canChange(event) { - if(event) { - const hasInstitutionPermission = eventCtrl.user.hasPermission('remove_posts', event.institution_key); - const hasEventPermission = eventCtrl.user.hasPermission('remove_post', event.key); + /** + * Checks if the user has permission to change the event. + */ + eventCtrl.canChange = function canChange() { + if (eventCtrl.event) { + const hasInstitutionPermission = eventCtrl.user.hasPermission('remove_posts', eventCtrl.event.institution_key); + const hasEventPermission = eventCtrl.user.hasPermission('remove_post', eventCtrl.event.key); return hasInstitutionPermission || hasEventPermission; } }; @@ -96,8 +104,8 @@ return !(emptyPhoto || nullPhoto); } - eventCtrl.isEventAuthor = function isEventAuthor(event) { - return event && (event.author_key === eventCtrl.user.key); + eventCtrl.isEventAuthor = function isEventAuthor() { + return eventCtrl.event && (eventCtrl.event.author_key === eventCtrl.user.key); }; eventCtrl.goToEvent = function goToEvent(event) { @@ -135,7 +143,7 @@ eventCtrl.isDeleted = () => { return eventCtrl.event ? eventCtrl.event.state === 'deleted' : true; - } + }; /** * This function receives a date in iso format, @@ -148,6 +156,57 @@ return new Date(isoTime).getHours(); }; + /** + * Copies the event's link to the clipboard. + * Checks if the user is following the event. + */ + eventCtrl.copyLink = function copyLink() { + var url = Utils.generateLink(`/event/${eventCtrl.event.key}/details`); + ngClipboard.toClipboard(url); + MessageService.showInfoToast("O link foi copiado", true); + }; + + /** + * Constructs a list with the menu options. + */ + eventCtrl.generateToolbarMenuOptions = function generateToolbarMenuOptions() { + eventCtrl.defaultToolbarOptions = [ + { title: 'Obter link', icon: 'link', action: () => { eventCtrl.copyLink() } }, + { title: 'Compartilhar', icon: 'share', action: () => { eventCtrl.share('$event') } }, + { title: 'Receber atualizações', icon: 'visibility', action: () => { eventCtrl.addFollower() }, hide: () => eventCtrl.isFollower() }, + { title: 'Não receber atualizações', icon: 'visibility_off', action: () => { eventCtrl.removeFollower() }, + hide: () => !eventCtrl.isFollower() || eventCtrl.isEventAuthor() }, + { title: 'Cancelar evento', icon: 'cancel', action: () => { eventCtrl.confirmDeleteEvent('$event') }, hide: () => !eventCtrl.canChange() } + ] + }; + + /** + * Checks if the user is following the event. + */ + eventCtrl.isFollower = () => { + return eventCtrl.event && eventCtrl.event.followers.includes(eventCtrl.user.key); + }; + + /** + * Add the user as an event's follower + */ + eventCtrl.addFollower = () => { + return EventService.addFollower(eventCtrl.event.key).then(() => { + eventCtrl.event.addFollower(eventCtrl.user.key); + MessageService.showInfoToast('Você receberá as atualizações desse evento.'); + }); + }; + + /** + * Remove the user from the event's followers list + */ + eventCtrl.removeFollower = () => { + return EventService.removeFollower(eventCtrl.event.key).then(() => { + eventCtrl.event.removeFollower(eventCtrl.user.key); + MessageService.showInfoToast('Você não receberá as atualizações desse evento.'); + }); + }; + /** * This function receives the event key, makes a * request to the backend, and returns the event @@ -157,16 +216,18 @@ */ function loadEvent(eventKey) { return EventService.getEvent(eventKey).then(function success(response) { - eventCtrl.event = response; + eventCtrl.event = new Event(response); }, function error(response) { - MessageService.showToast(response); + MessageService.showErrorToast(response); $state.go(STATES.HOME); }); } - + eventCtrl.$onInit = function() { - if ($state.params.eventKey) + if ($state.params.eventKey) { + eventCtrl.generateToolbarMenuOptions(); return loadEvent($state.params.eventKey); + } }; }); diff --git a/frontend/event/eventDialogController.js b/frontend/event/eventDialogController.js index 719b14ff5..219406557 100644 --- a/frontend/event/eventDialogController.js +++ b/frontend/event/eventDialogController.js @@ -4,7 +4,7 @@ const app = angular.module("app"); app.controller('EventDialogController', function EventDialogController(MessageService, brCidadesEstados, - ImageService, AuthService, EventService, $mdMenu, $state, $rootScope, $mdDialog, $http, STATES, SCREEN_SIZES, ObserverRecorderService) { + ImageService, AuthService, EventService, $mdMenu, $state, $rootScope, $mdDialog, $http, STATES, SCREEN_SIZES, ObserverRecorderService, StateLinkRequestService, STATE_LINKS) { var dialogCtrl = this; dialogCtrl.loading = false; @@ -30,6 +30,10 @@ var saveImgPromise = saveImage(callback); }; + dialogCtrl.colorButtonSubmit = function colorButtonSubmit(formValid) { + return formValid ?'default-teal-500':'default-grey-400'; + }; + dialogCtrl.removeUrl = function (url, urlList) { _.remove(urlList, function (element) { return element === url; @@ -69,7 +73,7 @@ dialogCtrl.event.photo_url = data.url; callback(); }, function error(response) { - MessageService.showToast(response.data.msg); + MessageService.showErrorToast(response.data.msg); }); } else { callback(); @@ -85,12 +89,12 @@ EventService.editEvent(dialogCtrl.event.key, formatedPatch) .then(function success() { dialogCtrl.cancelCreation(); - MessageService.showToast('Evento editado com sucesso.'); + MessageService.showInfoToast('Evento editado com sucesso.'); }, function error() { dialogCtrl.cancelCreation(); }); } else { - MessageService.showToast('Evento inválido'); + MessageService.showErrorToast('Evento inválido'); } } @@ -122,7 +126,7 @@ dialogCtrl.deletePreviousImage = true; dialogCtrl.file = null; }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; @@ -205,7 +209,7 @@ var nextStep = currentStep + 1; dialogCtrl.steps[nextStep] = true; } else { - MessageService.showToast(dialogCtrl._getRequiredFieldsMsg()); + MessageService.showErrorToast(dialogCtrl._getRequiredFieldsMsg()); } }; @@ -361,7 +365,8 @@ dialogCtrl.startHour = new Date(dialogCtrl.event.start_time); dialogCtrl.startHour.setHours(8, 0, 0); dialogCtrl.addStartHour(); - dialogCtrl.event.end_time = new Date(dialogCtrl.event.start_time); + dialogCtrl.event.end_time = _.isNil(dialogCtrl.event.end_time) ? + new Date(dialogCtrl.event.start_time) : dialogCtrl.event.end_time; dialogCtrl.endHour = new Date(dialogCtrl.event.start_time); dialogCtrl.endHour.setHours(18, 0, 0); dialogCtrl.addEndHour(); @@ -426,14 +431,14 @@ !isMobileScreen() && dialogCtrl.events.push(response); dialogCtrl.user.addPermissions(['edit_post', 'remove_post'], response.key); dialogCtrl.cancelCreation(); - MessageService.showToast('Evento criado com sucesso!'); + MessageService.showInfoToast('Evento criado com sucesso!'); }, function error() { dialogCtrl.loading = false; dialogCtrl.blockReturnButton = false; $state.go(STATES.EVENTS); }); } else { - MessageService.showToast('Evento inválido!'); + MessageService.showErrorToast('Evento inválido!'); } } @@ -495,7 +500,7 @@ dialogCtrl.isEditing = true; dialogCtrl._loadStatesToEdit(); }, function error(response) { - MessageService.showToast("Erro ao carregar evento."); + MessageService.showErrorToast("Erro ao carregar evento."); $state.go(STATES.HOME); }); } @@ -504,8 +509,9 @@ const address = { country: "Brasil" }; getCountries(); loadFederalStates(); - initUrlFields(); dialogCtrl._loadStateParams(); + initUrlFields(); + if (dialogCtrl.event) { dialogCtrl._loadStatesToEdit(); } else if(!dialogCtrl.event && $state.params.eventKey) { @@ -513,6 +519,9 @@ } else { dialogCtrl.event = { address: address }; } + if (Utils.isMobileScreen()) { + StateLinkRequestService.showLinkRequestDialog(STATE_LINKS.CREATE_EVENT, STATES.EVENTS); + } }; }); })(); \ No newline at end of file diff --git a/frontend/event/eventPageController.js b/frontend/event/eventPageController.js index 6044c50dc..51940ab72 100644 --- a/frontend/event/eventPageController.js +++ b/frontend/event/eventPageController.js @@ -21,7 +21,7 @@ var post = new Post({}, eventCtrl.user.current_institution.key); post.shared_event = event.key; PostService.createPost(post).then(function success(response) { - MessageService.showToast('Evento compartilhado com sucesso!'); + MessageService.showInfoToast('Evento compartilhado com sucesso!'); }); }; diff --git a/frontend/event/eventService.js b/frontend/event/eventService.js index eb4dd7aa9..d71ca71bc 100644 --- a/frontend/event/eventService.js +++ b/frontend/event/eventService.js @@ -39,5 +39,25 @@ service.getMonths = function getMonths() { return HttpService.get('app/utils/months.json'); }; + + service.searchEvents = function searchEvents(value, state, type) { + return HttpService.get(`/api/search/event?value=${value}&state=${state}&type=${type}`); + }; + + /** + * Make the request to add the user as event's follower + * {String} eventKey -- the event urlsafe key. + */ + service.addFollower = function (eventKey) { + return HttpService.post(`/api/events/${eventKey}/followers`); + }; + + /** + * Make the request to remove the user from event's followers list + * {String} eventKey -- the event urlsafe key. + */ + service.removeFollower = function (eventKey) { + return HttpService.delete(`/api/events/${eventKey}/followers`); + }; }); })(); \ No newline at end of file diff --git a/frontend/event/event_card.html b/frontend/event/event_card.html new file mode 100644 index 000000000..fa368f813 --- /dev/null +++ b/frontend/event/event_card.html @@ -0,0 +1,23 @@ + +
    + +
    + +
    +
    +
    + {{ eventCardCtrl.event.title | uppercase}} +
    +
    + {{ eventCardCtrl.event.start_time | amUtc | amLocal | amDateFormat:'HH:mm' }} + {{ eventCardCtrl.event.address.city ? ' | ' + eventCardCtrl.event.address.city : ''}} +

    + {{eventCardCtrl.event.institution_name || uppercase}} +

    +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/event/event_details.html b/frontend/event/event_details.html index 96cf9314c..f067f09ad 100644 --- a/frontend/event/event_details.html +++ b/frontend/event/event_details.html @@ -33,7 +33,7 @@

    - + more_vert @@ -46,17 +46,29 @@

    - + share Compartilhar evento - + cancel Cancelar evento + + + visibility + Receber Atualizações + + + + + visibility_off + Deixar de receber atualizações + + +
    {{ eventDetailsCtrl.event.title | uppercase}} - - - - - - share - Compartilhar evento - - - - - cancel - Cancelar evento - - - -
    diff --git a/frontend/event/event_dialog.html b/frontend/event/event_dialog.html index 0ff848342..08bd64bbc 100644 --- a/frontend/event/event_dialog.html +++ b/frontend/event/event_dialog.html @@ -157,12 +157,14 @@ @@ -179,7 +181,7 @@
    Link do Youtube inválido.
    @@ -219,7 +221,7 @@ hide-gt-xs ng-if="(controller.getStep(2) || controller.getStep(3)) && !controller.loading"> voltar - + {{controller.getStep(3) ? "publicar" : "avançar"}} diff --git a/frontend/event/events.html b/frontend/event/events.html index 0029c440d..940e5a702 100644 --- a/frontend/event/events.html +++ b/frontend/event/events.html @@ -1,6 +1,6 @@
    + md-colors="{background: 'grey-50'}" style="max-height: 100%;">
    @@ -41,7 +41,7 @@

    Nenhum evento a ser exibido.

    - +
    diff --git a/frontend/event/events_mobile.html b/frontend/event/events_mobile.html index ed91f5d50..7b74d5362 100644 --- a/frontend/event/events_mobile.html +++ b/frontend/event/events_mobile.html @@ -1,50 +1,38 @@ -
    +
    -
    - -

    Nenhum evento a ser exibido.

    -
    +
    + + + +
    - +
    {{events.day}} -

    - {{eventCtrl.test(events.events[0])}} - {{events.events[0].start_time | amUtc | amDateFormat:'ddd' }} -

    +

    {{events.events[0].start_time | amUtc | amDateFormat:'ddd'}}

    - -
    - -
    -
    - {{ event.title | uppercase}} -
    -
    - {{ event.start_time | amUtc | amLocal | amDateFormat:'HH:mm' }} - {{ event.address.city ? ' | ' + event.address.city : ''}} -

    - {{event.institution_name || uppercase}} -

    -
    -
    -
    -
    +
    - Nenhum evento a ser exibido.

    add
    - \ No newline at end of file + + + + diff --git a/frontend/event/filterEvents/filterEventByInstitution.component.js b/frontend/event/filterEvents/filterEventByInstitution.component.js new file mode 100644 index 000000000..c208702b5 --- /dev/null +++ b/frontend/event/filterEvents/filterEventByInstitution.component.js @@ -0,0 +1,62 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + app.controller('FilterEventsByInstitutionController', function() { + const filterCtrl = this; + filterCtrl.originalList = []; + filterCtrl.enableAll = true; + + + /** + * This function checks if all filters are enabled + * and changes the enableAll variable to true, + * if there is at least one disabled, switch to false. + */ + filterCtrl.checkChange = function checkChange() { + filterCtrl.enableAll = (_.find(filterCtrl.filterList, institution => !institution.enable)) ? false : true; + }; + + /** + * This function enables or disables all filters, + * according to the enableAll variable + */ + filterCtrl.enableOrDisableAll = function enableOrDisableAll() { + filterCtrl.filterList.map(institution => institution.enable = filterCtrl.enableAll); + }; + + /** + * This function cancels the filter modification + * and returns it to the original state. + */ + filterCtrl.cancel = function cancel() { + filterCtrl.filterList.map((institution, index) => { + institution.enable = filterCtrl.originalList[index].enable; + }); + filterCtrl.cancelAction(); + }; + + filterCtrl.$onInit = function() { + filterCtrl.originalList = _.cloneDeep(filterCtrl.filterList); + filterCtrl.checkChange(); + }; + }); + + /** + * Filter events by institution component + * @example + * + * + */ + app.component("filterEventsByInstitution", { + templateUrl: 'app/event/filterEvents/filter_events_by_institution.html', + controller: 'FilterEventsByInstitutionController', + controllerAs: 'filterCtrl', + bindings: { + filterList: '<', + confirmAction: '<', + cancelAction: '<' + } + }); +})(); \ No newline at end of file diff --git a/frontend/event/filterEvents/filter_events_by_institution.css b/frontend/event/filterEvents/filter_events_by_institution.css new file mode 100644 index 000000000..dfb062a6f --- /dev/null +++ b/frontend/event/filterEvents/filter_events_by_institution.css @@ -0,0 +1,46 @@ +.filter-container { + display: grid; + grid-template-rows: 1fr min-content; + height: 100%; + max-height: 100%; +} + +.filter-items-container { + max-height: 100%; + overflow-y: scroll; +} + +.filter-items-container > h3 { + text-align: center; +} + +.filter-items-container > div { + display: grid; + grid-auto-rows: 1fr; +} + +.filter-item { + display: grid; + grid-template-columns: 20px auto; + grid-column-gap: 10px; + padding: 0 16px; + margin: 8px 0; + align-items: center; +} + +.filter-item > md-checkbox { + margin: 0; + text-align: center; +} + +.filter-buttons-container { + display: grid; + grid-template-columns: auto auto; + justify-content: end; + margin-bottom: 10px; +} + +.filter-cancel-button { + color: white; + background-color: #7F7F7F; +} \ No newline at end of file diff --git a/frontend/event/filterEvents/filter_events_by_institution.html b/frontend/event/filterEvents/filter_events_by_institution.html new file mode 100644 index 000000000..8a5986c49 --- /dev/null +++ b/frontend/event/filterEvents/filter_events_by_institution.html @@ -0,0 +1,20 @@ +
    +
    +

    Filtrar por institutição

    +
    +
    + + {{institution.name}} +
    +
    + + Todos os eventos +
    +
    +
    + +
    + CANCELAR + FILTRAR +
    +
    \ No newline at end of file diff --git a/frontend/event/sharedEvent.component.js b/frontend/event/sharedEvent.component.js new file mode 100644 index 000000000..d692f0112 --- /dev/null +++ b/frontend/event/sharedEvent.component.js @@ -0,0 +1,20 @@ +(function() { + 'use strict'; + + const app = angular.module('app'); + + /** + * Shared event mobile component + * + * @example + * + */ + app.component('sharedEvent', { + templateUrl: 'app/event/shared_event_mobile.html', + controller: 'EventDetailsController', + controllerAs: 'eventDetailsCtrl', + bindings: { + event: '<' + } + }); +})(); \ No newline at end of file diff --git a/frontend/event/shared_event.css b/frontend/event/shared_event.css new file mode 100644 index 000000000..1b6286307 --- /dev/null +++ b/frontend/event/shared_event.css @@ -0,0 +1,119 @@ +.shared-event__image-container { + position: relative; +} + +.shared-event__image-container--canceled { + min-height: 100px; +} + +.shared-event__image-container__img { + width: 100%; + background-color: white; +} + +.shared-event__canceled { + height: 100%; + width: 100%; + max-width: 100%; + background-color: rgba(0,153,141,.85); + top: 0; + position: absolute; + z-index: 1; +} + +.shared-event__canceled-box { + padding: 0 16px; + height: 100%; + display: grid; + color: white; + font-weight: bold; + align-content: center; + align-items: center; + justify-content: center; + grid-template-areas: 'icon title' 'icon body'; + grid-column-gap: 10px; +} + +.shared-event__canceled-box__icon { + grid-area: icon; + width: 50px; + height: 50px; + font-size: 50px; + color: white; + margin: 0; +} + +.shared-event__canceled-box__title { + grid-area: title; + margin: 0; +} + +.shared-event__canceled-box__body { + grid-area: body; + margin: 0; + font-size: 11px; +} + +.shared-event__info { + display: grid; + grid-template-columns: max-content 1fr; +} + +.shared-event__info__date { + display: grid; + grid-template-rows: auto auto auto; + justify-content: center; justify-items: center; + align-content: center; + color: white; + background-color: #8CC04E; + padding: 8px; +} + +.shared-event__info__date > h3 { + margin: 0; +} + +.shared-event__info__date__divider { + border: 1px; + border-style: solid; + width: 100%; +} + +.shared-event__info__date--active { + background-color: #8CC04E; +} + +.shared-event__info__date--canceled { + background-color: #959595; +} + +.shared-event__info_name { + background-color: #199688; + display: grid; + grid-template-rows: auto auto; + align-content: space-around; + padding: 8px; +} + +.shared-event__info_name--active { + background-color: #199688; + color: white; +} + +.shared-event__info_name--canceled { + background-color: #707070; + color: #B5B5B5; +} + +.shared-event__info_name-event { + color: white; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; +} + +.shared-event__info_name-inst { + color: white; +} \ No newline at end of file diff --git a/frontend/event/shared_event_mobile.html b/frontend/event/shared_event_mobile.html new file mode 100644 index 000000000..7b4b4fe71 --- /dev/null +++ b/frontend/event/shared_event_mobile.html @@ -0,0 +1,42 @@ +
    +
    + + +
    +
    + cancel +

    ESTE EVENTO FOI CANCELADO

    +

    + {{eventDetailsCtrl.event.last_modified_by == eventDetailsCtrl.event.author ? 'por' : 'pelo administrador'}} + {{eventDetailsCtrl.event.last_modified_by}} + {{eventDetailsCtrl.event.last_modified_date | amUtc | amLocal | amCalendar:referenceTime:formats }}. +

    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/event/validateYoutubeLinkDirective.js b/frontend/event/validateYoutubeLinkDirective.js new file mode 100644 index 000000000..0e63252a6 --- /dev/null +++ b/frontend/event/validateYoutubeLinkDirective.js @@ -0,0 +1,18 @@ +var app = angular.module('app'); +app.directive('validateYoutubeLinkDirective', function() { + return { + require: 'ngModel', + link: function(scope, element, attr, mCtrl) { + function validateLink(value) { + var regexp =/http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?/; + if (regexp.test(value)) { + mCtrl.$setValidity('pattern', true); + } else { + mCtrl.$setValidity('pattern', false); + } + return value; + } + mCtrl.$parsers.push(validateLink); + } + }; +}); \ No newline at end of file diff --git a/frontend/home/colorPickerController.js b/frontend/home/colorPickerController.js index 23f42e280..5f4d5a2d1 100644 --- a/frontend/home/colorPickerController.js +++ b/frontend/home/colorPickerController.js @@ -3,15 +3,17 @@ (function () { const app = angular.module("app"); - app.controller("ColorPickerController", function ColorPickerController(user, ProfileService, MessageService, $mdDialog, AuthService, $http) { + app.controller("ColorPickerController", function ColorPickerController(user, institution, ProfileService, MessageService, $mdDialog, AuthService, $http) { var colorPickerCtrl = this; colorPickerCtrl.user = user; + colorPickerCtrl.institution = {}; + colorPickerCtrl.oldColorValue = institution.color; colorPickerCtrl.saveColor = function saveColor() { var diff = jsonpatch.compare(colorPickerCtrl.user, colorPickerCtrl.newUser); var promise = ProfileService.editProfile(diff); promise.then(function success() { - MessageService.showToast('Cor salva com sucesso'); + MessageService.showInfoToast('Cor salva com sucesso'); colorPickerCtrl.user.institution_profiles = colorPickerCtrl.newUser.institution_profiles; $mdDialog.cancel(); AuthService.save(); @@ -26,9 +28,7 @@ function loadProfile() { colorPickerCtrl.newUser = _.cloneDeep(colorPickerCtrl.user); - colorPickerCtrl.newProfile = _.find(colorPickerCtrl.newUser.institution_profiles, function (profile) { - return profile.institution_key === colorPickerCtrl.newUser.current_institution.key; - }); + colorPickerCtrl.institution = _.find(colorPickerCtrl.newUser.institution_profiles, ['institution_key', institution.institution_key]); } function loadColors() { diff --git a/frontend/home/color_picker.css b/frontend/home/color_picker.css new file mode 100644 index 000000000..e1f43aa96 --- /dev/null +++ b/frontend/home/color_picker.css @@ -0,0 +1,34 @@ +#color-dialog { + display: grid; + padding: 1em; + grid-template-rows: 10% 1fr auto; +} + +#color-dialog-buttons { + display: grid; + grid-auto-flow: column; + grid-auto-columns: min-content; + justify-content: end; +} + +.color-picker-area { + display: grid; + grid-template-columns: repeat(4, min-content); + justify-content: space-around; +} + +.color-picker-circle { + width: 3em !important; + height: 3em !important; +} + +.color-picker-title { + color: #009688; + font-size: 1em; + justify-self: center; + align-self: center; +} + +button.color-dialog-button { + font-size: 0.7em; +} diff --git a/frontend/home/color_picker.html b/frontend/home/color_picker.html index d1a42a5d7..04353edd0 100644 --- a/frontend/home/color_picker.html +++ b/frontend/home/color_picker.html @@ -5,9 +5,9 @@

    Selecione uma cor:

    - - check_circle + check_circle diff --git a/frontend/home/color_picker_mobile.html b/frontend/home/color_picker_mobile.html new file mode 100644 index 000000000..082f31eed --- /dev/null +++ b/frontend/home/color_picker_mobile.html @@ -0,0 +1,30 @@ + + +
    + Selecione uma cor +
    +
    + + check_circle + +
    +
    +
    + + CANCELAR + + + ALTERAR + +
    +
    +
    +
    diff --git a/frontend/home/home.html b/frontend/home/home.html index 916f9945f..5c8504eb0 100644 --- a/frontend/home/home.html +++ b/frontend/home/home.html @@ -10,7 +10,7 @@
    - +
    @@ -97,7 +97,7 @@ + md-colors="{background: 'light-green-600'}"> add diff --git a/frontend/home/homeController.js b/frontend/home/homeController.js index 8390154ed..d87963006 100644 --- a/frontend/home/homeController.js +++ b/frontend/home/homeController.js @@ -3,8 +3,10 @@ (function() { var app = angular.module("app"); - app.controller("HomeController", function HomeController(AuthService, $mdDialog, - $state, EventService, ProfileService, $rootScope, POST_EVENTS, STATES) { + app.controller("HomeController", ['AuthService', '$mdDialog', '$state', 'EventService', 'ProfileService', '$rootScope', + 'POST_EVENTS', 'STATES', + function HomeController(AuthService, $mdDialog, $state, EventService, ProfileService, $rootScope, + POST_EVENTS, STATES) { var homeCtrl = this; var LIMITE_EVENTS = 5; @@ -13,8 +15,6 @@ homeCtrl.followingInstitutions = []; homeCtrl.isLoadingPosts = true; homeCtrl.showMessageOfEmptyEvents = true; - - homeCtrl.user = AuthService.getCurrentUser(); homeCtrl.eventInProgress = function eventInProgress(event) { var end_time = event.end_time; @@ -122,10 +122,11 @@ $rootScope.$broadcast(eventType, post); } - (function main() { + homeCtrl.$onInit = () => { + homeCtrl.user = AuthService.getCurrentUser(); loadEvents(); getFollowingInstitutions(); registerPostEvents(); - })(); - }); + }; + }]); })(); \ No newline at end of file diff --git a/frontend/home/post_dialog.html b/frontend/home/post_dialog.html index cfe7675b5..83821f8db 100644 --- a/frontend/home/post_dialog.html +++ b/frontend/home/post_dialog.html @@ -1,4 +1,4 @@ - + diff --git a/frontend/imageUpload/cropImageController.js b/frontend/imageUpload/cropImageController.js index 5a9ef04f9..0f1ed2377 100644 --- a/frontend/imageUpload/cropImageController.js +++ b/frontend/imageUpload/cropImageController.js @@ -56,7 +56,7 @@ if(ImageService.isValidImage(image_file)) { readImage(image_file); } else { - MessageService.showToast("Imagem deve ser jpg ou png e menor que 5 Mb"); + MessageService.showErrorToast("Imagem deve ser jpg ou png e menor que 5 Mb"); cropImgCtrl.cancelCrop(); } })(); diff --git a/frontend/images/desenho-cis.png b/frontend/images/desenho-cis.png new file mode 100644 index 000000000..958e63f9a Binary files /dev/null and b/frontend/images/desenho-cis.png differ diff --git a/frontend/images/edit.png b/frontend/images/edit.png new file mode 100644 index 000000000..a275fe722 Binary files /dev/null and b/frontend/images/edit.png differ diff --git a/frontend/index.html b/frontend/index.html index 51414ee86..da800e6c1 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -37,12 +37,13 @@ - - + + + @@ -56,17 +57,41 @@ + + + + - + + + + + + + + + + + + + + + + + + + + + @@ -161,7 +186,11 @@ + + + + @@ -179,8 +208,9 @@ - + + @@ -200,6 +230,7 @@ + @@ -213,17 +244,22 @@ + + + + + - - + + @@ -231,6 +267,16 @@ + + + + + + + + + + @@ -272,6 +318,7 @@ + @@ -280,7 +327,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/institution/allInstitutionsController.js b/frontend/institution/allInstitutionsController.js index 7f056b9f8..da746c2ea 100644 --- a/frontend/institution/allInstitutionsController.js +++ b/frontend/institution/allInstitutionsController.js @@ -24,11 +24,13 @@ * {string} nextTab */ allInstitutionsCtrl.changeTab = function changeTab(nextTab) { - allInstitutionsCtrl.currentTab = ( - possibleTabs.includes(nextTab) ? nextTab : allInstitutionsCtrl.currentTab); - - currentPage = 0; - loadInstitutions(); + if (nextTab !== allInstitutionsCtrl.currentTab) { + allInstitutionsCtrl.currentTab = ( + possibleTabs.includes(nextTab) ? nextTab : allInstitutionsCtrl.currentTab); + + currentPage = 0; + return loadInstitutions(); + } }; /** diff --git a/frontend/institution/base_institution.css b/frontend/institution/base_institution.css index 7049ce4f0..5781fe439 100644 --- a/frontend/institution/base_institution.css +++ b/frontend/institution/base_institution.css @@ -19,6 +19,12 @@ padding: 5px; } +.base-content-inst{ + height: 100%; + position: absolute; + width: 100%; +} + .timeline-z-index{ z-index: 1; } @@ -86,7 +92,11 @@ .icon-button-menu-inst{ color: #FFFFFF; font-size: 20px; - margin-left: 0.5em; + margin: 0; +} + +.vert-button-navbar-inst { + display: inherit !important; } .institution-button-menu{ @@ -99,10 +109,6 @@ height: 0px; } -.btn-follow-unfollow{ - margin-right: -20px; -} - #buttons-navbar-inst-container{ position: relative; display: grid; @@ -114,7 +120,7 @@ #buttons-navbar-inst-container-end{ padding-top: 5px; display: grid; - grid-template-columns: 107px auto auto; + grid-template-columns: min-content auto min-content; align-items: center; justify-content: end; overflow-x:hidden; @@ -134,7 +140,8 @@ } #btn-more{ - width: 48px; + margin: 0; + padding: 0; } #btn-edit{ @@ -165,9 +172,6 @@ .button-navbar-inst{ font-size: 12px; } - #btn-more{ - margin-left: -20px; - } } @media screen and (min-height: 620px) and (max-height:660px){ diff --git a/frontend/institution/base_institution_page_mobile.html b/frontend/institution/base_institution_page_mobile.html index d8c3059f4..298722027 100644 --- a/frontend/institution/base_institution_page_mobile.html +++ b/frontend/institution/base_institution_page_mobile.html @@ -1,4 +1,4 @@ - +
    @@ -16,7 +16,8 @@
    + class="institution-button-menu" + ng-disabled="button.isDisabled"> {{button.icon}} {{button.label}} @@ -26,7 +27,8 @@
    -
    +
    diff --git a/frontend/institution/configInstDirective.js b/frontend/institution/configInstitution/configInstDirective.js similarity index 93% rename from frontend/institution/configInstDirective.js rename to frontend/institution/configInstitution/configInstDirective.js index 2f8f13714..6ef403f2c 100644 --- a/frontend/institution/configInstDirective.js +++ b/frontend/institution/configInstitution/configInstDirective.js @@ -3,7 +3,7 @@ var app = angular.module("app"); app.controller("ConfigInstController", function ConfigInstController(AuthService, InstitutionService, CropImageService,$state, $mdDialog, $http, STATES, ImageService, $rootScope, MessageService, PdfService, $q, $window, - RequestInvitationService, brCidadesEstados, ObserverRecorderService) { + RequestInvitationService, brCidadesEstados, ObserverRecorderService, StateLinkRequestService, STATE_LINKS) { var configInstCtrl = this; var institutionKey = $state.params.institutionKey; @@ -84,7 +84,7 @@ ImageService.readFile(data, setImage); configInstCtrl.file = null; }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); return promise; }; @@ -122,10 +122,10 @@ configInstCtrl.loadingSaveInstitution = true; updateInstitution(); }, function error() { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); } else { - MessageService.showToast("Campos obrigatórios não preenchidos corretamente."); + MessageService.showErrorToast("Campos obrigatórios não preenchidos corretamente."); } return promise; }; @@ -139,7 +139,7 @@ configInstCtrl.newInstitution.photo_url = data.url; defer.resolve(); }, function error(response) { - MessageService.showToast(response.data.msg); + MessageService.showErrorToast(response.data.msg); defer.reject(); }); } else { @@ -157,7 +157,7 @@ currentPortfoliourl = data.url; defer.resolve(); }, function error(response) { - MessageService.showToast(response.data.msg); + MessageService.showErrorToast(response.data.msg); defer.reject(); }); } else { @@ -184,7 +184,7 @@ $q.resolve(promise); }, function error(response) { configInstCtrl.isSubmitting = false; - MessageService.showToast(response.data.msg); + MessageService.showErrorToast(response.data.msg); $q.reject(promise); }); return promise; @@ -253,7 +253,7 @@ function saveRequestInst() { RequestInvitationService.sendRequestInst(configInstCtrl.newInstitution).then( function success() { - MessageService.showToast("Pedido enviado com sucesso!"); + MessageService.showInfoToast("Pedido enviado com sucesso!"); configInstCtrl.nextStep(); }); } @@ -264,7 +264,7 @@ AuthService.save(); changeInstitution(institution); configInstCtrl.loadingSaveInstitution = false; - MessageService.showToast('Dados da instituição salvos com sucesso.'); + MessageService.showInfoToast('Dados da instituição salvos com sucesso.'); showHierarchyDialog(institution); $state.go(STATES.HOME); } @@ -294,7 +294,7 @@ var nextStep = currentStep + 1; configInstCtrl.steps[nextStep] = true; } else { - MessageService.showToast("Campos obrigatórios não preenchidos corretamente."); + MessageService.showErrorToast("Campos obrigatórios não preenchidos corretamente."); } }; @@ -468,19 +468,27 @@ } else { $state.go(STATES.SIGNIN); } + if (Utils.isMobileScreen()) { + StateLinkRequestService.showLinkRequestDialog(getInstEditLink(), STATES.MANAGE_INST); + } }; + function getInstEditLink () { + return STATE_LINKS.MANAGE_INSTITUTION.replace("INSTITUTION_KEY", configInstCtrl.institutionKey); + } + (function main(){ configInstCtrl.institutionKey = institutionKey; configInstCtrl.initController(); })(); }); - app.directive("configInstitution", function() { + app.directive("configInstitution", function(SCREEN_SIZES) { return { restrict: 'E', - templateUrl: Utils.selectFieldBasedOnScreenSize("app/institution/submit_form.html", - "app/institution/edit_registration_data.html", 475), + templateUrl: Utils.selectFieldBasedOnScreenSize( + "app/institution/configInstitution/submit_form.html", + "app/institution/configInstitution/edit_registration_data.html", SCREEN_SIZES.SMARTPHONE), controller: "ConfigInstController", controllerAs: "configInstCtrl", scope: {}, diff --git a/frontend/institution/edit_registration_data.html b/frontend/institution/configInstitution/edit_registration_data.html similarity index 97% rename from frontend/institution/edit_registration_data.html rename to frontend/institution/configInstitution/edit_registration_data.html index d00a9c2c1..8c47749ac 100644 --- a/frontend/institution/edit_registration_data.html +++ b/frontend/institution/configInstitution/edit_registration_data.html @@ -1,9 +1,6 @@ -
    - - keyboard_arrow_left - -

    EDITAR DADOS CADASTRAIS

    -
    + +
    { + return ctrl.currentStep === step ? 'light-green-500' : 'grey-500'; + }; + + ctrl.backButton = () => { + ctrl.currentStep === 0 ? window.history.back() : ctrl.previousStep(); + } + + /** + * Loads the "empty" institution from InstitutionService and sets its default values. + * This consists of a address with Brasil as a country, and the suggested name from inviter. + * Sets an ObserverRecorderService required to generate a json patch later (when the institution is finally saved); + * + * @returns {Promise} - InstituionService promise; + */ + ctrl.loadInstitution = () => { + return InstitutionService.getInstitution(ctrl.institutionKey).then(res => { + ctrl.newInstitution = res; + ctrl.suggestedName = res.name; + observer = ObserverRecorderService.register(ctrl.newInstitution); + + // Set default values + ctrl.newInstitution.address = new Address(res.address); + ctrl.newInstitution.address.country = ctrl.newInstitution.address.country || 'Brasil'; + ctrl.newInstitution.photo_url = ctrl.newInstitution.photo_url || 'app/images/institution.png'; + ctrl.loading = false; + }, e => { + ctrl.loading = false; + MessageService.showErrorToast(e); + }) + } + + /** + * Validates the current form step, based on required fields. + * 1st step: requires a valid address. For institutions on Brazil, + * this requires a valid street, federal_state, neighbourhood, city and cep. + * For foreign institutions, this only requires a country. + * 2nd step: requires a name, institutional_email, legal_nature and actuation_area. + * 3rd step: requires a description and a leader. + * + * @returns {Boolean} - if the step is valid or not + */ + ctrl.isCurrentStepValid = () => { + const step = ctrl.currentStep; + const institution = ctrl.newInstitution; + + const testValids = (obj, ...fields) => { + let valid = true; + _.forEach(fields, f => { + if (_.isUndefined(obj[f]) || _.isEmpty(obj[f])) { + valid = false; + }; + }) + return valid; + } + + const validAddress = () => { + const address = institution.address; + if (address && !_.isEmpty(address.country)) { + if (address.country === 'Brasil') { + return testValids(address, 'street', 'federal_state', 'neighbourhood', + 'city', 'cep'); + } else { + return true; + } + } + return false; + } + + const stepValidation = { + 0: validAddress(), + 1: testValids(institution, 'name', 'actuation_area', 'legal_nature', + 'institutional_email'), + 2: testValids(institution, 'description', 'leader'), + } + + return stepValidation[step]; + }; + + ctrl.nextStep = () => { + if (ctrl.isCurrentStepValid()) { + ctrl.currentStep += 1; + } else { + MessageService.showErrorToast("Campos obrigatórios não preenchidos corretamente."); + } + } + + ctrl.previousStep = () => { + if (ctrl.currentStep === 0) return; + ctrl.currentStep -= 1; + } + + Object.defineProperty(ctrl, 'currentStepLabel', { + get: function() { + const labels = { + 0: 'Dados Cadastrais', + 1: 'Dados da Instituição', + 2: 'Finalizar Cadastro', + } + return labels[ctrl.currentStep]; + } + }) + + /** + * Callback when the photo is changed on institutionInfo.component + * + * ctrl.photoSrc is needed to save the image later (when the Institution is finally saved). + */ + ctrl.onNewPhoto = (photoSrc) => { + ctrl.photoSrc = photoSrc; + } + + /** + * Submits current institution info and tries to save it. + * Calls a chain of promises to deal with Institution saving, updating, + * and User updating. + * + * @params {Event} event - current click event + */ + ctrl.submit = (event) => { + const newInstitution = new Institution(ctrl.newInstitution); + + if (ctrl.isCurrentStepValid() && newInstitution.isValid()) { + const inviteKey = $state.params.inviteKey; + const instKey = ctrl.institutionKey; + const senderName = $state.params.senderName; + const dialogParent = angular.element('#create-inst-content'); + + return showConfirmationDialog(event, dialogParent).then(() => { + ctrl.loading = true; + return saveProfileImage(ctrl.photoSrc); + }).then(() => { + return saveAndUpdateInst(inviteKey, instKey, senderName); + }).then(() => { + return reloadAndRedirectHome(); + }).catch(e => { + ctrl.loading = false; + MessageService.showErrorToast(e); + }) + } else { + MessageService.showErrorToast("Campos obrigatórios não preenchidos corretamente."); + } + } + + /** + * Saves a image file as profile for the current institution. + * If src is non existant (meaning user has not chosen a new profile picture), + * this method bails out and resolves a Promise with nothing. + * Otherwise, sets the Image through ImageService and resolves it. + * @param {Image} src - current institutions image file (resized) + * + * @returns {Promise} - a Promise resolving with nothing + */ + function saveProfileImage(src) { + if (!src) { + return Promise.resolve() + } + + return ImageService.saveImage(src).then(data => { + ctrl.newInstitution.photo_url = data.url; + }); + } + + /** + * Reloads the current user through AuthService, as needed to set this new Institution + * as the User's current institution and update this info through the app and local storage. + * Then, sends the user back to STATE.HOME with a confirmation message. + */ + function reloadAndRedirectHome() { + // Check if institution is currently a superior + const message = _.isEqual(ctrl.invite.type_of_invite, 'INSTITUTION_PARENT') ? + 'Estamos processando suas permissões hierárquicas. Em breve você receberá uma notificação e ficará habilitado para administrar a instituição e toda sua hierarquia na Plataforma Virtual CIS.' + : + 'A instituição foi criada e já se encontra habilitada na Plataforma Virtual CIS.' + + return AuthService.reload().then(() => { + return $state.go(STATES.HOME).then(() => { + ctrl.loading = false; + const alert = $mdDialog.alert({ + title: 'INSTITUIÇÃO CRIADA', + textContent: message, + ok: 'Fechar' + }); + return $mdDialog.show(alert); + }); + }); + } + + /** + * Shows a confirmation dialog asking the user about saving this new institution. + * @param {Event} event - click event from DOM + * @param {DOMElement} parent - parent element for the modal + * + * @returns {Promise} $mdDialog Promise + */ + function showConfirmationDialog(event, parent) { + const confirm = $mdDialog.confirm(event) + .parent(parent) + .clickOutsideToClose(true) + .title('FINALIZAR') + .textContent('Você deseja finalizar e salvar os dados da instituição?') + .ariaLabel('Finalizar') + .targetEvent(event) + .ok('Sim') + .cancel('Não'); + return $mdDialog.show(confirm); + } + + /** + * Saves a (stub) institution, then promptly update it with info from the previous forms. + * Calls #updateUser at the end. + * @param {string} inviteKey - of current institution + * @param {String} instKey - of current institution + * @param {String} senderName - name of the current user + * + * @return {Promise} - InstitutionService#update promise. + */ + function saveAndUpdateInst(inviteKey, instKey, senderName) { + const patch = ObserverRecorderService.generate(observer); + const body = { sender_name: senderName } + + return InstitutionService.save(body, instKey, inviteKey).then(()=> { + return InstitutionService.update(instKey, patch).then((updatedInst) => { + updateUser(inviteKey, updatedInst); + }); + }); + } + + /** + * Updates the current User, setting up the created institution (and it as user's current), + * removing its invite key and saving it through AuthService. + * @param {String} key - invite key + * @param {Institution} inst - created institution + * + * Replaces: + * #updateUser + */ + function updateUser(key, inst) { + ctrl.user.removeInvite(key); + ctrl.user.institutions.push(inst); + ctrl.user.institutions_admin.push(inst.key); + ctrl.user.follow(inst); + ctrl.user.addProfile(createProfile(inst)); + ctrl.user.changeInstitution(inst); + AuthService.save(); + } + + /** + * Creates a new "empty" profile for the institution. + * @param {Institution} inst - Institution to generate profile + * + * Replaces: + * #createProfile + * + * @returns {Object} - An empty institution profile + */ + function createProfile(inst) { + return { + email: null, + institution_key: inst.key, + institution: { + name: inst.name, + photo_url: inst.photo_url, + }, + office: 'Administrador', + phone: null, + color: 'teal' + }; + } + + /** + * Initializes the controller, setting current user and institution key. + * Redirects if there's no institution key. + * + * Replaces: + * #main + * #initController + * #setDefaultPhotoUrl + */ + ctrl.$onInit = () => { + ctrl.user = AuthService.getCurrentUser(); + ctrl.institutionKey = $state.params.institutionKey; + const inviteKey = $state.params.inviteKey; + InviteService.getInvite(inviteKey).then(res => { + ctrl.invite = res; + }) + if (ctrl.institutionKey) { + ctrl.loadInstitution(ctrl.institutionKey) + } else { + $state.go(STATES.HOME); + } + } + }]); +})(); diff --git a/frontend/institution/create_inst_form_mobile.css b/frontend/institution/create_inst_form_mobile.css new file mode 100644 index 000000000..201a5b755 --- /dev/null +++ b/frontend/institution/create_inst_form_mobile.css @@ -0,0 +1,112 @@ +md-content.grid-fill-screen { + display: grid; + height: 100%; +} + +#create-inst-content { + display: grid; + align-content: center; + justify-items: center; +} + +#form-steps { + position: fixed; + top: 0; + width: 100%; + height: 3em; + background: white; + display: grid; + grid-auto-flow: column; + grid-auto-columns: min-content; + justify-content: space-around; + align-content: center; + z-index: 10; + box-shadow: 0px 2px 4px #00000022; +} + +#form-steps > span { + display: grid; + align-content: center; + width: 2em; + height: 2em; + border-radius: 50%; +} + +#form-steps > span > p { + color: white; + position: relative; + text-align: center; +} + +#form-steps > hr { + align-self: center; + margin-left: -1em; + margin-right: -1em; + width: 4em; + height: 0; +} + +.ec-card { + width: 90%; + background: #ffffff; + border-radius: 0.2em; + align-content: center; + justify-items: center; + display: grid; + color: black; + padding: 0.5em; + margin-bottom: 2em; + margin-top: 1em; +} + +#create-inst-card { + margin-top: 3.5em; + margin-bottom: 1.6em; +} + +#create-inst-card-content { + display: grid; + grid-template-rows: 2.6em 1fr 3em 2em; + width: 90%; + align-items: center; + justify-items: center; + color: black; + padding: 1em; +} + +#create-inst-card-content > h1 { + font-size: 1.2em; + font-weight: 500; + text-transform: uppercase; + justify-self: start; + margin-left: 0.4em; +} + +#create-inst-card-content > #forward-button { + justify-self: end; + margin-right: 0; +} + +#create-inst-card-content > #back-button { + margin-bottom: -4.5em; +} + +#form-switch { + width: 100%; + margin-top: 1em; +} + +#create-inst-content button.md-primary { + color: #009688 !important; +} + +.loading-container { + display: grid; + height: 10em; + align-content: center; + justify-content: center; +} + +.loading-container load-circle svg path { + stroke: #009688 !important; +} diff --git a/frontend/institution/create_inst_form_mobile.html b/frontend/institution/create_inst_form_mobile.html new file mode 100644 index 000000000..8c04cb2bf --- /dev/null +++ b/frontend/institution/create_inst_form_mobile.html @@ -0,0 +1,56 @@ + +
    + +
    +

    {{ 1 }}

    +
    +

    {{ 2 }}

    +
    +

    {{ 3 }}

    +
    + +
    +
    + +
    +
    +

    {{ ctrl.currentStepLabel }}

    + +
    + + + + + + + + + +
    + + + Próximo + + + Finalizar + + + + keyboard_arrow_left + +
    +
    +
    +
    diff --git a/frontend/institution/descriptionInst/descriptionController.js b/frontend/institution/descriptionInst/descriptionController.js new file mode 100644 index 000000000..e158d6f46 --- /dev/null +++ b/frontend/institution/descriptionInst/descriptionController.js @@ -0,0 +1,26 @@ +(function(){ + const app = angular.module('app'); + + app.controller("DescriptionInstController", function DescriptionInstController($state, InstitutionService, $rootScope){ + const descriptionCtrl = this; + descriptionCtrl.isLoading = false; + + descriptionCtrl.$onInit = () => { + descriptionCtrl.isLoading = true; + InstitutionService.getInstitution($state.params.institutionKey).then(function(institution){ + descriptionCtrl.institution = institution; + descriptionCtrl.isLoading = false; + }) + }; + + /** Listenner edit description inst event, and should refresh institution. + */ + $rootScope.$on('EDIT_DESCRIPTION_INST', () => { + descriptionCtrl.isLoading = true; + InstitutionService.getInstitution($state.params.institutionKey).then(function(institution){ + descriptionCtrl.institution = institution; + descriptionCtrl.isLoading = false; + }) + }); + }); +})(); \ No newline at end of file diff --git a/frontend/institution/descriptionInst/description_inst.css b/frontend/institution/descriptionInst/description_inst.css new file mode 100644 index 000000000..da916d95d --- /dev/null +++ b/frontend/institution/descriptionInst/description_inst.css @@ -0,0 +1,65 @@ +#textarea-edit-description{ + height: 100% !important; + border-style: solid; + border-width: 1px; + border-color: black; + border-radius: 5px; + padding: 0.5em; + overflow-y: scroll; +} + +#label-edit-description{ + font-weight: bold; + font-size: 25px; + color:black; +} + +.height-dialog{ + max-height: 90%; +} + +.description-inst{ + padding: 0px 1.5em; + margin-right: auto; + word-break: break-all; +} + +.button-confirm-describe{ + justify-self: end; + margin: 0em; +} + +.dialog-edit-description{ + padding: 2em 1em 1em 1em; + display: grid; + grid-template-rows: 2.5em 1fr 3.5em; + width: 16em; + height: 100%; +} + +.margin-zero{ + margin: 0px; +} + +.input-edit-desciption .md-resize-wrapper{ + height: 100%; +} + +.input-edit-desciption{ + height: 22em; +} + +@media screen and (max-height:570px){ + .dialog-edit-description{ + width: 14em; + } + .input-edit-desciption{ + height: 18em; + } +} + +@media screen and (min-height:700px){ + .input-edit-desciption{ + height: 26em; + } +} \ No newline at end of file diff --git a/frontend/institution/descriptionInst/description_inst.html b/frontend/institution/descriptionInst/description_inst.html new file mode 100644 index 000000000..3fae1d257 --- /dev/null +++ b/frontend/institution/descriptionInst/description_inst.html @@ -0,0 +1,6 @@ +
    + +
    +

    {{descriptionCtrl.institution.description}}

    +
    +
    \ No newline at end of file diff --git a/frontend/institution/descriptionInst/editDescriptionController.js b/frontend/institution/descriptionInst/editDescriptionController.js new file mode 100644 index 000000000..db6ec45b2 --- /dev/null +++ b/frontend/institution/descriptionInst/editDescriptionController.js @@ -0,0 +1,29 @@ +(function(){ + const app = angular.module('app'); + + app.controller("EditDescriptionController",['institution', 'InstitutionService', + '$rootScope', '$mdDialog', function EditDescriptionController(institution, InstitutionService, + $rootScope, $mdDialog){ + const descriptionCtrl = this; + + descriptionCtrl.$onInit = () => { + descriptionCtrl.institution = institution; + descriptionCtrl.institutionClone = _.cloneDeep(institution); + }; + + /** Save changes of institution and emit event. + */ + descriptionCtrl.save = () => { + const clone = JSON.parse(angular.toJson(descriptionCtrl.institutionClone)); + const modified = JSON.parse(angular.toJson(descriptionCtrl.institution)); + const patch = jsonpatch.compare(clone, modified); + + InstitutionService.update(descriptionCtrl.institution.key, patch).then( + function success() { + $rootScope.$emit('EDIT_DESCRIPTION_INST'); + $mdDialog.hide(); + } + ); + } + }]); +})(); \ No newline at end of file diff --git a/frontend/institution/descriptionInst/edit_description.html b/frontend/institution/descriptionInst/edit_description.html new file mode 100644 index 000000000..714dc6b24 --- /dev/null +++ b/frontend/institution/descriptionInst/edit_description.html @@ -0,0 +1,12 @@ + +
    + + + + + + CONFIRMAR + +
    +
    \ No newline at end of file diff --git a/frontend/institution/edit_info.html b/frontend/institution/editInfo/edit_info.html similarity index 100% rename from frontend/institution/edit_info.html rename to frontend/institution/editInfo/edit_info.html diff --git a/frontend/institution/edit_info_mobile.html b/frontend/institution/editInfo/edit_info_mobile.html similarity index 100% rename from frontend/institution/edit_info_mobile.html rename to frontend/institution/editInfo/edit_info_mobile.html diff --git a/frontend/institution/forms/addressForm.component.js b/frontend/institution/forms/addressForm.component.js new file mode 100644 index 000000000..876ead2f1 --- /dev/null +++ b/frontend/institution/forms/addressForm.component.js @@ -0,0 +1,48 @@ +'use strict'; + +(function () { + function AddressFormController(brCidadesEstados, HttpService) { + const ctrl = this; + ctrl.states = {}; + ctrl.countries = {}; + ctrl.cities = {}; + + ctrl.numberRegex = /\d+$/; + ctrl.cepRegex = /\d{5}\-\d{3}/; + + Object.defineProperty(ctrl, 'isAnotherCountry', { + get: function() { + return ctrl.address && ctrl.address.country !== 'Brasil'; + } + }); + + Object.defineProperty(ctrl, 'cities', { + get: function() { + if (ctrl.address && !ctrl.isAnotherCountry) { + const currentState = _.find(brCidadesEstados.estados, + e => _.isEqual(e.nome, ctrl.address.federal_state)) + if (currentState) { + return currentState.cidades; + } + } + } + }); + + ctrl.$onInit = () => { + ctrl.states = brCidadesEstados.estados; + HttpService.get('app/institution/countries.json').then(res => { + ctrl.countries = res; + }); + } + } + + const app = angular.module('app'); + app.component('addressForm', { + controller: AddressFormController, + controllerAs: 'ctrl', + templateUrl: 'app/institution/forms/address_form.html', + bindings: { + address: '=', + } + }); +})(); diff --git a/frontend/institution/forms/address_form.html b/frontend/institution/forms/address_form.html new file mode 100644 index 000000000..7a621b3d4 --- /dev/null +++ b/frontend/institution/forms/address_form.html @@ -0,0 +1,64 @@ +
    + + + + + + + + + + + + + + + + + {{ country.nome_pais }} + + + + + + + + + + + + {{ state.sigla }} + + + + + + + + + + + + + {{ city }} + + +
    +
    + Primeiro selecione um estado +
    +
    +
    + + + + +
    diff --git a/frontend/institution/forms/forms.css b/frontend/institution/forms/forms.css new file mode 100644 index 000000000..d56f60acd --- /dev/null +++ b/frontend/institution/forms/forms.css @@ -0,0 +1,98 @@ +address-form #address-form { + display: grid; + grid-template-areas: + "street street street" + "number neighbourhood neighbourhood" + "country state city" + "cep cep cep"; + grid-template-columns: repeat(3, calc(100%/3)); + grid-template-rows: repeat(4, 1fr); +} + +#address-form #street { + grid-area: street; +} + +#address-form #number { + grid-area: number; +} + +#address-form #neighbourhood { + grid-area: neighbourhood; +} + +#address-form #city { + grid-area: city; +} + +#address-form #state { + grid-area: state; +} + +#address-form #country { + grid-area: country; +} + +#address-form #cep { + grid-area: cep; +} + +.field-required { + font-size: 0.6em; + line-height: 1em; + overflow: visible; +} + +.limit-md-select { + justify-self: center; + display: grid; +} + +institution-form #institution-form { + display: grid; + grid-template-rows: auto repeat(7, 1fr); + height: 100%; + width: 100%; +} + +last-info-form #last-info-form { + display: grid; + grid-template-rows: 8em 1fr 1fr; +} + +#last-info-form md-input-container#description { + max-height: 80%; + height: 100%; + align-items: center; + border: 1px solid; + border-color: #ccc; + border-radius: 0.4em; + margin-top: 1em; + margin-bottom: 1em; +} + +#last-info-form #description textarea { + height: 100% !important; + border: 0 !important; +} + +.ec-form md-input-container { + margin: 0.2em 0 0.2em 0; +} + +.ec-form md-input-container.md-input-focused input { + border-color: #009688; +} + +.ec-form .md-select-icon { + color: #8cbf4d; +} + +.ec-form md-input-container .md-errors-spacer { + height: 0.2em; +} + +.ec-form md-input-container label { + color: #1f6357; + font-weight: 500; +} diff --git a/frontend/institution/forms/institutionForm.component.js b/frontend/institution/forms/institutionForm.component.js new file mode 100644 index 000000000..c5f79fe86 --- /dev/null +++ b/frontend/institution/forms/institutionForm.component.js @@ -0,0 +1,50 @@ +'use strict'; + +(function () { + function InstitutionFormController(CropImageService, ImageService, MessageService, $scope, InstitutionService) { + const ctrl = this; + ctrl.institution = {}; + ctrl.pictureFile = {}; + ctrl.actuationAreas = {}; + ctrl.legalNatures = {}; + ctrl.numberRegex = /\d+$/ + ctrl.phoneRegex = /\d{2}\s\d{4,5}\-\d{4,5}/ + + ctrl.cropThenSetImage = (event) => { + CropImageService.crop(ctrl.pictureFile, event).then((cropped) => { + const size = 800; + ImageService.compress(cropped, size).then((resized) => { + ctrl.onNewPhoto({photoSrc: resized}); + ImageService.readFile(resized, (img) => { + ctrl.institution.photo_url = img.src; + ctrl.pictureFile = null; + $scope.$apply(); + }); + }); + }).catch(e => { + MessageService.showErrorToast(e); + ctrl.pictureFile = null; + }); + } + + ctrl.$onInit = () => { + InstitutionService.getLegalNatures().then(res => { + ctrl.legalNatures = res; + }); + InstitutionService.getActuationAreas().then(res => { + ctrl.actuationAreas = res; + }); + } + } + + const app = angular.module('app'); + app.component('institutionForm', { + controller: ['CropImageService', 'ImageService', 'MessageService', '$scope', 'InstitutionService', InstitutionFormController], + controllerAs: 'ctrl', + templateUrl: 'app/institution/forms/institution_form.html', + bindings: { + institution: '=', + onNewPhoto: '&', + } + }); +})(); diff --git a/frontend/institution/forms/institution_form.html b/frontend/institution/forms/institution_form.html new file mode 100644 index 000000000..bca6cbada --- /dev/null +++ b/frontend/institution/forms/institution_form.html @@ -0,0 +1,88 @@ +
    + + + + + + +
    +
    Este campo é obrigatório!
    +
    +
    + + + +
    +
    Este campo é obrigatório!
    +
    O email deve ser válido!
    +
    +
    + + + + + + + + {{ value }} + + +
    +
    Este campo é obrigatório!
    +
    +
    + + + + {{ value }} + + +
    +
    Este campo é obrigatório!
    +
    +
    + + + +
    +
    O número de telefone deve ser válido!
    +
    +
    + + + +
    +
    O ramal deve ser válido!
    +
    +
    +
    diff --git a/frontend/institution/forms/lastInfoForm.component.js b/frontend/institution/forms/lastInfoForm.component.js new file mode 100644 index 000000000..0cbaf1683 --- /dev/null +++ b/frontend/institution/forms/lastInfoForm.component.js @@ -0,0 +1,16 @@ +'use strict'; + +(function () { + function LastInfoController() { + } + + const app = angular.module('app'); + app.component('lastInfoForm', { + controller: [LastInfoController], + controllerAs: 'ctrl', + templateUrl: 'app/institution/forms/last_info_form.html', + bindings: { + institution: '=', + } + }); +})(); diff --git a/frontend/institution/forms/last_info_form.html b/frontend/institution/forms/last_info_form.html new file mode 100644 index 000000000..ab71cd814 --- /dev/null +++ b/frontend/institution/forms/last_info_form.html @@ -0,0 +1,26 @@ +
    + + + + + + + + + + + + +
    +
    Este campo é obrigatório!
    +
    +
    +
    diff --git a/frontend/institution/institutionCardDirective.js b/frontend/institution/institutionCardDirective.js index bcdb50796..559027f7b 100644 --- a/frontend/institution/institutionCardDirective.js +++ b/frontend/institution/institutionCardDirective.js @@ -28,7 +28,7 @@ institutionCardCtrl.copyLink = function copyLink(){ var url = Utils.generateLink(URL_INSTITUTION + institutionCardCtrl.institution.key + "/home"); ngClipboard.toClipboard(url); - MessageService.showToast("O link foi copiado"); + MessageService.showInfoToast("O link foi copiado", true); }; institutionCardCtrl.showFollowButton = function showFollowButton() { @@ -40,7 +40,7 @@ institutionCardCtrl.follow = function follow(){ var promise = InstitutionService.follow(institutionCardCtrl.institution.key); promise.then(function success(){ - MessageService.showToast("Seguindo "+ institutionCardCtrl.institution.name); + MessageService.showInfoToast("Seguindo "+ institutionCardCtrl.institution.name); institutionCardCtrl.user.follow(institutionCardCtrl.institution); AuthService.save(); }); @@ -49,13 +49,13 @@ institutionCardCtrl.unfollow = function unfollow() { if (institutionCardCtrl.user.isMember(institutionCardCtrl.institution.key)){ - MessageService.showToast("Você não pode deixar de seguir " + institutionCardCtrl.institution.name); + MessageService.showErrorToast("Você não pode deixar de seguir " + institutionCardCtrl.institution.name); } else { var promise = InstitutionService.unfollow(institutionCardCtrl.institution.key); promise.then(function success(){ institutionCardCtrl.user.unfollow(institutionCardCtrl.institution); AuthService.save(); - MessageService.showToast("Deixou de seguir "+institutionCardCtrl.institution.name); + MessageService.showInfoToast("Deixou de seguir "+institutionCardCtrl.institution.name, true); }); return promise; } @@ -70,7 +70,7 @@ $mdDialog.show({ controller: "RequestInvitationController", controllerAs: "requestInvCtrl", - templateUrl: 'app/requests/request_invitation_dialog.html', + templateUrl: InstitutionService.getRequestInvitationTemplate(), parent: angular.element(document.body), targetEvent: event, locals: { diff --git a/frontend/institution/institutionController.js b/frontend/institution/institutionController.js index 7f678fc57..7a4c73960 100644 --- a/frontend/institution/institutionController.js +++ b/frontend/institution/institutionController.js @@ -58,7 +58,8 @@ 'label': 'PORTFOLIO', 'icon': 'description', 'onClick': institutionCtrl.portfolioDialog, - 'parameters': '$event' + 'parameters': '$event', + 'isDisabled': _.isNil(institutionCtrl.portfolioUrl) }, { 'label': 'SEGUIDORES', @@ -80,7 +81,7 @@ institutionCtrl.institution = new Institution(response); checkIfUserIsFollower(); institutionCtrl.checkIfUserIsMember(); - getPortfolioUrl(); + setPortfolioUrl(); getActuationArea(); getLegalNature(); institutionCtrl.isLoadingData = false; @@ -112,31 +113,20 @@ function loadTimelineButtonsHeaderMob(){ institutionCtrl.timelineButtonsHeaderMob = { goBack: institutionCtrl.goBack, - showDescribe: null, + goToDescription: institutionCtrl.goToDescription, follow: institutionCtrl.follow, unfollow: institutionCtrl.unfollow, cropImage: institutionCtrl.cropImage, showImageCover: institutionCtrl.showImageCover, requestInvitation: institutionCtrl.requestInvitation, getLimitedName: institutionCtrl.getLimitedName, + editDescription: institutionCtrl.editDescription, editRegistrationData: institutionCtrl.editRegistrationData } } - function getPortfolioUrl() { + function setPortfolioUrl() { institutionCtrl.portfolioUrl = institutionCtrl.institution.portfolio_url; - if(institutionCtrl.portfolioUrl) { - PdfService.getReadableURL(institutionCtrl.portfolioUrl, setPortifolioURL) - .then(function success() { - }, function error(response) { - MessageService.showToast(response.data.msg); - - }); - } - } - - function setPortifolioURL(url) { - institutionCtrl.portfolioUrl = url; } institutionCtrl.isAdmin = function isAdmin() { @@ -152,19 +142,19 @@ institutionCtrl.user.follow(institutionCtrl.institution); institutionCtrl.isUserFollower = true; AuthService.save(); - MessageService.showToast("Seguindo "+ institutionCtrl.institution.name); + MessageService.showInfoToast("Seguindo "+ institutionCtrl.institution.name); }); return promise; }; institutionCtrl.unfollow = function unfollow() { if(institutionCtrl.user.isMember(institutionCtrl.institution.key)){ - MessageService.showToast("Você não pode deixar de seguir " + institutionCtrl.institution.name); + MessageService.showErrorToast("Você não pode deixar de seguir " + institutionCtrl.institution.name); } else{ var promise = InstitutionService.unfollow(currentInstitutionKey); promise.then(function success(){ - MessageService.showToast("Deixou de seguir "+institutionCtrl.institution.name); + MessageService.showInfoToast("Deixou de seguir "+institutionCtrl.institution.name); institutionCtrl.user.unfollow(institutionCtrl.institution); institutionCtrl.isUserFollower = false; AuthService.save(); @@ -207,6 +197,11 @@ $state.go(STATES.INST_TIMELINE, {institutionKey: instKey}); }; + institutionCtrl.goToDescription = function goToDescription(institutionKey) { + const instKey = institutionKey || currentInstitutionKey; + $state.go(STATES.INST_DESCRIPTION, {institutionKey: instKey}); + }; + institutionCtrl.goToMembers = function goToMembers(institutionKey) { UtilsService.selectNavOption(STATES.INST_MEMBERS, {institutionKey: institutionKey}); }; @@ -220,10 +215,17 @@ }; institutionCtrl.goToEvents = function goToEvents(institutionKey) { - UtilsService.selectNavOption(STATES.INST_EVENTS, - {institutionKey: institutionKey, posts: institutionCtrl.posts}); + Utils.isMobileScreen() ? goToEventsMobile(institutionKey) : goToEventsDesktop(institutionKey); }; + function goToEventsMobile(institutionKey) { + UtilsService.selectNavOption(STATES.EVENTS,{institutionKey: institutionKey}); + } + + function goToEventsDesktop(institutionKey) { + UtilsService.selectNavOption(STATES.INST_EVENTS, {institutionKey: institutionKey}); + } + institutionCtrl.goToLinks = function goToLinks(institutionKey) { UtilsService.selectNavOption(STATES.INST_LINKS, {institutionKey: institutionKey}); }; @@ -251,17 +253,27 @@ }; institutionCtrl.portfolioDialog = function(ev) { + PdfService.showPdfDialog(ev, getPortfolioPdfObj()); + }; + + institutionCtrl.editDescription = function(ev) { $mdDialog.show({ - templateUrl: 'app/institution/portfolioDialog.html', + templateUrl: 'app/institution/descriptionInst/edit_description.html', targetEvent: ev, clickOutsideToClose:true, locals: { - portfolioUrl: institutionCtrl.portfolioUrl + institution: institutionCtrl.institution }, - controller: DialogController, - controllerAs: 'ctrl' + controller: 'EditDescriptionController', + controllerAs: 'descriptionCtrl' }); }; + function getPortfolioPdfObj() { + return { + name: institutionCtrl.institution.name, + url: institutionCtrl.institution.portfolio_url + }; + } institutionCtrl.openWebsite = function openWebsite() { var website = institutionCtrl.institution.website_url; @@ -297,7 +309,7 @@ $mdDialog.show({ controller: "RequestInvitationController", controllerAs: "requestInvCtrl", - templateUrl: 'app/requests/request_invitation_dialog.html', + templateUrl: InstitutionService.getRequestInvitationTemplate(), parent: angular.element(document.body), targetEvent: event, locals: { @@ -327,7 +339,7 @@ institutionCtrl.file = null; institutionCtrl.saveImage(); }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; @@ -337,7 +349,7 @@ ImageService.saveImage(institutionCtrl.cover_photo).then(function success(data) { updateCoverImage(data); }, function error(response) { - MessageService.showToast(response.msg); + MessageService.showErrorToast(response.msg); }); } }; @@ -363,12 +375,6 @@ }); } - function DialogController($mdDialog, portfolioUrl) { - var ctrl = this; - var trustedUrl = $sce.trustAsResourceUrl(portfolioUrl); - ctrl.portfolioUrl = trustedUrl; - } - institutionCtrl.getSelectedClass = function (stateName){ return $state.current.name === STATES[stateName] ? "selected" : ""; }; diff --git a/frontend/institution/institutionHeader.component.js b/frontend/institution/institutionHeader.component.js index 3ffaba663..07cf758ec 100644 --- a/frontend/institution/institutionHeader.component.js +++ b/frontend/institution/institutionHeader.component.js @@ -7,7 +7,7 @@ templateUrl: "/app/institution/institution_header.html", controller: ['$state', 'STATES', function($state, STATES){ const instHeaderCtrl = this; - + /** Return if should show or hide button more, * show if in timeline and is admin or member. */ @@ -17,36 +17,54 @@ return instHeaderCtrl.isTimeline() && ( !instHeaderCtrl.isMember || isAdmin); - } + }; /** Return if current state is registration data on institution. * */ instHeaderCtrl.isTimeline = function isTimeline(){ return $state.current.name == STATES.INST_TIMELINE; - } + }; /** Return if current state is registration data on institution. * */ instHeaderCtrl.isRegistrationData = function isRegistrationData(){ return $state.current.name == STATES.INST_REGISTRATION_DATA; - } + }; + + /** Return if current state is registration data on institution. + * + */ + instHeaderCtrl.isDescription = function isDescription(){ + return $state.current.name == STATES.INST_DESCRIPTION; + }; /** Return the title of page according current state. */ - instHeaderCtrl.getTitle = function getTitle(){ - const getLimitedName = instHeaderCtrl.actionsButtons && - instHeaderCtrl.actionsButtons.getLimitedName(110); - const tileState = { - [STATES.INST_TIMELINE]: getLimitedName, - [STATES.INST_REGISTRATION_DATA]: "Dados cadastrais", - [STATES.INST_LINKS]: "Vínculos Institucionais", - [STATES.INST_MEMBERS]: "Membros", - [STATES.INST_FOLLOWERS]: "Seguidores" + instHeaderCtrl.getTitle = function getTitle(){ + const instName = instHeaderCtrl.institution ? instHeaderCtrl.institution.name : ""; + const limitedInstName = Utils.limitString(instName, 110); + + switch($state.current.name) { + case STATES.INST_TIMELINE: + case STATES.MANAGE_INST_MENU_MOB: return limitedInstName; + case STATES.INST_REGISTRATION_DATA: return "Dados cadastrais"; + case STATES.INST_LINKS: return "Vínculos Institucionais"; + case STATES.INST_MEMBERS: return "Membros"; + case STATES.INST_FOLLOWERS: return "Seguidores"; }; - return tileState[$state.current.name]; - } + }; + + instHeaderCtrl.showButtonEdit = function showButtonEdit(){ + return (instHeaderCtrl.isRegistrationData() || instHeaderCtrl.isDescription()) && + instHeaderCtrl.institution && instHeaderCtrl.user.isAdmin(instHeaderCtrl.institution.key); + }; + + instHeaderCtrl.editInfo = function editInfo($event){ + if(instHeaderCtrl.isDescription())instHeaderCtrl.actionsButtons.editDescription(); + if(instHeaderCtrl.isRegistrationData())instHeaderCtrl.actionsButtons.editRegistrationData($event); + }; }], controllerAs: "instHeaderCtrl", bindings: { diff --git a/frontend/institution/institutionService.js b/frontend/institution/institutionService.js index b5caa5354..5fb3422b2 100644 --- a/frontend/institution/institutionService.js +++ b/frontend/institution/institutionService.js @@ -76,5 +76,8 @@ const path = (isParent) ? 'institution_children' : 'institution_parent'; return HttpService.delete(INSTITUTIONS_URI + "/" + institutionKey + "/hierarchy/" + institutionLink + '/' + path); }; + + service.getRequestInvitationTemplate = () => Utils.isMobileScreen() ? + "app/requests/request_invitation_dialog_mobile.html" : "app/requests/request_invitation_dialog.html"; }); })(); \ No newline at end of file diff --git a/frontend/institution/institution_header.html b/frontend/institution/institution_header.html index 84e13d349..1bfe4cba9 100644 --- a/frontend/institution/institution_header.html +++ b/frontend/institution/institution_header.html @@ -7,7 +7,7 @@
    + id="btn-description" ng-click="instHeaderCtrl.actionsButtons.goToDescription()"> DESCRIÇÃO
    @@ -23,7 +23,7 @@ - more_vert + more_vert @@ -42,8 +42,8 @@ - + EDITAR
    diff --git a/frontend/institution/manageInstMenu/manageInstMenuController.js b/frontend/institution/manageInstMenu/manageInstMenuController.js new file mode 100644 index 000000000..5b6bf41cf --- /dev/null +++ b/frontend/institution/manageInstMenu/manageInstMenuController.js @@ -0,0 +1,91 @@ +"use strict"; + +(function() { + angular + .module("app") + .controller("ManageInstMenuController", [ + 'AuthService', 'ManageInstItemsFactory', + ManageInstMenuController]); + + function ManageInstMenuController(AuthService, ManageInstItemsFactory) { + const manageInstMenuCtrl = this; + + manageInstMenuCtrl.$onInit = () => { + _.defaults(manageInstMenuCtrl, { + user: AuthService.getCurrentUser(), + }); + + manageInstMenuCtrl._loadSwitchInstOptions(); + manageInstMenuCtrl._loadInstitution(); + }; + + /** + * Sets the user current institution in the controller + * than it loads the menu options + */ + manageInstMenuCtrl._loadInstitution = () => { + manageInstMenuCtrl.institution = manageInstMenuCtrl.user.current_institution; + manageInstMenuCtrl._loadMenuOptions(); + }; + + /** + * Sets the options that are going to be showed on the menu + */ + manageInstMenuCtrl._loadMenuOptions = () => { + // the slice was used to get just the first four items + manageInstMenuCtrl.options = ManageInstItemsFactory.getItems(manageInstMenuCtrl.institution).slice(0,4); + } + + /** + * Property with the actions that are going to be used by the + * institution-header component + */ + manageInstMenuCtrl.getActionButtons = { + goBack: () => window.history.back(), + showImageCover: () => true + }; + + /** + * For each profile in which the user is admin, + * a menu option is generated to be used in the + * switch institution menu, on the white-toolbar component + */ + manageInstMenuCtrl._loadSwitchInstOptions = () => { + manageInstMenuCtrl.switchInstOptions = manageInstMenuCtrl._getProfilesAdmin() + .map(prof => { + return { + getIcon: () => manageInstMenuCtrl._getIcon(prof.institution_key), + title: prof.institution.name, + action: () => manageInstMenuCtrl._switchInstitution(prof.institution) + }; + }); + }; + + /** + * Returns the corresponding icon button depending + * on the given institution key if it is the user current institution + * @param {string} instKey - institution key + */ + manageInstMenuCtrl._getIcon = (instKey) => { + const isInstSelected = manageInstMenuCtrl.user.current_institution.key === instKey; + return isInstSelected ? "radio_button_checked" : "radio_button_unchecked"; + }; + + /** + * Changes the user current institution to the given one + * than reloads the controller institution + */ + manageInstMenuCtrl._switchInstitution = institution => { + manageInstMenuCtrl.user.changeInstitution(institution); + manageInstMenuCtrl._loadInstitution(); + }; + + /** + * Returns all the user instituton profiles in which she is admin + */ + manageInstMenuCtrl._getProfilesAdmin = () => { + return manageInstMenuCtrl.user.institution_profiles + .filter(prof => manageInstMenuCtrl.user.isAdmin(prof.institution_key)); + }; + } +})(); \ No newline at end of file diff --git a/frontend/institution/manageInstMenu/manage_institution_menu.css b/frontend/institution/manageInstMenu/manage_institution_menu.css new file mode 100644 index 000000000..71a83df94 --- /dev/null +++ b/frontend/institution/manageInstMenu/manage_institution_menu.css @@ -0,0 +1,42 @@ +.manage-inst-menu__toolbar { + position: fixed; + z-index: 3; + width: 100%; +} + +.manage-inst-menu__toolbar--title { + white-space: nowrap; + text-transform: uppercase; + font-size: 0.9em; +} + +.manage-inst-menu { + display: grid; + grid-template-columns: 1fr; + grid-template-rows: auto 2em auto; +} + +.manage-inst-menu #buttons-navbar-inst-container { + display: none; +} + +.manage-inst-menu__divider { + border: none; + background-color: #84C45E; + height: 4px; + width: 30%; + align-self: center; +} + +.manage-inst-menu__option { + background: #009688; + color: white; + text-align: start; + width: 90%; + justify-self: center; +} + +.manage-inst-menu__option > md-icon { + color: white; + margin: 0 0.5em; +} \ No newline at end of file diff --git a/frontend/institution/manageInstMenu/manage_institution_menu.html b/frontend/institution/manageInstMenu/manage_institution_menu.html new file mode 100644 index 000000000..962ebf1a6 --- /dev/null +++ b/frontend/institution/manageInstMenu/manage_institution_menu.html @@ -0,0 +1,24 @@ + + + + + + + +
    + + + {{option.icon}} + {{option.description}} + +
    \ No newline at end of file diff --git a/frontend/institution/management_institution.css b/frontend/institution/manageInstitution/management_institution.css similarity index 96% rename from frontend/institution/management_institution.css rename to frontend/institution/manageInstitution/management_institution.css index e261fbc37..d3021594c 100644 --- a/frontend/institution/management_institution.css +++ b/frontend/institution/manageInstitution/management_institution.css @@ -42,6 +42,10 @@ width: 16%; } +.margin-input-info{ + margin-top: 9px; +} + .manage-member-content { overflow: auto; max-height: 220px; @@ -57,6 +61,10 @@ margin-top: 5px; } +.padding-div-info-admin{ + padding-left: 15px; +} + @media screen and (min-width: 601px) { .edit-inst-name, .edit-inst-street { width: 59%; diff --git a/frontend/institution/manageInstitution/management_institution_mobile.css b/frontend/institution/manageInstitution/management_institution_mobile.css new file mode 100644 index 000000000..d94d2ba36 --- /dev/null +++ b/frontend/institution/manageInstitution/management_institution_mobile.css @@ -0,0 +1,59 @@ +.manage-institution { + display: grid; + padding: 1em 0; + margin-top: 25%; +} + +.manage-institution__toolbar { + position: fixed; + z-index: 3; + width: 100%; +} + +.manage-institution__toolbar__title { + color: #737474; + text-transform: uppercase; + white-space: nowrap; + font-size: 0.9em; +} + +.manage-institution__cards { + grid-row-start: 2; + display: grid; + grid-row-gap: 1em; +} + +.manage-institution__card__content { + display: grid; + grid-row-gap: 1em; +} + +.manage-institution__form { + color: grey; + font-size: 0.9em; +} + +.manage-institution__form__btns { + text-align: end; + margin-bottom: 1em; +} + +.manage-institution__form md-input-container { + padding-right: 0; + margin: 0; + color: #9E9E9E; +} + +.manage-institution__btn { + width: min-content; + justify-self: end; + background-color: #009688; + color: white; + margin-right: 0; +} + +.manage-institution__list { + display: grid; + grid-row-gap: 0.5em; + max-height: 18em; +} \ No newline at end of file diff --git a/frontend/institution/manageInstitution/management_institution_mobile.html b/frontend/institution/manageInstitution/management_institution_mobile.html new file mode 100644 index 000000000..3f6fa2fd7 --- /dev/null +++ b/frontend/institution/manageInstitution/management_institution_mobile.html @@ -0,0 +1,98 @@ + + + + +
    + +
    +
    + + + + + + +

    Qual a conexão da instituição {{inviteInstHierCtrl.invite.suggestion_institution_name}} + com {{inviteInstHierCtrl.institution.name}} ? +

    + + É uma instituição superior + É uma instituição subordinada + +
    +
    + + CANCELAR + + + ENVIAR + +
    + +
    +
    + + +
    + + +
    +
    + + +
    + + + + + +
    +
    + + +
    + + + + + +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/institution/management_institution_page.html b/frontend/institution/manageInstitution/management_institution_page.html similarity index 85% rename from frontend/institution/management_institution_page.html rename to frontend/institution/manageInstitution/management_institution_page.html index e9d4c512f..30faec327 100644 --- a/frontend/institution/management_institution_page.html +++ b/frontend/institution/manageInstitution/management_institution_page.html @@ -7,7 +7,7 @@
    - +
    diff --git a/frontend/institution/managementMembersController.js b/frontend/institution/manageMembers/managementMembersController.js similarity index 90% rename from frontend/institution/managementMembersController.js rename to frontend/institution/manageMembers/managementMembersController.js index afa7e55e1..c5957ad69 100644 --- a/frontend/institution/managementMembersController.js +++ b/frontend/institution/manageMembers/managementMembersController.js @@ -4,7 +4,7 @@ app.controller("ManagementMembersController", function InviteUserController( InviteService, $state, $mdDialog, InstitutionService, AuthService, MessageService, - RequestInvitationService, ProfileService, STATES) { + RequestInvitationService, ProfileService, STATES, EntityShowcase) { var manageMemberCtrl = this; var MAX_EMAILS_QUANTITY = 10; @@ -90,12 +90,31 @@ _.remove(manageMemberCtrl.members, function(member) { return member.key === member_obj.key; }); - MessageService.showToast("Membro removido com sucesso."); + MessageService.showInfoToast("Membro removido com sucesso."); }; manageMemberCtrl.showUserProfile = function showUserProfile(userKey, ev) { ProfileService.showProfile(userKey, ev, manageMemberCtrl.institution.key); }; + + /** + * Returns the default image for an user avatar + */ + manageMemberCtrl.getDefaultAvatar = () => "app/images/avatar.png"; + + /** + * Returns a message that indicates the name + * of the user who sent the given invite + */ + manageMemberCtrl.getInviteSubtitle = (invite) => `Convidado por: ${invite.sender_name}`; + + /** + * Constructs the object that will be used to create a button + * in the entity-showcase component + */ + manageMemberCtrl.getEntityShowcaseBtn = (...args) => { + return EntityShowcase.createIconBtn(...args); + }; manageMemberCtrl.sendUserInvite = function sendInvite(loadedEmails) { manageMemberCtrl.invite.institution_key = currentInstitutionKey; @@ -119,13 +138,13 @@ manageMemberCtrl.showInvites = true; manageMemberCtrl.showSendInvite = false; manageMemberCtrl.isLoadingInvite = false; - MessageService.showToast(responseData.msg); + MessageService.showInfoToast(responseData.msg); }, function error() { manageMemberCtrl.isLoadingInvite = false; }); return promise; } else if(!invite.isValid()) { - MessageService.showToast('Convite inválido!'); + MessageService.showErrorToast('Convite inválido!'); } }; @@ -179,10 +198,10 @@ } manageMemberCtrl._getMembers = () => { - InstitutionService.getMembers(currentInstitutionKey).then(function success(response) { - manageMemberCtrl.members = Utils.isMobileScreen(475) ? - Utils.groupUsersByInitialLetter(response) : response; - getAdmin(response); + InstitutionService.getMembers(currentInstitutionKey) + .then(function success(response) { + manageMemberCtrl.members = response; + manageMemberCtrl._getAdmin(response); manageMemberCtrl.isLoadingMembers = false; }, function error() { manageMemberCtrl.isLoadingMembers = true; @@ -196,7 +215,7 @@ }); } - function getAdmin(members) { + manageMemberCtrl._getAdmin = (members) => { manageMemberCtrl.institution.admin = _.find(members, function(member){ return member.key === manageMemberCtrl.institution.admin.key; @@ -237,17 +256,17 @@ .clickOutsideToClose(false) .title('Reenviar convite') .textContent('Você deseja reenviar o convite?') - .ariaLabel('Reenviar convite') + .ariaLabel('Reenviar') .targetEvent(event) - .ok('Reenviar convite') + .ok('Reenviar') .cancel('Cancelar'); var promise = $mdDialog.show(confirm); promise.then(function () { InviteService.resendInvite(inviteKey).then(function success() { - MessageService.showToast("Convite reenviado com sucesso."); + MessageService.showInfoToast("Convite reenviado com sucesso."); }); }, function () { - MessageService.showToast('Cancelado.'); + MessageService.showInfoToast('Cancelado.'); }); return promise; }; @@ -278,13 +297,13 @@ manageMemberCtrl.isValidAllEmails = function isValidAllEmails(emails) { if(_.size(emails) === 0 ){ - MessageService.showToast("Insira pelo menos um email."); + MessageService.showErrorToast("Insira pelo menos um email."); return false; } var correctArray = manageMemberCtrl.removePendingAndMembersEmails(emails); if(!_.isEqual(correctArray, emails)){ - MessageService.showToast("E-mails selecionados já foram convidados, " + + MessageService.showErrorToast("E-mails selecionados já foram convidados, " + "requisitaram ser membro ou pertencem a algum" + " membro da instituição."); return false; @@ -311,7 +330,7 @@ manageMemberCtrl.addCSV = function addCSV(files, ev) { var file = files[0]; if(file && (file.size > MAXIMUM_CSV_SIZE)) { - MessageService.showToast('O arquivo deve ser um CSV menor que 5 Mb'); + MessageService.showErrorToast('O arquivo deve ser um CSV menor que 5 Mb'); } else { var reader = new FileReader(); reader.onload = function(e) { diff --git a/frontend/institution/management_members.html b/frontend/institution/manageMembers/management_members.html similarity index 96% rename from frontend/institution/management_members.html rename to frontend/institution/manageMembers/management_members.html index ca79f524f..94e6c1944 100644 --- a/frontend/institution/management_members.html +++ b/frontend/institution/manageMembers/management_members.html @@ -23,9 +23,9 @@

    Convidar membros

    Endereço de e-mail

    - - @@ -91,19 +91,19 @@

    {{ manageMemberCtrl.institution.admin.name }}

    -
    -
    +

    {{ manageMemberCtrl.getMemberName(invite.invitee_key) }}

    {{ invite.invitee }}

    -
    +

    PENDENTE

    h3, +.manage-members__send__invites > p { + margin: 0; +} + +.manage-members__send__invites > .description { + font-size: 0.9em; + color: grey; +} + +.manage-members__send__invites > .subtitle { + font-size: 0.8em; + font-weight: 500; +} + +.manage-members__send__invites md-input-container { + padding-right: 0; + margin: 0; + color: #9E9E9E; +} + +.manage-members__btn { + width: min-content; + justify-self: end; + background-color: #009688; + color: white; + margin-right: 0; +} + +.manage-members__list { + display: grid; + grid-row-gap: 0.5em; + max-height: 18em; +} + + +@media screen and (max-width: 361px) { + .remove-member-title{ + font-size: 15px; + } + + .remove-member-name-user{ + font-size: 13px; + } +} + +@media screen and (min-width: 361px) and (max-width: 460px) { + .remove-member-title{ + font-size: 16px; + } + + .remove-member-name-user{ + font-size: 14px; + } +} \ No newline at end of file diff --git a/frontend/institution/manageMembers/management_members_mobile.html b/frontend/institution/manageMembers/management_members_mobile.html new file mode 100644 index 000000000..9eceef9e4 --- /dev/null +++ b/frontend/institution/manageMembers/management_members_mobile.html @@ -0,0 +1,111 @@ + + + + +
    + +
    +

    Convidar Membros

    +

    + Coloque abaixo os endereços de e-mail das pessoas que você deseja convidar + para fazer parte da sua instituição na Plataforma CIS. +

    +

    Endereço de e-mail

    + + + + + + + Enviar + + +
    +
    + + + + + + + + + Transferir + + + + + +
    + + + + + +
    +
    + + +
    + + + + + +
    +
    + + +
    + + + + + +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/institution/registeredInstitution.component.js b/frontend/institution/registeredInstitution.component.js index a7f9eb6b2..371fedf09 100644 --- a/frontend/institution/registeredInstitution.component.js +++ b/frontend/institution/registeredInstitution.component.js @@ -39,7 +39,7 @@ .then(function success() { regInstCtrl.user.follow(regInstCtrl.institution); AuthService.save(); - MessageService.showToast("Seguindo " + regInstCtrl.institution.name); + MessageService.showInfoToast("Seguindo " + regInstCtrl.institution.name); }); }; @@ -72,7 +72,7 @@ */ regInstCtrl.goToInst = () => { $state.go(STATES.INST_TIMELINE, - { institutionKey: regInstCtrl.institution.key }); + { institutionKey: regInstCtrl.institution.key || regInstCtrl.institution.id }); }; /** @@ -82,5 +82,12 @@ regInstCtrl.hasSeenInstitution = function hasSeenInstitution() { return regInstCtrl.user.last_seen_institutions && regInstCtrl.user.last_seen_institutions > regInstCtrl.institution.creation_date; }; + + regInstCtrl.$onInit = () => { + const address = regInstCtrl.institution.address; + if (_.isString(address)) { + regInstCtrl.institution.address = JSON.parse(address); + } + }; }); })(); \ No newline at end of file diff --git a/frontend/institution/registered_institution.css b/frontend/institution/registered_institution.css index 026a47f61..476d699d8 100644 --- a/frontend/institution/registered_institution.css +++ b/frontend/institution/registered_institution.css @@ -20,7 +20,7 @@ .registered-institution-cover div img { height: 5.5em; - width: 100%; + justify-self: center; } #registered-institution-img { @@ -36,6 +36,7 @@ height: 3em; width: 3em; border-radius: 50%; + background: white; } .registered-institution-content { diff --git a/frontend/institution/registered_institutions_mobile.html b/frontend/institution/registered_institutions_mobile.html index 064678e27..52c5e41ba 100644 --- a/frontend/institution/registered_institutions_mobile.html +++ b/frontend/institution/registered_institutions_mobile.html @@ -1,6 +1,6 @@ -
    +
    TODAS diff --git a/frontend/institution/removeInstController.js b/frontend/institution/removeInstController.js index adb22ba80..7b363c5a6 100644 --- a/frontend/institution/removeInstController.js +++ b/frontend/institution/removeInstController.js @@ -25,7 +25,7 @@ } else { $state.go(STATES.HOME); } - MessageService.showToast("Instituição removida com sucesso."); + MessageService.showInfoToast("Instituição removida com sucesso."); }); }; @@ -41,5 +41,13 @@ $state.go('app.institution.timeline', { institutionKey: removeInstCtrl.institution.key}); removeInstCtrl.closeDialog(); }; + + /** + * Select the title according to how many institutions the user is member. + */ + removeInstCtrl.getTitle = () => { + return removeInstCtrl.hasOneInstitution() ? + "Ao remover essa instituição você perderá o acesso a plataforma. Deseja remover?" : "Deseja remover esta instituição permanentemente ?"; + }; }); })(); \ No newline at end of file diff --git a/frontend/institution/removeMemberDialog.html b/frontend/institution/removeMemberDialog.html index 575537358..ed597e17f 100644 --- a/frontend/institution/removeMemberDialog.html +++ b/frontend/institution/removeMemberDialog.html @@ -1,20 +1,17 @@
    - Deseja remover este membro de sua instituição? + Deseja remover este membro de sua instituição? close
    - - -
    -

    {{ removeMemberCtrl.member.name | uppercase }}

    -

    {{ removeMemberCtrl.member.email[0]}}

    -
    -
    + +
    Motivo da remoção (Opcional) diff --git a/frontend/institution/remove_inst_mobile.html b/frontend/institution/remove_inst_mobile.html new file mode 100644 index 000000000..d577a10b5 --- /dev/null +++ b/frontend/institution/remove_inst_mobile.html @@ -0,0 +1,17 @@ + + + + Quanto a toda a hierarquia abaixo dessa institutição, desejo: +
    + + + Remover + + + Manter + + +
    +
    +
    \ No newline at end of file diff --git a/frontend/institution/selectEmailsController.js b/frontend/institution/selectEmailsController.js index 9ab534687..ebe4413a8 100644 --- a/frontend/institution/selectEmailsController.js +++ b/frontend/institution/selectEmailsController.js @@ -18,7 +18,7 @@ if (emailExists) { selectEmailsCtrl.selectedEmails.splice(index, 1); } else if (!selectEmailsCtrl.validateEmail(email)) { - MessageService.showToast("Não é possível selecionar esta opção. E-mail inválido."); + MessageService.showErrorToast("Não é possível selecionar esta opção. E-mail inválido."); } else { selectEmailsCtrl.selectedEmails.push(email); } @@ -54,13 +54,13 @@ if (!_.isEmpty(emails)) { selectEmailsCtrl.sendUserInvite(emails); } else { - MessageService.showToast("E-mails selecionados já foram convidados, requisitaram ser membro ou pertencem a algum membro da instituição."); + MessageService.showErrorToast("E-mails selecionados já foram convidados, requisitaram ser membro ou pertencem a algum membro da instituição."); } selectEmailsCtrl.closeDialog(); } else if (selectEmailsCtrl.selectedEmails > MAX_EMAILS_QUANTITY) { - MessageService.showToast("Limite máximo de " + MAX_EMAILS_QUANTITY + " e-mails selecionados excedido."); + MessageService.showErrorToast("Limite máximo de " + MAX_EMAILS_QUANTITY + " e-mails selecionados excedido."); } else { - MessageService.showToast("Pelo menos um e-mail deve ser selecionado."); + MessageService.showErrorToast("Pelo menos um e-mail deve ser selecionado."); } }; diff --git a/frontend/institution/timeline_inst.html b/frontend/institution/timeline_inst.html index 3ec2a84fc..96d9c23bc 100644 --- a/frontend/institution/timeline_inst.html +++ b/frontend/institution/timeline_inst.html @@ -4,7 +4,7 @@
    -
    +
    diff --git a/frontend/institution/transferAdminController.js b/frontend/institution/transferAdminController.js index 4da2d8e97..06124a012 100644 --- a/frontend/institution/transferAdminController.js +++ b/frontend/institution/transferAdminController.js @@ -20,6 +20,13 @@ return false; }; + /** Get class of element HTML that show member entity. + * The class is defined according if member is selected. + */ + transferAdminCtrl.getClass = function getClass(member){ + return (member === transferAdminCtrl.selectedMember) ? "small-avatar": "small-avatar white-background"; + } + transferAdminCtrl.selectMember = function selectMember(member) { transferAdminCtrl.selectedMember = member; transferAdminCtrl.member = member.email[0]; @@ -46,13 +53,13 @@ InviteService.sendInviteUser({invite_body: invite}).then(function success() { invite.status = 'sent'; $mdDialog.hide(invite); - MessageService.showToast("Convite enviado com sucesso!"); + MessageService.showInfoToast("Convite enviado com sucesso!"); }); } else { - MessageService.showToast('Você já é administrador da instituição, selecione outro membro!'); + MessageService.showErrorToast('Você já é administrador da instituição, selecione outro membro!'); } } else { - MessageService.showToast('Selecione um memebro!'); + MessageService.showErrorToast('Selecione um membro!'); } }; }); diff --git a/frontend/institution/transfer_admin_dialog.html b/frontend/institution/transfer_admin_dialog.html index 46dde6143..1961a9735 100644 --- a/frontend/institution/transfer_admin_dialog.html +++ b/frontend/institution/transfer_admin_dialog.html @@ -1,24 +1,18 @@ - - + +

    Transferir administração

    Cada institutição precisa ter um administrador na plataforma CIS. Escolha abaixo um novo administrador para sua instituição:

    - - - search - + - - -
    - {{ member.name }} - {{ member.email[0]}} -
    -
    +

    Nenhum membro foi encontrado com esse nome ou email.

    @@ -28,10 +22,10 @@

    Transferir administração

    - + CANCELAR - + CONFIRMAR diff --git a/frontend/invites/inviteInstHierarchieController.js b/frontend/invites/inviteInstHierarchieController.js index 6ffc63818..792a3ea40 100644 --- a/frontend/invites/inviteInstHierarchieController.js +++ b/frontend/invites/inviteInstHierarchieController.js @@ -5,7 +5,7 @@ app.controller("InviteInstHierarchieController", function InviteInstHierarchieController( InviteService, STATES, $mdDialog, $state, AuthService, InstitutionService, - MessageService, RequestInvitationService, RequestDialogService, $q) { + MessageService, RequestInvitationService, RequestDialogService, $q, EntityShowcase) { var inviteInstHierCtrl = this; var institutionKey = $state.params.institutionKey; @@ -30,6 +30,10 @@ inviteInstHierCtrl.requested_invites = []; inviteInstHierCtrl.isLoadingSubmission = false; + inviteInstHierCtrl.$onInit = () => { + loadInstitution(); + } + inviteInstHierCtrl.toggleElement = function toggleElement(flagName) { inviteInstHierCtrl[flagName] = !inviteInstHierCtrl[flagName]; }; @@ -41,9 +45,9 @@ inviteInstHierCtrl.invite.admin_key = inviteInstHierCtrl.user.key; invite = new Invite(inviteInstHierCtrl.invite); if (!invite.isValid()) { - MessageService.showToast('Convite inválido!'); + MessageService.showErrorToast('Convite inválido!'); } else if(inviteInstHierCtrl.hasParent && invite.type_of_invite === INSTITUTION_PARENT) { - MessageService.showToast("Já possui instituição superior"); + MessageService.showErrorToast("Já possui instituição superior"); } else { var suggestionInstName = inviteInstHierCtrl.invite.suggestion_institution_name; promise = InstitutionService.searchInstitutions(suggestionInstName, INSTITUTION_STATE, 'institution'); @@ -96,7 +100,7 @@ } deferred.resolve(); inviteInstHierCtrl.isLoadingSubmission = false; - MessageService.showToast('Convite enviado com sucesso!'); + MessageService.showInfoToast('Convite enviado com sucesso!'); }, function error() { deferred.reject(); inviteInstHierCtrl.isLoadingSubmission = false; @@ -110,7 +114,7 @@ var deferred = $q.defer(); sendRequest(invite).then(function success() { - MessageService.showToast('Convite enviado com sucesso!'); + MessageService.showInfoToast('Convite enviado com sucesso!'); addInviteToRequests(invite); if (invite.type_of_invite === REQUEST_PARENT) { addParentInstitution(institutionRequestedKey); @@ -193,7 +197,7 @@ if (inviteInstHierCtrl.isActive(institution)) { inviteInstHierCtrl.goToInst(institution.key); } else { - MessageService.showToast("Institutição inativa!"); + MessageService.showErrorToast("Institutição inativa!"); } }; @@ -202,7 +206,7 @@ }; inviteInstHierCtrl.isActive = function isActive(institution) { - return institution.state === ACTIVE; + return institution && institution.state === ACTIVE; }; function loadInstitution() { @@ -252,7 +256,7 @@ var promise = $mdDialog.show(confirm); promise.then(function() { InstitutionService.removeLink(inviteInstHierCtrl.institution.key, institution.key, isParent).then(function success() { - MessageService.showToast('Conexão removida com sucesso'); + MessageService.showInfoToast('Conexão removida com sucesso'); if(isParent) { inviteInstHierCtrl.hasParent = false; inviteInstHierCtrl.institution.parent_institution = {}; @@ -261,7 +265,7 @@ } }); }, function() { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); return promise; }; @@ -340,8 +344,7 @@ inviteInstHierCtrl.canRemoveInst = function canRemoveInst(institution) { var hasChildrenLink = institution.parent_institution === inviteInstHierCtrl.institution.key; var removeInstPermission = inviteInstHierCtrl.user.permissions.remove_inst; - return removeInstPermission - && removeInstPermission[institution.key] && hasChildrenLink; + return removeInstPermission && removeInstPermission[institution.key] && hasChildrenLink ? true : false; }; inviteInstHierCtrl.linkParentStatus = function linkParentStatus() { @@ -354,6 +357,23 @@ return institution.parent_institution && institution.parent_institution === inviteInstHierCtrl.institution.key ? "confirmado" : "não confirmado"; }; + /** + * Gets the correspondent link status message depending on the + * the link status itself and on whether the given institution + * is active or not + * @param {object} - institution that is linked with the user's current institution + * @param {boolean} - isParent flag, if true indicates that the given institution is parent + * of the user's current institution + */ + inviteInstHierCtrl.getStatusMsg = (institution, isParent) => { + const status = isParent ? inviteInstHierCtrl.linkParentStatus() : inviteInstHierCtrl.linkChildrenStatus(institution); + if(inviteInstHierCtrl.isActive(institution)) { + return `Status do vínculo: ${status}`; + } else { + return "Instituição ainda não cadastrada na plataforma" + } + }; + inviteInstHierCtrl.analyseRequest = function analyseRequest(event, request) { RequestDialogService .showHierarchyDialog(request, event) @@ -404,7 +424,9 @@ inviteInstHierCtrl.limitString = function limitString(string, size) { return Utils.limitString(string, size); }; - - loadInstitution(); + + inviteInstHierCtrl.createIconBtn = (...args) => { + return EntityShowcase.createIconBtn(...args); + }; }); })(); \ No newline at end of file diff --git a/frontend/invites/inviteInstitutionController.js b/frontend/invites/inviteInstitutionController.js index c4c8a7b79..707c1f0fa 100644 --- a/frontend/invites/inviteInstitutionController.js +++ b/frontend/invites/inviteInstitutionController.js @@ -4,7 +4,7 @@ app.controller("InviteInstitutionController", function InviteInstitutionController( InviteService, $state, AuthService, InstitutionService, RequestInvitationService, - STATES, $mdDialog, MessageService) { + STATES, $mdDialog, MessageService, EntityShowcase, STATE_LINKS) { var inviteInstCtrl = this; inviteInstCtrl.invite = {}; @@ -22,6 +22,10 @@ inviteInstCtrl.user = AuthService.getCurrentUser(); + inviteInstCtrl.$onInit = () => { + inviteInstCtrl._loadSentInvitations(); + inviteInstCtrl._loadSentRequests(); + }; inviteInstCtrl.toggleElement = function toggleElement(flagName) { inviteInstCtrl[flagName] = !inviteInstCtrl[flagName]; @@ -31,6 +35,11 @@ inviteInstCtrl.invite = {}; }; + inviteInstCtrl.resetForm = () => { + inviteInstCtrl.inviteInstForm.$setPristine(); + inviteInstCtrl.inviteInstForm.$setUntouched(); + }; + inviteInstCtrl.checkInstInvite = function checkInstInvite(ev) { var promise; var currentInstitutionKey = inviteInstCtrl.user.current_institution.key; @@ -42,9 +51,9 @@ invite = new Invite(inviteInstCtrl.invite); if (!invite.isValid()) { - MessageService.showToast('Convite inválido!'); + MessageService.showErrorToast('Convite inválido!'); } else if (!inviteInstCtrl.user.hasPermission('analyze_request_inst')) { - MessageService.showToast('Você não tem permissão para enviar este tipo de convite.'); + MessageService.showErrorToast('Você não tem permissão para enviar este tipo de convite.'); } else { var suggestionInstName = inviteInstCtrl.invite.suggestion_institution_name; promise = InstitutionService.searchInstitutions(suggestionInstName, INSTITUTION_STATE, 'institution'); @@ -80,6 +89,8 @@ parent: angular.element(document.body), targetEvent: ev, clickOutsideToClose: true + }).then(_ => { + inviteInstCtrl.resetForm(); }); }; @@ -93,30 +104,39 @@ inviteInstCtrl.sent_invitations.push(invite); inviteInstCtrl.showInvites = true; inviteInstCtrl.showSendInvites = false; - MessageService.showToast('Convite enviado com sucesso!'); + inviteInstCtrl.resetForm(); + MessageService.showInfoToast('Convite enviado com sucesso!'); }); return promise; }; inviteInstCtrl.showPendingRequestDialog = function showPendingRequestDialog(event, request) { + const template = Utils.selectFieldBasedOnScreenSize( + "app/requests/request_institution_processing.html", + "app/requests/request_institution_processing_mobile.html", + SCREEN_SIZES.SMARTPHONE + ); $mdDialog.show({ - templateUrl: "app/requests/request_institution_processing.html", + templateUrl: template, controller: "RequestProcessingController", controllerAs: "requestCtrl", parent: angular.element(document.body), targetEvent: event, clickOutsideToClose:true, locals: { - "request": request + "request": request, + "updateRequest": inviteInstCtrl._updateRequest }, openFrom: '#fab-new-post', closeTo: angular.element(document.querySelector('#fab-new-post')) - }).then(function success() { - request.status = 'accepted'; - _.remove(inviteInstCtrl.sent_requests, (req) => request.key === req.key); }); }; + inviteInstCtrl._updateRequest = (request, status) => { + request.status = status; + _.remove(inviteInstCtrl.sent_requests, (req) => request.key === req.key); + } + inviteInstCtrl.goToInst = function goToInst(institutionKey) { $state.go(STATES.INST_TIMELINE, {institutionKey: institutionKey}); }; @@ -127,17 +147,17 @@ .clickOutsideToClose(false) .title('Reenviar convite') .textContent('Você deseja reenviar o convite?') - .ariaLabel('Reenviar convite') + .ariaLabel('Reenviar') .targetEvent(event) - .ok('Reenviar convite') + .ok('Reenviar') .cancel('Cancelar'); var promise = $mdDialog.show(confirm); promise.then(function () { InviteService.resendInvite(inviteKey).then(function success() { - MessageService.showToast("Convite reenviado com sucesso."); + MessageService.showInfoToast("Convite reenviado com sucesso."); }); }, function () { - MessageService.showToast('Cancelado.'); + MessageService.showInfoToast('Cancelado.'); }); return promise; }; @@ -153,7 +173,7 @@ angular.element($cancelButton).addClass('green-button-text'); } - function loadSentRequests() { + inviteInstCtrl._loadSentRequests = () => { var institution_key = inviteInstCtrl.user.current_institution.key; RequestInvitationService.getRequestsInst(institution_key).then(function success(requests) { var isSentRequest = createRequestSelector('sent', 'REQUEST_INSTITUTION'); @@ -163,7 +183,7 @@ }); } - function loadSentInvitations() { + inviteInstCtrl._loadSentInvitations = () => { InviteService.getSentInstitutionInvitations().then(function success(response) { var requests = response; getSentInvitations(requests); @@ -172,7 +192,11 @@ $state.go(STATES.HOME); }); } - + + inviteInstCtrl.hasNewRequests = () => { + return inviteInstCtrl.sent_requests.length > 0; + }; + function getSentInvitations(requests) { var isSentInvitation = createRequestSelector('sent', 'INSTITUTION'); inviteInstCtrl.sent_invitations = requests.filter(isSentInvitation); @@ -189,9 +213,17 @@ } } - (function main() { - loadSentInvitations(); - loadSentRequests(); - })(); + inviteInstCtrl.goToActiveInst = (institution) => { + if (institution.state === "active") { + inviteInstCtrl.goToInst(institution.key); + } else { + MessageService.showErrorToast("Institutição inativa!"); + } + }; + + inviteInstCtrl.createIconBtn = (...args) => { + return EntityShowcase.createIconBtn(...args) + }; + }); })(); \ No newline at end of file diff --git a/frontend/invites/invite_institution_mobile.css b/frontend/invites/invite_institution_mobile.css new file mode 100644 index 000000000..a8bf05e5a --- /dev/null +++ b/frontend/invites/invite_institution_mobile.css @@ -0,0 +1,53 @@ +.invite-inst { + display: grid; + padding: 1em 0; +} + +.invite-inst__toolbar { + position: fixed; + z-index: 3; + width: 100%; +} + +.invite-inst__toolbar__title { + color: #737474; + text-transform: uppercase; + white-space: nowrap; +} + +.invite-inst__cards { + grid-row-start: 2; + display: grid; + grid-row-gap: 1em; + padding-top: 25%; +} + +.invite-inst__card__content { + display: grid; + grid-row-gap: 1em; +} + +.invite-inst__card__content md-input-container { + padding-right: 0; + margin: 0; + color: #9E9E9E; +} + +.invite-inst__btns { + text-align: end; + margin-bottom: 0.5em; +} + +.invite-inst__btn { + width: min-content; + justify-self: end; + background-color: #009688; + color: white; + margin-right: 0; +} + +.invite-inst__list { + display: grid; + grid-row-gap: 0.5em; + max-height: 18em; +} diff --git a/frontend/invites/invite_institution_mobile.html b/frontend/invites/invite_institution_mobile.html new file mode 100644 index 000000000..237c8ed2f --- /dev/null +++ b/frontend/invites/invite_institution_mobile.html @@ -0,0 +1,87 @@ + + + + +
    + +
    + + + + + + + + +
    + + CANCELAR + + + ENVIAR + +
    +
    +
    + + +
    + + + + + +
    +
    + + + + + + + + + + + + + + + + +
    +
    \ No newline at end of file diff --git a/frontend/invites/newInviteController.js b/frontend/invites/newInviteController.js index 216e31df8..88618d76d 100644 --- a/frontend/invites/newInviteController.js +++ b/frontend/invites/newInviteController.js @@ -26,7 +26,7 @@ if (!userIsAMember()) { newInviteCtrl.addInstitution(event); } else { - MessageService.showToast('Você já é membro dessa instituição'); + MessageService.showErrorToast('Você já é membro dessa instituição'); newInviteCtrl.deleteInvite(); } } @@ -106,7 +106,7 @@ promise.then(function() { newInviteCtrl.deleteInvite(); }, function() { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); return promise; }; @@ -154,6 +154,10 @@ return promise; } + newInviteCtrl.showMobileInstInviteScreen = () => { + return Utils.isMobileScreen() && !newInviteCtrl.isInviteUser() && !newInviteCtrl.isAlreadyProcessed; + }; + function showAlert(event) { $mdDialog.show({ templateUrl: 'app/invites/welcome_dialog.html', @@ -195,7 +199,7 @@ function isValidProfile() { if(!newInviteCtrl.office) { - MessageService.showToast("Cargo institucional deve ser preenchido."); + MessageService.showErrorToast("Cargo institucional deve ser preenchido."); return false; } return true; diff --git a/frontend/invites/new_invite.css b/frontend/invites/new_invite.css index 6c9fe887d..d0805fac8 100644 --- a/frontend/invites/new_invite.css +++ b/frontend/invites/new_invite.css @@ -10,10 +10,6 @@ margin-left: -4.3em; } -.no-margin{ - margin: 0px; -} - @media screen and (min-width: 600px) and (max-width:800px) { .new-invite-page-card { max-width: 30em; diff --git a/frontend/invites/new_invite_mobile.css b/frontend/invites/new_invite_mobile.css new file mode 100644 index 000000000..58efa4002 --- /dev/null +++ b/frontend/invites/new_invite_mobile.css @@ -0,0 +1,41 @@ +.limit-card { + max-width: 400px; +} + +img.mobile-invite-logo { + width: 70%; +} + +.mobile-invite-btns { + display: grid; + width: 100%; + grid-auto-flow: column; + justify-content: end; +} + +#accept-invite-grid { + display: grid; +} + +.divisor-text { + font-size: 0.8em; + font-weight: 500; + margin-left: 1.6em; +} + +.invite-inst-name { + overflow: hidden; + line-height: 1.2em; + max-height: 3.6em; + font-size: 1em; + font-weight: normal; + padding: 0.1em; + text-align: left; + text-overflow: ellipsis; + justify-items: start; +} + +#invite-back-button { + justify-self: center; + margin-bottom: -2.5em; +} diff --git a/frontend/invites/new_invite_page.html b/frontend/invites/new_invite_page.html index 4247951ba..f9e0840fc 100644 --- a/frontend/invites/new_invite_page.html +++ b/frontend/invites/new_invite_page.html @@ -1,4 +1,4 @@ - + @@ -46,26 +46,26 @@

    {{ newInviteCtrl.invite.suggestion_institution_name }}

    - + - + - +
    - + - + @@ -73,7 +73,7 @@

    {{ newInviteCtrl.invite.suggestion_institution_name }}

    - + Rejeitar @@ -88,7 +88,7 @@

    {{ newInviteCtrl.invite.suggestion_institution_name }}

    - +
    @@ -103,4 +103,55 @@

    {{ newInviteCtrl.invite.suggestion_institution_name }}

    - \ No newline at end of file + + + + + + +
    + +
    +

    VOCÊ RECEBEU UM CONVITE DE:

    + + +
    +

    + PREENCHA O FORMULÁRIO PARA CADASTRAR A INSTITUIÇÃO: +

    + + +
    + + +
    +
    +
    +
    + + Rejeitar + + + Próximo + +
    + +
    +
    + + + keyboard_arrow_left + + + diff --git a/frontend/invites/processInviteUserAdmController.js b/frontend/invites/processInviteUserAdmController.js index 3ded90487..7ecc2c43a 100644 --- a/frontend/invites/processInviteUserAdmController.js +++ b/frontend/invites/processInviteUserAdmController.js @@ -23,14 +23,14 @@ AuthService.save(); processCtrl.typeOfDialog = processCtrl.VIEW_INVITE_INVITEE; processCtrl.isAccepting = true; - MessageService.showToast('Convite aceito com sucesso!'); + MessageService.showInfoToast('Convite aceito com sucesso!'); }); }; processCtrl.reject = function reject() { InviteService.rejectInviteUserAdm(processCtrl.invite.key).then(function success() { processCtrl.close(); - MessageService.showToast('Convite recusado!'); + MessageService.showInfoToast('Convite recusado!'); }); }; diff --git a/frontend/invites/removeChildController.js b/frontend/invites/removeChildController.js index a19611b5d..a1a8b837b 100644 --- a/frontend/invites/removeChildController.js +++ b/frontend/invites/removeChildController.js @@ -29,7 +29,7 @@ AuthService.save(); removeChildFromParent(); removeChildCtrl.closeDialog(); - MessageService.showToast("Instituição removida com sucesso."); + MessageService.showInfoToast("Instituição removida com sucesso."); }); }; }); diff --git a/frontend/invites/suggestInstitutionController.js b/frontend/invites/suggestInstitutionController.js index 57ca944de..e5f1898dd 100644 --- a/frontend/invites/suggestInstitutionController.js +++ b/frontend/invites/suggestInstitutionController.js @@ -94,7 +94,7 @@ const isChild = isChildFromBottomUpPerspective && isChildFromTopDownPerspective; if (isParent || isChild) { - MessageService.showToast('As instituições já estão conectadas'); + MessageService.showErrorToast('As instituições já estão conectadas'); return true; } return false; @@ -102,7 +102,7 @@ function isPedingRequest() { if (_.includes(_.map(suggestInstCtrl.requested_invites, getInstKeyFromInvite), suggestInstCtrl.chosen_institution)) { - MessageService.showToast('Esta instituição tem uma requisição de vínculo pendente. Aceite ou rejeite a requisição'); + MessageService.showErrorToast('Esta instituição tem uma requisição de vínculo pendente. Aceite ou rejeite a requisição'); return true; } return false; @@ -110,7 +110,7 @@ function isSelf() { if (suggestInstCtrl.institution.key === suggestInstCtrl.chosen_institution) { - MessageService.showToast('A instituição convidada não pode ser ela mesma'); + MessageService.showErrorToast('A instituição convidada não pode ser ela mesma'); return true; } return false; @@ -121,7 +121,7 @@ _.forEach(suggestInstCtrl.institution.sent_invitations, function(invite) { if ((invite.type_of_invite === "REQUEST_INSTITUTION_PARENT" || invite.type_of_invite === "REQUEST_INSTITUTION_CHILDREN") && invite.institution_requested_key === suggestInstCtrl.chosen_institution && invite.status === "sent") { - MessageService.showToast('Esta instituição já foi convidada, mas seu convite está pendente'); + MessageService.showErrorToast('Esta instituição já foi convidada, mas seu convite está pendente'); result = true; } }); diff --git a/frontend/main/main.html b/frontend/main/main.html index 2f56b17ee..804b917fe 100644 --- a/frontend/main/main.html +++ b/frontend/main/main.html @@ -36,7 +36,7 @@
    -
    +
    refresh @@ -80,7 +80,7 @@

    Verifique seu email para confirmar sua conta.

    - event + date_range

    Eventos

    diff --git a/frontend/main/mainController.js b/frontend/main/mainController.js index e4e525aae..9d643d3ac 100644 --- a/frontend/main/mainController.js +++ b/frontend/main/mainController.js @@ -3,7 +3,7 @@ var app = angular.module('app'); app.controller("MainController", function MainController($mdSidenav, $state, AuthService, UtilsService, - UserService, RequestInvitationService, $window, NotificationListenerService, STATES, SCREEN_SIZES) { + UserService, RequestInvitationService, $window, NotificationListenerService, STATES, SCREEN_SIZES, PushNotificationService) { var mainCtrl = this; var url_report = Config.SUPPORT_URL + "/report"; @@ -143,6 +143,13 @@ AuthService.reload(); }; + /** Should update version, refresh user and reload the page. + */ + mainCtrl.updateVersion = function updateVersion() { + mainCtrl.refreshUser(); + $window.location.reload(); + }; + /** Return correct class according currently state. */ mainCtrl.getSelectedClass = function (stateName){ @@ -179,10 +186,11 @@ (function main() { if (mainCtrl.user.name === 'Unknown') { - $state.go(STATES.CONFIG_PROFILE); + $state.go(STATES.CONFIG_PROFILE, {userKey: mainCtrl.user.key}); } notificationListener(); mainCtrl.getPendingTasks(); + PushNotificationService.setupPushNotificationPermission(); })(); }); })(); diff --git a/frontend/notification/notificationMessageCreatorService.js b/frontend/notification/notificationMessageCreatorService.js index c08b39299..47980eebf 100644 --- a/frontend/notification/notificationMessageCreatorService.js +++ b/frontend/notification/notificationMessageCreatorService.js @@ -47,16 +47,18 @@ 'DELETED_USER': messageCreator('Removeu sua conta na Plataforma Virtual CIS', NO_INST), 'ADD_ADM_PERMISSIONS': messageCreator('Suas permissões hierárquicas foram atualizadas na instituição ', SINGLE_INST), 'USER_INVITES_SENT': messageCreator('Todos os convites para novos membros foram enviados', NO_INST), - 'RE_ADD_ADM_PERMISSIONS': messageCreator('O vínculo foi restabelecido entre ', DOUBLE_INST) + 'RE_ADD_ADM_PERMISSIONS': messageCreator('O vínculo foi restabelecido entre ', DOUBLE_INST), + 'DELETED_EVENT': messageCreator('Removeu o evento de título ', NO_INST), + 'UPDATED_EVENT': messageCreator('Atualizou o evento de título ', NO_INST) }; - service.assembleMessage = function assembleMessage(entity_type, mainInst, otherInst) { + service.assembleMessage = function assembleMessage(entity_type, mainInst, otherInst, title) { var assembler = MESSAGE_ASSEMBLERS[entity_type]; - return assembler(mainInst, otherInst); + return assembler(mainInst, otherInst) + (title || ''); }; - function messageCreator(message, notificationType) { + function messageCreator(message, notificationType, title) { return function (mainInst, otherInst) { switch(notificationType) { case DOUBLE_INST: diff --git a/frontend/notification/notificationService.js b/frontend/notification/notificationService.js index 974719fdd..4b9dbc143 100644 --- a/frontend/notification/notificationService.js +++ b/frontend/notification/notificationService.js @@ -25,7 +25,7 @@ * DATE: 10/05/2018 */ var otherInst = (notification.to && notification.to.institution_name) || notification.from.institution_name; - var message = NotificationMessageCreatorService.assembleMessage(entity_type, mainInst, otherInst); + var message = NotificationMessageCreatorService.assembleMessage(entity_type, mainInst, otherInst, notification.entity.title); return message; }; diff --git a/frontend/notification/notification_list_mobile.css b/frontend/notification/notification_list_mobile.css index 5c5da45c1..3f661ce83 100644 --- a/frontend/notification/notification_list_mobile.css +++ b/frontend/notification/notification_list_mobile.css @@ -13,12 +13,6 @@ margin-top: 1%; } -#mobile-notification-empty { - display: grid; - grid-template-columns: auto; - text-align: center; -} - #mobile-notification-content { display: grid; grid-template-columns: auto; diff --git a/frontend/notification/notifications_list_mobile.html b/frontend/notification/notifications_list_mobile.html index 4a868a929..0cf64b0a8 100644 --- a/frontend/notification/notifications_list_mobile.html +++ b/frontend/notification/notifications_list_mobile.html @@ -1,7 +1,7 @@ - -

    - Nenhuma notificação no momento -

    +
    + +
    @@ -26,4 +26,4 @@

    +
    +
    \ No newline at end of file diff --git a/frontend/notification/notifications_type.constant.js b/frontend/notification/notifications_type.constant.js index 510638b02..d7364d3d3 100644 --- a/frontend/notification/notifications_type.constant.js +++ b/frontend/notification/notifications_type.constant.js @@ -150,6 +150,12 @@ }, RE_ADD_ADM_PERMISSIONS: { "icon": "check_circle_outline" + }, + DELETED_EVENT: { + "icon": "delete" + }, + UPDATED_EVENT: { + "icon": "autorenew" } }) })() \ No newline at end of file diff --git a/frontend/notification/pushNotificationService.js b/frontend/notification/pushNotificationService.js index cbb7abcf3..fb09ab6af 100644 --- a/frontend/notification/pushNotificationService.js +++ b/frontend/notification/pushNotificationService.js @@ -4,7 +4,7 @@ const app = angular.module('app'); app.service('PushNotificationService', function PushNotificationService($firebaseArray, - $firebaseObject, $q) { + $firebaseObject, $q, AuthService ) { /** * Service responsible for send request permission * to enable notifications to the user and for deal @@ -23,38 +23,63 @@ const ref = firebase.database().ref(); const PUSH_NOTIFICATIONS_URL = "pushNotifications/"; - + + service.firebaseArrayNotifications; + + /** + * Setup necessary properties as: + * Initilize firebase array with user's device tokens. + */ + service.setupPushNotificationPermission = () => { + service._initFirebaseArray(); + }; + + /** + * Check if the user has blocked push notification in the browser for this application. + * @returns {boolean} True if is blocked, false otherwise + */ + service.isPushNotificationBlockedOnBrowser = function isPushNotificationBlockedOnBrowser() { + const { permission } = Notification; + return permission === "denied"; + }; + + /** + * Check if the user has already allowed push Notification in this application + * @returns {Promise} True if notification is active, false otherwise + */ + service.isPushNotificationActive = function () { + return service._getTokenObjectInFirebaseArray().then((tokenObject) => { + return !!tokenObject; + }); + }; + + /** + * Unsubscribe User for push notification in current device. + * @return {Promise} + */ + service.unsubscribeUserNotification = () => { + return service._removeTokenFromFirebaseArray(); + }; + /** + * Remove the current device token from firebase array, blocking the device from + * receive push notifications. + * @returns {Promise} * @private */ - service._isMobile = { - Android: () => { - return navigator.userAgent.match(/Android/i); - }, - BlackBerry: () => { - return navigator.userAgent.match(/BlackBerry/i); - }, - iOS: () => { - return navigator.userAgent.match(/iPhone|iPad|iPod/i); - }, - Opera: () => { - return navigator.userAgent.match(/Opera Mini/i); - }, - Windows: () => { - return navigator.userAgent.match(/IEMobile/i); - }, - any: () => { - return ( - service._isMobile.Android() || - service._isMobile.BlackBerry() || - service._isMobile.iOS() || - service._isMobile.Opera() || - service._isMobile.Windows() - ); - } + service._removeTokenFromFirebaseArray = () => { + return service._getTokenObjectInFirebaseArray().then((tokenObject) => { + tokenObject && service.firebaseArrayNotifications.$remove(tokenObject); + }); }; - service.firebaseArrayNotifications; + /** + * Subscribe User for push notification in current device. + * * @return {Promise} + */ + service.subscribeUserNotification = () => { + return service._requestNotificationPermission(); + }; /** * Ask permission to the user to send push notifications @@ -62,10 +87,8 @@ * is retrieved and saveToken is called passing the token * as parameter. */ - service.requestNotificationPermission = function requestNotificationPermission(user) { - service.currentUser = user; - const isOnMobile = service._isMobile.any(); - if (messaging && !service._hasNotificationPermission() && isOnMobile) { + service._requestNotificationPermission = function requestNotificationPermission() { + if (messaging && !service.isPushNotificationBlockedOnBrowser()) { return messaging.requestPermission().then(() => { return messaging.getToken().then(token => { service._saveToken(token); @@ -97,7 +120,7 @@ * @private */ service._initFirebaseArray = function initFirebaseArray() { - const endPoint = `${PUSH_NOTIFICATIONS_URL}${service.currentUser.key}`; + const endPoint = `${PUSH_NOTIFICATIONS_URL}${AuthService.getCurrentUser().key}`; const notificationsRef = ref.child(endPoint); if (!service.firebaseArrayNotifications) { @@ -124,13 +147,22 @@ }; /** - * Check if the user has already conceded the permission - * using Notification object. + * Look for firebase object, in firebase array, corresponding to the current device token. + * @returns {Promise} * @private */ - service._hasNotificationPermission = function hasNotificationPermission() { - const { permission } = Notification; - return permission === "granted"; + service._getTokenObjectInFirebaseArray = () => { + return messaging && messaging.getToken().then((deviceToken) => { + return service.firebaseArrayNotifications.$loaded().then((updatedArray) => { + let tokenObject; + updatedArray.map((objectToken) => { + if (objectToken.token === deviceToken){ + tokenObject = objectToken; + } + }); + return updatedArray.find((obj) => obj.token === deviceToken); + }); + }); }; }); })(); \ No newline at end of file diff --git a/frontend/post/pdfDialog.html b/frontend/pdfUpload/pdfDialog.html similarity index 100% rename from frontend/post/pdfDialog.html rename to frontend/pdfUpload/pdfDialog.html diff --git a/frontend/pdfUpload/pdfDialogMobile.html b/frontend/pdfUpload/pdfDialogMobile.html new file mode 100644 index 000000000..dd2df476e --- /dev/null +++ b/frontend/pdfUpload/pdfDialogMobile.html @@ -0,0 +1,17 @@ + + +
    +
    + + picture_as_pdf + +
    +
    +

    {{ctrl.pdf.name}}

    +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/pdfUpload/pdfService.js b/frontend/pdfUpload/pdfService.js index d648b0f34..d0c067d84 100644 --- a/frontend/pdfUpload/pdfService.js +++ b/frontend/pdfUpload/pdfService.js @@ -3,7 +3,7 @@ (function() { var app = angular.module('app'); - app.service("PdfService", function PdfService($q, $firebaseStorage, $http) { + app.service("PdfService", function PdfService($q, $firebaseStorage, $http, $mdDialog, $window) { var service = this; var fileFolder = "files/"; var INDEX_FILE_NAME = 0; @@ -79,6 +79,10 @@ return deferred.promise; }; + service.download = function download (url) { + $window.open(url); + }; + function isValidPdf(file) { if(file) { var correctType = file.type === PDF_TYPE; @@ -87,5 +91,53 @@ } return false; } + + service.showPdfDialog = function showPdfDialog (ev, pdf) { + $mdDialog.show({ + templateUrl: Utils.selectFieldBasedOnScreenSize( + 'app/pdfUpload/pdfDialog.html', + 'app/pdfUpload/pdfDialogMobile.html' + ), + targetEvent: ev, + clickOutsideToClose:true, + locals: { + pdf: pdf + }, + controller: [ + "PdfService", + "$sce", + "pdf", + PdfDialogController, + ], + controllerAs: 'ctrl' + }); + }; + + function PdfDialogController(PdfService, $sce, pdf) { + var ctrl = this; + ctrl.pdfUrl = ""; + ctrl.isLoadingPdf = true; + ctrl.pdf = pdf; + + function readPdf() { + var readablePdf = {}; + PdfService.getReadableURL(pdf.url, setPdfURL, readablePdf).then(function success() { + var trustedUrl = $sce.trustAsResourceUrl(readablePdf.url); + ctrl.pdfUrl = trustedUrl; + ctrl.isLoadingPdf = false; + }); + } + + ctrl.downloadPdf = () => PdfService.download(ctrl.pdf.url); + + (function main() { + if (!Utils.isMobileScreen()) readPdf(); + })(); + } + + function setPdfURL(url, pdf) { + pdf.url = url; + } + }); })(); \ No newline at end of file diff --git a/frontend/post/create_post.css b/frontend/post/create_post.css index b3693be20..79df71166 100644 --- a/frontend/post/create_post.css +++ b/frontend/post/create_post.css @@ -1,6 +1,5 @@ .save-post-dialog { display: grid; - height: 100%; padding: 8px; overflow: scroll; } @@ -162,8 +161,6 @@ } .create-post-actions { - position: absolute; - bottom: 50px; width: 85%; } @@ -241,6 +238,19 @@ } } +.dialog-transparent-without-shadow { + background-color: rgba(0, 0, 0, 0); + box-shadow: 0 0 0; +} + +@media screen and (max-width: 960px) { + .dialog-transparent-without-shadow { + max-width: 100%; + max-height: 100%; + border-radius: 0; + } +} + @media screen and (max-width: 600px) { .create-post-title-placeholder { font-size: 12px !important; @@ -249,6 +259,24 @@ .create-post-text { font-size: 12px !important; } + + .save-post-dialog { + height: 100%; + } + + .dialog-transparent-without-shadow { + height: 100%; + } +} + +@media screen and (min-width: 601px) { + .save-post-dialog { + overflow: auto; + } + + .dialog-transparent-without-shadow { + width: 60%; + } } .no-padding { diff --git a/frontend/post/pdfViewDirective.js b/frontend/post/pdfViewDirective.js index 54e31169a..d27833846 100644 --- a/frontend/post/pdfViewDirective.js +++ b/frontend/post/pdfViewDirective.js @@ -3,7 +3,7 @@ var app = angular.module('app'); - app.controller('PdfController', function PdfController($mdDialog) { + app.controller('PdfController', function PdfController(PdfService) { var pdfCtrl = this; pdfCtrl.showFiles = function() { @@ -13,16 +13,7 @@ pdfCtrl.pdfDialog = function(ev, pdf) { if(!pdfCtrl.isEditing) { - $mdDialog.show({ - templateUrl: 'app/post/pdfDialog.html', - targetEvent: ev, - clickOutsideToClose:true, - locals: { - pdf: pdf - }, - controller: DialogController, - controllerAs: 'ctrl' - }); + PdfService.showPdfDialog(ev, pdf); } }; @@ -46,25 +37,6 @@ function setPdfURL(url, pdf) { pdf.url = url; } - - function DialogController($mdDialog, PdfService, $sce, pdf) { - var ctrl = this; - ctrl.pdfUrl = ""; - ctrl.isLoadingPdf = true; - - function readPdf() { - var readablePdf = {}; - PdfService.getReadableURL(pdf.url, setPdfURL, readablePdf).then(function success() { - var trustedUrl = $sce.trustAsResourceUrl(readablePdf.url); - ctrl.pdfUrl = trustedUrl; - ctrl.isLoadingPdf = false; - }); - } - - (function main() { - readPdf(); - })(); - } }); /** diff --git a/frontend/post/postDetailsDirective.js b/frontend/post/postDetailsDirective.js index fdc3a1b13..51df207b9 100644 --- a/frontend/post/postDetailsDirective.js +++ b/frontend/post/postDetailsDirective.js @@ -4,7 +4,8 @@ var app = angular.module('app'); app.controller('PostDetailsController', function(PostService, AuthService, CommentService, $state, - $mdDialog, MessageService, ngClipboard, ProfileService, $rootScope, POST_EVENTS, STATES) { + $mdDialog, MessageService, ngClipboard, ProfileService, $rootScope, + POST_EVENTS, STATES, EventService, SCREEN_SIZES) { var postDetailsCtrl = this; @@ -40,10 +41,10 @@ POST_EVENTS.DELETED_POST_EVENT_TO_UP, postDetailsCtrl.post ); - MessageService.showToast('Post excluído com sucesso'); + MessageService.showInfoToast('Post excluído com sucesso'); }); }, function() { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); }; @@ -124,8 +125,7 @@ postDetailsCtrl.showSharedEvent = function showSharedEvent() { return postDetailsCtrl.post.shared_event && - !postDetailsCtrl.isDeleted(postDetailsCtrl.post) && - !postDetailsCtrl.isDeleted(postDetailsCtrl.post.shared_event); + !postDetailsCtrl.isDeleted(postDetailsCtrl.post); }; postDetailsCtrl.showSurvey = function showSurvey() { @@ -189,7 +189,7 @@ postDetailsCtrl.copyLink = function copyLink(){ var url = Utils.generateLink(URL_POST + postDetailsCtrl.post.key); ngClipboard.toClipboard(url); - MessageService.showToast("O link foi copiado"); + MessageService.showInfoToast("O link foi copiado", true); }; postDetailsCtrl.likeOrDislikePost = function likeOrDislikePost() { @@ -229,7 +229,10 @@ $mdDialog.show({ controller: "SharePostController", controllerAs: "sharePostCtrl", - templateUrl: 'app/post/share_post_dialog.html', + templateUrl: Utils.selectFieldBasedOnScreenSize( + 'app/post/share_post_dialog.html', + 'app/post/share_post_dialog_mobile.html' + ), parent: angular.element(document.body), targetEvent: event, clickOutsideToClose:true, @@ -243,14 +246,14 @@ postDetailsCtrl.addSubscriber = function addSubscriber() { PostService.addSubscriber(postDetailsCtrl.post.key).then(function success() { - MessageService.showToast('Esse post foi marcado como de seu interesse.'); + MessageService.showInfoToast('Esse post foi marcado como de seu interesse.'); postDetailsCtrl.post.subscribers.push(postDetailsCtrl.user.key); }); }; postDetailsCtrl.removeSubscriber = function removeSubscriber() { PostService.removeSubscriber(postDetailsCtrl.post.key).then(function success() { - MessageService.showToast('Esse post foi removido dos posts de seu interesse.'); + MessageService.showInfoToast('Esse post foi removido dos posts de seu interesse.'); _.remove(postDetailsCtrl.post.subscribers, function(userKey) { return userKey === postDetailsCtrl.user.key; }); @@ -275,6 +278,44 @@ return Utils.isLargerThanTheScreen(postDetailsCtrl.post.title) ? 'break' : 'no-break'; }; + /** + * Checks if the post is actually an event that has been shared. + */ + postDetailsCtrl.isSharedEvent = () => { + return postDetailsCtrl.post.shared_event; + }; + + /** + * Checks if the user is following the event, if so + * the user will receive notifications related to the event. + */ + postDetailsCtrl.isFollowingEvent = () => { + const eventFollowers = (postDetailsCtrl.post.shared_event && postDetailsCtrl.post.shared_event.followers) || []; + return eventFollowers.includes(postDetailsCtrl.user.key); + }; + + /** + * Add the user as an event's follower. + * Thus, the user will receive notifications related to the event. + */ + postDetailsCtrl.followEvent = () => { + EventService.addFollower(postDetailsCtrl.post.shared_event.key).then(() => { + postDetailsCtrl.post.shared_event.addFollower(postDetailsCtrl.user.key); + MessageService.showInfoToast('Você receberá as atualizações desse evento.'); + }); + }; + + /** + * Remove the user from the event's followers list. + * Thus, the user won't receive any notification related to the event. + */ + postDetailsCtrl.unFollowEvent = () => { + EventService.removeFollower(postDetailsCtrl.post.shared_event.key).then(() => { + postDetailsCtrl.post.shared_event.removeFollower(postDetailsCtrl.user.key); + MessageService.showInfoToast('Você não receberá as atualizações desse evento.'); + }); + }; + function getOriginalPost(post){ if(post.shared_post){ return post.shared_post; @@ -437,7 +478,7 @@ $state.go(STATES.HOME); }); } else { - MessageService.showToast("Comentário não pode ser vazio."); + MessageService.showErrorToast("Comentário não pode ser vazio."); } return promise; }; @@ -450,6 +491,7 @@ return !postDetailsCtrl.post || _.isEmpty(postDetailsCtrl.post); }; + function isInstitutionAdmin() { return _.includes(_.map(postDetailsCtrl.user.institutions_admin, getKeyFromUrl), postDetailsCtrl.post.institution_key); } @@ -511,11 +553,24 @@ return {background: color}; }; + /** + * Checks if the application is being used by a mobile device. + */ + postDetailsCtrl.isMobileScreen = () => { + return Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE); + }; + function adjustText(text){ return (!postDetailsCtrl.isPostPage && text) ? Utils.limitString(text, LIMIT_POST_CHARACTERS) : text; } + postDetailsCtrl.$onInit = () => { + if (postDetailsCtrl.isSharedEvent()) { + postDetailsCtrl.post.shared_event = new Event(postDetailsCtrl.post.shared_event); + } + }; + postDetailsCtrl.$postLink = function() { if($state.params.focus){ window.location.href= window.location.href + '#comment-input'; diff --git a/frontend/post/postDirective.js b/frontend/post/postDirective.js index 67b7285de..3815203f1 100644 --- a/frontend/post/postDirective.js +++ b/frontend/post/postDirective.js @@ -37,7 +37,7 @@ postCtrl.deletePreviousImage = true; postCtrl.file = null; }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; @@ -61,7 +61,7 @@ postCtrl.addPdf = function addPdf(files) { if(files[0].size > MAXIMUM_PDF_SIZE) { - MessageService.showToast('O arquivo deve ser um pdf menor que 5 Mb'); + MessageService.showErrorToast('O arquivo deve ser um pdf menor que 5 Mb'); } else { postCtrl.pdfFiles = files; } @@ -136,7 +136,7 @@ } deferred.resolve(); }, function error(response) { - MessageService.showToast(response); + MessageService.showErrorToast(response); deferred.reject(); }); } else { @@ -200,7 +200,7 @@ saveEditedPost(originalPost); }, function error(error) { postCtrl.loadingPost = false; - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; @@ -229,7 +229,7 @@ PostService.createPost(post).then(function success(response) { postCtrl.clearPost(); $rootScope.$emit(POST_EVENTS.NEW_POST_EVENT_TO_UP, new Post(response)); - MessageService.showToast('Postado com sucesso!'); + MessageService.showInfoToast('Postado com sucesso!'); changeTimelineToStart(); $mdDialog.hide(); postCtrl.loadingPost = false; @@ -243,7 +243,7 @@ }); }); } else { - MessageService.showToast('Post inválido!'); + MessageService.showErrorToast('Post inválido!'); } }); postCtrl.post.photo_url = null; @@ -290,14 +290,14 @@ PostService.save(postCtrl.post.key, patch).then(function success() { deleteFiles().then(function success() { postCtrl.deletedFiles = []; - MessageService.showToast('Publicação editada com sucesso!'); + MessageService.showInfoToast('Publicação editada com sucesso!'); $mdDialog.hide(postCtrl.post); }, function error(response) { $mdDialog.cancel(); }); }); } else { - MessageService.showToast('Edição inválida!'); + MessageService.showErrorToast('Edição inválida!'); } }); } diff --git a/frontend/post/postPageController.js b/frontend/post/postPageController.js index a02a3f5fd..485f5a278 100644 --- a/frontend/post/postPageController.js +++ b/frontend/post/postPageController.js @@ -3,11 +3,16 @@ var app = angular.module('app'); - app.controller("PostPageController", function PostPageController(PostService, $state, STATES) { + app.controller("PostPageController", function PostPageController(PostService, $state, + STATES, MessageService, ngClipboard, AuthService, $mdDialog) { var postCtrl = this; postCtrl.post = null; + postCtrl.user = AuthService.getCurrentUser(); + + const EDIT_POST_PERMISSION = 'edit_post'; + postCtrl.isHiden = function isHiden() { var isDeleted = postCtrl.post.state == 'deleted'; var hasNoComments = postCtrl.post.number_of_comments === 0; @@ -17,6 +22,176 @@ return postCtrl.post.state === 'deleted' && hasNoActivity; }; + /** + * It copies the post's url to the clipboard + */ + postCtrl.copyLink = function copyLink() { + var url = Utils.generateLink('/post/' + postCtrl.post.key); + ngClipboard.toClipboard(url); + MessageService.showInfoToast("O link foi copiado", true); + }; + + /** + * Refreshes the post by retrieving it from + * the server once again. + */ + postCtrl.reloadPost = function reloadPost() { + var type_survey = postCtrl.post.type_survey; + postCtrl.post.type_survey = ''; + return PostService.getPost(postCtrl.post.key) + .then(function success(response) { + response.data_comments = Object.values(response.data_comments); + postCtrl.post = response; + }, function error(response) { + postCtrl.post.type_survey = type_survey; + }); + }; + + /** + * Open up a dialog that allows the user to share + * the post. + */ + postCtrl.share = function share(event) { + const post = getOriginalPost(); + $mdDialog.show({ + controller: "SharePostController", + controllerAs: "sharePostCtrl", + templateUrl: 'app/post/share_post_dialog.html', + parent: angular.element(document.body), + targetEvent: event, + clickOutsideToClose: true, + locals: { + user: postCtrl.user, + post: post, + addPost: true + } + }); + }; + + /** + * Add the user to the post's subscribers list + * what makes him to receive the notifications realated + * to the post. + */ + postCtrl.addSubscriber = function addSubscriber() { + PostService.addSubscriber(postCtrl.post.key).then(function success() { + MessageService.showInfoToast('Esse post foi marcado como de seu interesse.'); + postCtrl.post.subscribers.push(postCtrl.user.key); + }); + }; + + /** + * Removes the user from the post's subscribers list + * peventing him of receive notifications related to the post. + */ + postCtrl.removeSubscriber = function removeSubscriber() { + PostService.removeSubscriber(postCtrl.post.key).then(function success() { + MessageService.showInfoToast('Esse post foi removido dos posts de seu interesse.'); + _.remove(postCtrl.post.subscribers, function (userKey) { + return userKey === postCtrl.user.key; + }); + }, function error(response) { + $state.go($state.current); + }); + }; + + /** + * Checks if the user is in the post's subscribers list + */ + postCtrl.isSubscriber = function isSubscriber() { + return postCtrl.post && postCtrl.post.subscribers.includes(postCtrl.user.key); + }; + + /** + * If the post comes from another + * it returns the shared one, otherwise + * the post is returned. + */ + function getOriginalPost() { + if (postCtrl.post.shared_post) { + return postCtrl.post.shared_post; + } else if (postCtrl.post.shared_event) { + return postCtrl.post.shared_event; + } + return postCtrl.post; + } + + /** + * Open up a dialog that allows the user to edit the post. + */ + postCtrl.edit = function edit(event) { + $mdDialog.show({ + controller: function DialogController() { }, + controllerAs: "controller", + templateUrl: 'app/home/post_dialog.html', + parent: angular.element(document.body), + targetEvent: event, + clickOutsideToClose: true, + locals: { + originalPost: postCtrl.post, + isEditing: true + }, + bindToController: true + }).then(function success(editedPost) { + postCtrl.post.title = editedPost.title; + postCtrl.post.text = editedPost.text; + postCtrl.post.photo_url = editedPost.photo_url; + postCtrl.post.pdf_files = editedPost.pdf_files; + postCtrl.post.video_url = editedPost.video_url; + }, function error() { }); + }; + + /** + * Checks if the user can edit the post. For that, the user needs to have the + * permissions. Besides, the post and the institution can not be unavailable + */ + postCtrl.canEdit = function canEdit() { + const hasPermission = postCtrl.post && postCtrl.user.hasPermission(EDIT_POST_PERMISSION, postCtrl.post.key); + var isActiveInst = postCtrl.post && postCtrl.post.institution_state == "active"; + return hasPermission && postCtrl.post.state !== 'deleted' && isActiveInst && + !postCtrl.postHasActivity() && !postCtrl.isShared() && !postCtrl.post.type_survey; + }; + + /** + * Checks if the post has any activity. It can be comments or likes. + */ + postCtrl.postHasActivity = function postHasActivity() { + var hasNoComments = postCtrl.post.number_of_comments === 0; + var hasNoLikes = postCtrl.post.number_of_likes === 0; + + return !hasNoComments || !hasNoLikes; + }; + + /** + * Checks if the post came from another post or event by sharing. + */ + postCtrl.isShared = function isShared() { + return postCtrl.post.shared_post || + postCtrl.post.shared_event; + }; + + /** + * Constructs a list with the menu options. + */ + postCtrl.generateToolbarOptions = function generateToolbarOptions() { + postCtrl.defaultToolbarOptions = [ + { title: 'Obter link', icon: 'link', action: () => { postCtrl.copyLink() } }, + { title: 'Atualizar post', icon: 'refresh', action: () => { postCtrl.reloadPost() } }, + { title: 'Compartilhar', icon: 'share', action: () => { postCtrl.share('$event') } }, + { title: 'Receber atualizações', icon: 'bookmark', action: () => { postCtrl.addSubscriber() }, hide: () => postCtrl.isSubscriber() }, + { title: 'Não receber atualizações', icon: 'bookmark', + action: () => { postCtrl.removeSubscriber() }, hide: () => !postCtrl.isSubscriber() || postCtrl.isPostAuthor() }, + { title: 'Editar postagem', icon: 'edit', action: () => { postCtrl.edit() }, hide: () => !postCtrl.canEdit() } + ]; + }; + + /** + * Checks if the current user is the post's author. + */ + postCtrl.isPostAuthor = function isPostAuthor() { + return postCtrl.post.author_key === postCtrl.user.key; + }; + function loadPost(postKey) { var promise = PostService.getPost(postKey); promise.then(function success(response) { @@ -28,6 +203,9 @@ return promise; } - loadPost($state.params.key); + postCtrl.$onInit = () => { + loadPost($state.params.key); + postCtrl.generateToolbarOptions(); + }; }); })(); \ No newline at end of file diff --git a/frontend/post/post_details.html b/frontend/post/post_details.html index 251de6917..ba77f9985 100644 --- a/frontend/post/post_details.html +++ b/frontend/post/post_details.html @@ -6,7 +6,7 @@

    + ng-hide="postDetailsCtrl.isHidden() || postDetailsCtrl.isPostEmpty()" id="post-container">
    ENQUETE FINALIZADA | {{postDetailsCtrl.post.deadline | amUtc | amLocal | amCalendar:referenceTime:formats}} @@ -41,7 +41,7 @@ - + more_vert @@ -74,6 +74,18 @@ Receber atualizações + + + visibility + Receber atualizações do evento + + + + + visibility_off + Deixar de receber atualizações do evento + + @@ -92,52 +104,12 @@ - - + + + - -
    - ENQUETE FINALIZADA | {{postDetailsCtrl.post.shared_post.deadline | amUtc | amLocal | amCalendar:referenceTime:formats}} -
    - - - - - - - {{ postDetailsCtrl.post.shared_post.institution_name }} - por {{ postDetailsCtrl.post.shared_post.author }} - - - - - -
    - -
    -

    - - {{ postDetailsCtrl.post.shared_post.title }} - -

    - - - -
    -
    + -
    + + +
    +
    -
    - +
    +
    - +
    - +

    Esta publicação foi removida.

    diff --git a/frontend/post/sharePostController.js b/frontend/post/sharePostController.js index dce0a6459..f16578ee0 100644 --- a/frontend/post/sharePostController.js +++ b/frontend/post/sharePostController.js @@ -44,7 +44,7 @@ shareCtrl.share = function share() { makePost(shareCtrl.post); PostService.createPost(shareCtrl.newPost).then(function success(response) { - MessageService.showToast('Compartilhado com sucesso!'); + MessageService.showInfoToast('Compartilhado com sucesso!'); $mdDialog.hide(); shareCtrl.addPostTimeline(response); const postAuthorPermissions = ["remove_post"]; @@ -93,5 +93,11 @@ } return text && text.replace(URL_PATTERN, REPLACE_URL); }; + + shareCtrl.$onInit = () => { + const type = shareCtrl.isEvent() ? 'evento' : 'post'; + shareCtrl.title = `Compartilhar ${type}`; + shareCtrl.subtitle = `Você deseja compartilhar esse ${type}?`; + }; }); })(); \ No newline at end of file diff --git a/frontend/post/share_post_dialog_mobile.html b/frontend/post/share_post_dialog_mobile.html new file mode 100644 index 000000000..5da90ebe6 --- /dev/null +++ b/frontend/post/share_post_dialog_mobile.html @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/frontend/post/sharedPost.component.js b/frontend/post/sharedPost.component.js new file mode 100644 index 000000000..6eebc0d24 --- /dev/null +++ b/frontend/post/sharedPost.component.js @@ -0,0 +1,13 @@ +(function() { + 'use strict'; + const app = angular.module('app'); + + app.component('sharedPost', { + templateUrl: Utils.selectFieldBasedOnScreenSize('app/post/shared_post_desktop.html', 'app/post/shared_post_mobile.html', 600), + controller: 'PostDetailsController', + controllerAs: 'postDetailsCtrl', + bindings: { + post: '<' + } + }); +})(); \ No newline at end of file diff --git a/frontend/post/shared_post.css b/frontend/post/shared_post.css new file mode 100644 index 000000000..478760b3f --- /dev/null +++ b/frontend/post/shared_post.css @@ -0,0 +1,21 @@ +.shared-post__header { + display: grid; + grid-template-columns: min-content 1fr; + padding: 8px 8px 0 8px; + grid-column-gap: 10px; +} + +.shared-post__img { + border-radius: 50%; +} + +.shared-post__title { + display: grid; + grid-template-rows: auto auto; + font-size: 14px; + color: rgb(117, 117, 117); +} + +.shared-post__body { + padding: 16px; +} \ No newline at end of file diff --git a/frontend/post/shared_post_desktop.html b/frontend/post/shared_post_desktop.html new file mode 100644 index 000000000..4368b13a0 --- /dev/null +++ b/frontend/post/shared_post_desktop.html @@ -0,0 +1,42 @@ + +
    + ENQUETE FINALIZADA | {{postDetailsCtrl.post.shared_post.deadline | amUtc | amLocal | amCalendar:referenceTime:formats}} +
    + + + + + +
    + {{ postDetailsCtrl.post.shared_post.institution_name }} + por {{ postDetailsCtrl.post.shared_post.author }} + + + + + +
    + +
    +

    + + {{ postDetailsCtrl.post.shared_post.title }} + +

    + + + +
    + \ No newline at end of file diff --git a/frontend/post/shared_post_mobile.html b/frontend/post/shared_post_mobile.html new file mode 100644 index 000000000..1236f8e8f --- /dev/null +++ b/frontend/post/shared_post_mobile.html @@ -0,0 +1,40 @@ +
    +
    + ENQUETE FINALIZADA | {{postDetailsCtrl.post.shared_post.deadline | amUtc | amLocal | amCalendar:referenceTime:formats}} +
    +
    + +
    + + {{ postDetailsCtrl.post.shared_post.institution_name }} + por {{ postDetailsCtrl.post.shared_post.author }} +
    +
    + +
    + +
    + +
    +

    + + {{ postDetailsCtrl.post.shared_post.title }} + +

    + + + +
    +
    diff --git a/frontend/post/timeline.html b/frontend/post/timeline.html index e579e55bc..7c5ec51fc 100644 --- a/frontend/post/timeline.html +++ b/frontend/post/timeline.html @@ -1,9 +1,11 @@
    - - -

    Esta instituição ainda não possui publicações.

    -
    + + + + +

    Esta instituição ainda não possui publicações.

    +
    @@ -11,7 +13,7 @@

    Esta instituição ainda não possui publicações.

    refresh
    -
    +
    diff --git a/frontend/post/timelineDirective.js b/frontend/post/timelineDirective.js index 0704e28a8..c619381eb 100644 --- a/frontend/post/timelineDirective.js +++ b/frontend/post/timelineDirective.js @@ -56,6 +56,8 @@ return timelineCtrl.posts.loadMorePosts(); }; + timelineCtrl.isMobileScreen = () => Utils.isMobileScreen(); + /** * Set the properties necessary to make the default Timeline work * with the expected values to this context. diff --git a/frontend/requests/analyseHierarchyRequestController.js b/frontend/requests/analyseHierarchyRequestController.js index 8acf8cc09..a5754517e 100644 --- a/frontend/requests/analyseHierarchyRequestController.js +++ b/frontend/requests/analyseHierarchyRequestController.js @@ -6,6 +6,7 @@ app.controller('AnalyseHierarchyRequestController', function AnalyseHierarchyRequestController(request, RequestInvitationService, InstitutionService, MessageService, $mdDialog) { const analyseHierReqCtrl = this; + analyseHierReqCtrl.analyseInstitutions = false; const REQUEST_PARENT = "REQUEST_INSTITUTION_PARENT"; const REQUEST_CHILDREN = "REQUEST_INSTITUTION_CHILDREN"; @@ -27,6 +28,22 @@ analyseHierReqCtrl.child = child; })(); + /** Show button accept if hasn't link to remove or + * if user in display on analyse institution hierarchie. + * + */ + analyseHierReqCtrl.showButtonAccept = function(){ + return !analyseHierReqCtrl.hasToRemoveLink || + analyseHierReqCtrl.hasToRemoveLink && analyseHierReqCtrl.analyseInstitutions; + }; + + /** Show description that informes to user that + * he's need remove old link before accept new link; + */ + analyseHierReqCtrl.showDescToRemoveLink = function(){ + return analyseHierReqCtrl.hasToRemoveLink && !analyseHierReqCtrl.analyseInstitutions; + }; + analyseHierReqCtrl.confirmRequest = function confirmRequest() { analyseHierReqCtrl.hasToRemoveLink ? confirmLinkRemoval() : acceptRequest(); }; @@ -36,13 +53,13 @@ function success() { request.status = 'rejected'; $mdDialog.cancel(); - MessageService.showToast('Solicitação rejeitada com sucesso'); + MessageService.showInfoToast('Solicitação rejeitada com sucesso'); }); }; analyseHierReqCtrl.close = function close() { $mdDialog.hide(); - MessageService.showToast('Solicitação aceita com sucesso'); + MessageService.showInfoToast('Solicitação aceita com sucesso'); }; analyseHierReqCtrl.showProcessingMessage = function showProcessingMessage() { diff --git a/frontend/requests/analyse_hierarchy_request.css b/frontend/requests/analyse_hierarchy_request.css new file mode 100644 index 000000000..51f2ed1bc --- /dev/null +++ b/frontend/requests/analyse_hierarchy_request.css @@ -0,0 +1,27 @@ +.analyse-request__description{ + color: #707070; +} + +.analyse-request__dialog{ + max-height: 90%; +} + +.analyse-request__green-bar{ + width: 8px; + background-color: #009688; +} + +.analyse-request__margin-bottom{ + margin:0 0 8px 0; +} + +.analyse-request__children-inst{ + display: grid; + grid-template-columns: 25px auto; +} + +@media screen and (max-width: 420px){ + .analyse-request__children-inst{ + grid-template-columns: 15px auto; + } +} \ No newline at end of file diff --git a/frontend/requests/analyse_hierarchy_request_dialog.html b/frontend/requests/analyse_hierarchy_request_dialog.html index cdb4a93b3..24c9a86f1 100644 --- a/frontend/requests/analyse_hierarchy_request_dialog.html +++ b/frontend/requests/analyse_hierarchy_request_dialog.html @@ -1,88 +1,92 @@ - +

    Confirmar vínculo

    -

    +

    Para aceitar o vínculo e tornar {{ analyseHierReqCtrl.child.name }} uma subornadinada de - {{ analyseHierReqCtrl.parent.name }}, clique em Confirmar. Caso queira rejeitar, clique em cancelar. + {{ analyseHierReqCtrl.parent.name }}, clique em aceitar. Caso não queira se vincular a esta instituição clique em rejeitar.

    + +
    + + +
    +
    + + +
    +
    -
    +

    Confirmar remoção de vínculo existente

    -

    +

    Para aceitar o vínculo e tornar {{ analyseHierReqCtrl.child.name }} uma subornadinada de {{ analyseHierReqCtrl.parent.name }} - é necessário que o vínculo com {{ analyseHierReqCtrl.child.parent_institution.name }} seja desfeito. Clique em Confirmar, - para prosseguir, ou em Cancelar, para rejeitar o pedido. + é necessário que o vínculo com {{ analyseHierReqCtrl.child.parent_institution.name }} seja desfeito. Clique em aceitar, + para visualizar a alteração de vínculo, caso não queira se vincular a esta instituição clique em rejeitar.

    +
    +

    Vínculo Atual

    -
    -
    - {{analyseHierReqCtrl.child.parent_institution.name}} -
    -
    - {{ analyseHierReqCtrl.child.parent_institution.name }} - {{ analyseHierReqCtrl.child.parent_institution.institutional_email }} -
    -
    -
    -
    -
    -
    -
    -
    - {{ analyseHierReqCtrl.child.name }} -
    -
    - {{ analyseHierReqCtrl.child.name || analyseHierReqCtrl.child.sender_name}} - {{ analyseHierReqCtrl.child.institutional_email }} - {{ analyseHierReqCtrl.child.office }} -
    -
    + + +
    +
    + +

    Vínculo Futuro

    -
    -
    -
    -
    - {{analyseHierReqCtrl.parent.name}} -
    -
    - {{ analyseHierReqCtrl.parent.name }} - {{ analyseHierReqCtrl.parent.institutional_email }} -
    -
    -
    -
    -
    -
    -
    -
    - {{ analyseHierReqCtrl.child.name }} -
    -
    - {{ analyseHierReqCtrl.child.name || analyseHierReqCtrl.child.sender_name}} - {{ analyseHierReqCtrl.child.institutional_email }} - {{ analyseHierReqCtrl.child.office }} +
    + + +
    +
    + +
    -
    Cancelar + md-colors="{color: 'default-teal-500'}"> Rejeitar Confirmar + md-colors="{color: 'default-teal-500'}" + ng-if="analyseHierReqCtrl.showButtonAccept()"> Aceitar + Avançar + diff --git a/frontend/requests/requestDialogService.js b/frontend/requests/requestDialogService.js index 04610171c..ef104764b 100644 --- a/frontend/requests/requestDialogService.js +++ b/frontend/requests/requestDialogService.js @@ -35,7 +35,7 @@ var request = new Invite(data); selectDialogToShow(request, event, dialogProperties); }, function error(response) { - MessageService.showToast(response.data.msg); + MessageService.showErrorToast(response.data.msg); } ); }; diff --git a/frontend/requests/requestInvitationController.js b/frontend/requests/requestInvitationController.js index 165de470d..9a193e9ee 100644 --- a/frontend/requests/requestInvitationController.js +++ b/frontend/requests/requestInvitationController.js @@ -31,7 +31,7 @@ requestInvCtrl.currentUser.institutions_requested.push(requestInvCtrl.institutionSelect.key); AuthService.save(); $mdDialog.hide(); - MessageService.showToast("Pedido enviado com sucesso!"); + MessageService.showInfoToast("Pedido enviado com sucesso!"); }, function error() { requestInvCtrl.cancelDialog(); }); @@ -44,7 +44,7 @@ .filter(request => request.status === "sent") .map(request => request.sender_key); return !sender_keys.includes(requestInvCtrl.currentUser.key) ? - requestInvCtrl.sendRequest() : MessageService.showToast("Usuário já solicitou fazer parte dessa instituição."); + requestInvCtrl.sendRequest() : MessageService.showErrorToast("Usuário já solicitou fazer parte dessa instituição."); } else { requestInvCtrl.sendRequest(); } diff --git a/frontend/requests/requestProcessingController.js b/frontend/requests/requestProcessingController.js index fa8e6cc5d..867d83915 100644 --- a/frontend/requests/requestProcessingController.js +++ b/frontend/requests/requestProcessingController.js @@ -4,7 +4,7 @@ var app = angular.module('app'); app.controller('RequestProcessingController', function RequestProcessingController(AuthService, RequestInvitationService, - MessageService, InstitutionService, request, $state, $mdDialog, STATES) { + MessageService, InstitutionService, request, updateRequest, $state, $mdDialog, STATES) { var requestController = this; var REQUEST_INSTITUTION = "REQUEST_INSTITUTION"; @@ -18,10 +18,11 @@ requestController.isRejecting = false; requestController.acceptRequest = function acceptRequest() { - resolveRequest().then(function success() { - MessageService.showToast("Solicitação aceita!"); - request.status = 'accepted'; + resolveRequest() + .then(function success() { + updateRequest(request, 'accepted'); requestController.hideDialog(); + MessageService.showInfoToast("Solicitação aceita!"); refreshUser(); }); }; @@ -40,20 +41,31 @@ } requestController.rejectRequest = function rejectRequest(event){ - requestController.isRejecting = true; + const confirm = $mdDialog.confirm() + .title('Rejeitar Instituição') + .textContent('Tem certeza que deseja rejeitar?') + .targetEvent(event) + .ok('CONFIRMAR') + .cancel('CANCELAR'); + + $mdDialog + .show(confirm) + .then(requestController.confirmReject) + .catch(requestController.cancelReject); }; requestController.confirmReject = function confirmReject() { - deleteRequest().then(function success() { - request.status = 'rejected'; + deleteRequest() + .then(function success() { + updateRequest(request, 'rejected'); requestController.hideDialog(); - MessageService.showToast("Solicitação rejeitada!"); + MessageService.showInfoToast("Solicitação rejeitada!"); }); }; requestController.cancelReject = function cancelReject() { $mdDialog.cancel(); - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }; function deleteRequest() { @@ -79,16 +91,13 @@ }; requestController.getChildrenInstName = function getChildrenInstName(size) { - const returnValue = requestController.children ? - Utils.limitString(requestController.children.name || - requestController.children.sender_name, size) : ""; - return returnValue; + return requestController.children ? + (requestController.children.name || requestController.children.sender_name) : ""; }; requestController.getChildrenInstEmail = function getChildrenInstEmail(size) { - const returnValue = requestController.children ? - Utils.limitString(requestController.children.institutional_email, size) : ""; - return returnValue; + return requestController.children ? + (requestController.children.institutional_email) : ""; }; requestController.isAnotherCountry = function isAnotherCountry() { @@ -126,7 +135,7 @@ const institutionLinkKey = requestController.children.parent_institution.key; InstitutionService.removeLink(institutionKey, institutionLinkKey, isParent).then(function success() { - MessageService.showToast('Vínculo removido.'); + MessageService.showInfoToast('Vínculo removido.'); delete requestController.children.parent_institution; }); }; @@ -155,6 +164,8 @@ }); } + requestController.showProperty = prop => Utils.showProperty(prop); + (function main () { if(request.status == 'sent') loadInstitution(); })(); diff --git a/frontend/requests/request_institution_processing.html b/frontend/requests/request_institution_processing.html index c8962ed97..8097357c0 100644 --- a/frontend/requests/request_institution_processing.html +++ b/frontend/requests/request_institution_processing.html @@ -43,7 +43,7 @@

    Informações institucionais

    - + RECUSAR @@ -51,18 +51,6 @@

    Informações institucionais

    APROVAR
    - -

    Rejeitar Instituição

    -

    Tem certeza que deseja rejeitar?

    -
    - - - CANCELAR - - - CONFIRMAR - -
    diff --git a/frontend/requests/request_institution_processing_mobile.css b/frontend/requests/request_institution_processing_mobile.css new file mode 100644 index 000000000..556cd070b --- /dev/null +++ b/frontend/requests/request_institution_processing_mobile.css @@ -0,0 +1,95 @@ +.pending-inst-request { + display: grid; + padding: 1em; + max-width: 70%; + overflow-y: hidden; +} + +.pending-inst-request > .title { + font-size: 1.1em; + font-weight: 500; +} + +.pending-inst-request > .inst-data { + background: white; + padding-right: 0.3em; + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: auto; + grid-template-areas: + 'name name' + 'actuation actuation' + 'nature nature' + 'country state' + 'street street' + 'neighbourhood number' + 'email email' + 'leader leader'; + align-items: initial; +} + +.inst-data p { + font-size: 0.7em; + font-weight: 500; + margin-bottom: 0.2em; + color: #004D40; +} + +.inst-data span { + font-size: 0.8em; + color: grey; +} + +.name_container { + grid-area: name; +} + +.name_container .name { + font-weight: 500; +} + +.actuation-containter { + grid-area: actuation; +} + +.nature-container { + grid-area: nature; +} + +.country-container { + grid-area: country; +} + +.state-container { + grid-area: state; +} + +.street-container { + grid-area: street; +} + +.neighbourhood-container { + grid-area: neighbourhood; +} + +.number-container { + grid-area: number; +} + +.email-container { + grid-area: email; +} + +.leader-container { + grid-area: leader; +} + +.pending-inst-request .btns-container { + text-align: end; + padding-top: 0.3em; +} + +.pending-inst-request .button { + color: #07988B; + margin: auto; +} diff --git a/frontend/requests/request_institution_processing_mobile.html b/frontend/requests/request_institution_processing_mobile.html new file mode 100644 index 000000000..98f1400f2 --- /dev/null +++ b/frontend/requests/request_institution_processing_mobile.html @@ -0,0 +1,49 @@ + + Informações institucionais + +
    +

    Nome

    + {{ requestCtrl.parent.name }} +
    +
    +

    Áreas de Atuação

    + {{ requestCtrl.instActuationArea }} +
    +
    +

    Natureza Jurídica

    + {{ requestCtrl.instLegalNature }} +
    +
    +

    País

    + {{ requestCtrl.parent.address.country }} +
    +
    +

    Estado

    + {{ requestCtrl.showProperty(requestCtrl.parent.address.federal_state) }} +
    +
    +

    Rua

    + {{ requestCtrl.showProperty(requestCtrl.parent.address.street) }} +
    +
    +

    Bairro

    + {{ requestCtrl.showProperty(requestCtrl.parent.address.neighbourhood) }} +
    +
    +

    Número

    + {{ requestCtrl.showProperty(requestCtrl.parent.address.number) }} +
    + +
    +

    Responsável

    + {{ requestCtrl.parent.leader }} +
    +
    +
    + RECUSAR + ACEITAR +
    +
    \ No newline at end of file diff --git a/frontend/requests/request_invitation_dialog.css b/frontend/requests/request_invitation_dialog.css new file mode 100644 index 000000000..35031078f --- /dev/null +++ b/frontend/requests/request_invitation_dialog.css @@ -0,0 +1,14 @@ +.request-invitation__dialog { + max-width: 90%; + border-radius: 0; +} + +.request-invitation__content { + padding: 2.5em 2em; +} + +.request-invitation__title { + display: flex; + text-align: center; + margin: 0 0 1.5em; +} \ No newline at end of file diff --git a/frontend/requests/request_invitation_dialog_mobile.html b/frontend/requests/request_invitation_dialog_mobile.html new file mode 100644 index 000000000..c7eceff01 --- /dev/null +++ b/frontend/requests/request_invitation_dialog_mobile.html @@ -0,0 +1,40 @@ + + + + Solicitar vínculo institucional + {{requestInvCtrl.request.institution_name}} +
    + + + +
    +
    Este campo é obrigatório!
    +
    +
    + + + + +
    +
    Este campo é obrigatório!
    +
    +
    + + + + +
    +
    Este campo é obrigatório!
    +
    +
    +
    + + Cancelar + + + Confirmar + +
    +
    +
    +
    diff --git a/frontend/requests/request_user_dialog.css b/frontend/requests/request_user_dialog.css new file mode 100644 index 000000000..ccc1f23a3 --- /dev/null +++ b/frontend/requests/request_user_dialog.css @@ -0,0 +1,46 @@ +.request-user__avatar{ + grid-area: avatar; + height: 3em; + width: 3em; + border-radius: 50%; +} + +.request-user__description-dialog{ + margin: 0; + color: #707070; +} + +.request-user__margin-user{ + margin: 0 0 8px 0; +} + +.request-user__requester-entity{ + display: grid; + grid-template-columns: max-content auto; + grid-template-rows: max-content max-content max-content; + grid-template-areas: + 'avatar title' + 'avatar subtitle' + 'avatar sub'; + grid-gap: 0 0.6rem; + padding: 0.6rem; + align-items: center; + background-color: #E0E0E0; +} + +.request-user__title { + grid-area: title; + line-height: 1rem; +} + +.request-user__subtitle { + grid-area: subtitle; + font-size: 0.8em; + line-height: 1rem; +} + +.request-user__sub{ + grid-area: sub; + font-size: 0.8em; + line-height: 1rem; +} \ No newline at end of file diff --git a/frontend/requests/request_user_dialog.html b/frontend/requests/request_user_dialog.html index 2aed9e4f7..e0d177176 100644 --- a/frontend/requests/request_user_dialog.html +++ b/frontend/requests/request_user_dialog.html @@ -1,37 +1,29 @@ - + -

    Confirmar Vínculo

    -

    +

    Confirmar Vínculo

    +

    {{requestCtrl.isRequestUser() ? "Um usuário da plataforma" : "Uma instituição"}} solicitou vincular-se a uma das instituições que você administra. Clique em confirmar para aceitar ou rejeitar para recusar vinculo.

    -
    -
    - {{requestCtrl.parent.name}} -
    -
    - {{ requestCtrl.parent.name }} - {{ requestCtrl.parent.email }} -
    -
    + +
    -
    -
    - {{ requestCtrl.children.name }} -
    -
    - {{ requestCtrl.getChildrenInstName(25)}} - {{ requestCtrl.getChildrenInstName(60)}} - {{ requestCtrl.getChildrenInstEmail(20) }} - {{ requestCtrl.getChildrenInstEmail(50) }} - {{ requestCtrl.children.office }} -
    +
    + + {{requestCtrl.getChildrenInstName()}} + + {{requestCtrl.getChildrenInstEmail()}} + + + Cargo: {{ requestCtrl.children.office }} +
    diff --git a/frontend/search/search.css b/frontend/search/search.css index 7b4a7ebb4..02c89daf3 100644 --- a/frontend/search/search.css +++ b/frontend/search/search.css @@ -6,10 +6,11 @@ width: 100%; font-size: 20px; z-index: 2; + overflow: hidden; } .search-mobile-content { - margin-top: 85px; + overflow: hidden; } .search-mobile-content form { @@ -54,7 +55,7 @@ .search-mobile-options-title { margin-top: 0.3em; - font-size: 1.5em; + font-size: 1.3em; margin-left: 7.5%; } @@ -88,4 +89,91 @@ #search-list-item div b { height: 2.8em; font-size: 0.75em; +} + +.search-event-input-margin { + margin: -0.4em 1.4em 0 1.2em; +} + +.search-event-input-name { + width: 90%; + margin-left: 1.2em; + font-size: 0.8em; +} + +.search-event-input { + border-color: #009688 !important; + margin-top: -1.2em; +} + +.search-event-title { + color: #009688; + font-size: 0.96em; +} + +.search-event-title { + margin-left: 0.17em; +} + +.search-event-select-menu { + margin: -0.3em 0em -2.35em 1.6em; + font-size: 0.7em; +} + +.search-event-select-menu-size { + width: 96%; +} + +.search-event-md-select { + width: 100%; +} + +.search-event-title-margin { + margin-bottom: 2em; + margin-left: 0.8em; +} + +.registered-insts-as-search-result { + margin-bottom: 0.5em; +} + +.single-inst-as-search-result { + border-style: solid; + border-width: 0.5px 0px 0px 0.5px; + border-color: white; +} + +.empty-card-as-search-result { + margin-top: 1em; + margin-left: auto; + margin-right: auto; +} + +.single-inst-as-search-result-container { + margin-left: 0.5em; + margin-right: 0.5em; +} + +.registered-insts-as-search-result-container { + display: grid; + grid-template-columns: 49% 49%; + grid-column-gap: 0.4em; + margin-top: 1em; +} + +.search-event-input-container { + padding: 0; + margin: 0; +} + +.search-event-select-container { + margin-bottom: 2em; +} + +.search-event-header { + margin-top: 1.2em; +} + +.search-event-scroll { + overflow: scroll; } \ No newline at end of file diff --git a/frontend/search/searchController.js b/frontend/search/searchController.js index 08301a64c..94ffdcf89 100644 --- a/frontend/search/searchController.js +++ b/frontend/search/searchController.js @@ -4,7 +4,7 @@ var app = angular.module('app'); app.controller("SearchController", function SearchController($state, InstitutionService, - brCidadesEstados, HttpService, $mdDialog, $window, STATES) { + brCidadesEstados, HttpService, $mdDialog, $window, STATES, AuthService) { var searchCtrl = this; @@ -17,6 +17,9 @@ var actuationAreas; var legalNatures; searchCtrl.loading = false; + searchCtrl.hasChanges = false; + searchCtrl.hasNotSearched = true; + searchCtrl.user = AuthService.getCurrentUser(); searchCtrl.makeSearch = function makeSearch(value, type) { searchCtrl.loading = false; @@ -25,10 +28,15 @@ promise.then(function success(response) { searchCtrl.institutions = response; searchCtrl.loading = true; + searchCtrl.hasChanges = true; }); return promise; }; + searchCtrl.setHasChanges = () => { + searchCtrl.hasChanges = Boolean(searchCtrl.search_keyword); + }; + searchCtrl.clearFilters = function clearFilters() { searchCtrl.searchActuation = ""; searchCtrl.searchNature = ""; @@ -49,15 +57,14 @@ searchCtrl.search = function search(ev) { if (searchCtrl.search_keyword) { let promise = searchCtrl.makeSearch(searchCtrl.search_keyword, 'institution'); - promise.then(() => { - if (Utils.isMobileScreen()) { - searchCtrl.showSearchFromMobile(ev); - } + searchCtrl.setupResultsInMobile(); }); refreshPreviousKeyword(); return promise; + } else { + searchCtrl.setupResultsInMobile(); } }; @@ -75,18 +82,18 @@ }; /** - * Open up a mdDialog to show the search result in a mobile fone - * @param {Event} ev + * Change the title position and the flag that decides + * if the results gotta be shown or not. */ - searchCtrl.showSearchFromMobile = (ev) => { - $mdDialog.show({ - controller: SearchDialogController, - controllerAs: "searchCtrl", - templateUrl: '/app/search/search_dialog.html', - parent: angular.element(document.body), - targetEvent: ev, - clickOutsideToClose: true, - }); + searchCtrl.setupResultsInMobile = () => { + if (searchCtrl.isMobileScreen()) { + const title = document.getElementById('search-title'); + if (title) { + title.style.marginTop = '1em'; + } + + searchCtrl.hasNotSearched = false; + } }; /** diff --git a/frontend/search/searchEventController.js b/frontend/search/searchEventController.js new file mode 100644 index 000000000..670010c24 --- /dev/null +++ b/frontend/search/searchEventController.js @@ -0,0 +1,169 @@ +'use strict'; + +(function () { + var app = angular.module('app'); + + app.controller("SearchEventController", function SearchEventController(brCidadesEstados, HttpService, + $window, STATES, AuthService, EventService) { + + var searchCtrl = this; + + searchCtrl.search_keyword = ''; + searchCtrl.previous_keyword = searchCtrl.search_keyword; + searchCtrl.events = []; + searchCtrl.loading = false; + searchCtrl.hasChanges = false; + searchCtrl.hasNotSearched = true; + searchCtrl.user = AuthService.getCurrentUser(); + + searchCtrl.makeSearch = function makeSearch(value, type) { + searchCtrl.loading = false; + const valueOrKeyword = value ? value : (searchCtrl.search_keyword || ""); + let promise = EventService.searchEvents(valueOrKeyword, "published", type); + promise.then(function success(response) { + searchCtrl.events = response; + searchCtrl.loading = true; + searchCtrl.hasChanges = true; + }); + return promise; + }; + + searchCtrl.setHasChanges = () => { + searchCtrl.hasChanges = Boolean(searchCtrl.search_keyword); + }; + + searchCtrl.clearFilters = function clearFilters() { + searchCtrl.searchState = ""; + searchCtrl.searchDate = ""; + searchCtrl.searchCountry = ""; + searchCtrl.searchCity = ""; + searchCtrl.events = []; + }; + + /** + * First of all it checks if there is a search + * keyword before make the search to avoid unecessary requests. + * Then, make search is called and the result is stored in + * searchCtrl.institutions. If the user is using a mobile + * showSearchFromMobile is called to open a mdDialog with the + * search's result. + * @param {Event} ev : The event that is useful to deal with the mdDialog. + * When the user isn't in a mobile its value is undefined. + */ + searchCtrl.search = function search() { + if (searchCtrl.search_keyword) { + let promise = searchCtrl.makeSearch(searchCtrl.search_keyword, 'event'); + promise.then(() => { + searchCtrl.setupResultsInMobile(); + refreshPreviousKeyword(); + }); + return promise; + } else { + searchCtrl.setupResultsInMobile(); + } + }; + + searchCtrl.searchBy = function searchBy(search) { + if (keywordHasChanges()) { + searchCtrl.makeSearch(search, 'event'); + refreshPreviousKeyword(); + } + }; + + /** + * Change the title position and the flag that decides + * if the results gotta be shown or not. + */ + searchCtrl.setupResultsInMobile = () => { + if (searchCtrl.isMobileScreen()) { + const title = document.getElementById('search-title'); + if (title) { + title.style.marginTop = '1em'; + } + + searchCtrl.hasNotSearched = false; + } + }; + + /** + * Go back to the previous state. + */ + searchCtrl.leaveMobileSearchPage = () => { + $window.history.back(); + }; + + /** + * Check if the user is in a mobile or not. + */ + searchCtrl.isMobileScreen = () => { + return Utils.isMobileScreen(); + }; + + /** + * Go to the page of a specific event + * @param {object} event - The current event + */ + searchCtrl.goToEvent = (event) => { + event.state !== 'deleted' && $state.go(STATES.EVENT_DETAILS, { eventKey: event.id }); + }; + + searchCtrl.isAnotherCountry = () => searchCtrl.searchCountry !== "Brasil"; + + searchCtrl.closeSearchResult = () => { + searchCtrl.hasNotSearched = true; + searchCtrl.clearFilters(); + refreshPreviousKeyword(); + searchCtrl.search_keyword = ''; + }; + + /** + * This function verifies if there is any changes in the search_keyword. + * If it has changes, the search will be made in the server and the + * previous_keyword will be updated. Otherwise, the search is just a filtering + * in the controller's institutions field. + */ + function keywordHasChanges() { + var keywordHasChanged = searchCtrl.search_keyword !== searchCtrl.previous_keyword; + return _.isEmpty(searchCtrl.institutions) || keywordHasChanged || !searchCtrl.search_keyword; + } + + /** + * Refreshes the previous_keyword field. It is called + * when the controller goes to the server to make the search, + * in other words, when the search_keywords changes. + */ + function refreshPreviousKeyword() { + searchCtrl.previous_keyword = searchCtrl.search_keyword; + } + + searchCtrl.isLoading = function isLoading() { + return !searchCtrl.loading && searchCtrl.search_keyword; + }; + + function loadSearch() { + if (searchCtrl.search_keyword) { + searchCtrl.makeSearch(searchCtrl.search_keyword, 'institution'); + } + } + + function loadCountries() { + HttpService.get('app/institution/countries.json').then(function success(response) { + searchCtrl.countries = response; + }); + } + + searchCtrl.getCitiesByState = () => { + searchCtrl.cities = brCidadesEstados.buscarCidadesPorSigla(searchCtrl.searchState.sigla); + }; + + function loadBrazilianFederalStates() { + searchCtrl.brazilianFederalStates = brCidadesEstados.estados; + } + + (function main() { + loadSearch(); + loadBrazilianFederalStates(); + loadCountries(); + })(); + }); +})(); \ No newline at end of file diff --git a/frontend/search/search_dialog.html b/frontend/search/search_dialog.html deleted file mode 100644 index 5e4e5c6c1..000000000 --- a/frontend/search/search_dialog.html +++ /dev/null @@ -1,26 +0,0 @@ - -
    - -

    Resultado da pesquisa

    - -
    - - account_balance - -
    - - {{ institution.name | limitTo: 45}}{{institution.name.length > 45 ? '...' : ''}} -
    -
    -
    - -
    - • Nenhuma instituição encontrada -
    -
    -
    -
    - -
    \ No newline at end of file diff --git a/frontend/search/search_event.html b/frontend/search/search_event.html new file mode 100644 index 000000000..6e2a254c7 --- /dev/null +++ b/frontend/search/search_event.html @@ -0,0 +1,68 @@ + + +
    +
    + Pesquisa avançada + + arrow_drop_down + +
    +
    + +

    INSTITUIÇÃO

    + +
    + + + + + + + {{country.nome_pais}} + + + + + + + + {{state.nome}} + + + + + + + + {{city}} + + + +
    +
    + + CANCELAR + + + PESQUISAR + +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/frontend/search/search_mobile.html b/frontend/search/search_mobile.html index c85412840..58086d149 100644 --- a/frontend/search/search_mobile.html +++ b/frontend/search/search_mobile.html @@ -1,54 +1,71 @@ - -
    - - clear - - PESQUISAR -
    -
    + + +
    +
    - +
    -
    +
    Pesquisa avançada + + arrow_drop_down +
    -
    - - - - {{actuation_area.name}} - - - - - - - {{nature.name}} - - - - - - - {{state.nome}} - - - +
    +
    + + + + {{actuation_area.name}} + + + + + + + {{nature.name}} + + + + + + + {{state.nome}} + + + +
    +
    + + CANCELAR + + + PESQUISAR + +
    -
    - - CANCELAR - - - PESQUISAR - +
    +
    + + +
    +
    + + +
    +
    + +
    - \ No newline at end of file +
    \ No newline at end of file diff --git a/frontend/sideMenu/factories/homeItems.factory.js b/frontend/sideMenu/factories/homeItems.factory.js index c2cc646bb..08c618ab7 100644 --- a/frontend/sideMenu/factories/homeItems.factory.js +++ b/frontend/sideMenu/factories/homeItems.factory.js @@ -3,7 +3,7 @@ (function () { angular .module('app') - .factory('HomeItemsFactory', function ($state, STATES, AuthService, $mdDialog, $window) { + .factory('HomeItemsFactory', function ($state, STATES, AuthService, $mdDialog, $window, SCREEN_SIZES) { const factory = {}; const url_report = Config.SUPPORT_URL + "/report"; @@ -40,7 +40,7 @@ icon: 'account_box', description: 'Meu Perfil', stateName: 'CONFIG_PROFILE', - onClick: () => $state.go(STATES.CONFIG_PROFILE) + onClick: () => $state.go(STATES.CONFIG_PROFILE, {userKey: user.key}) }, { icon: 'date_range', @@ -62,7 +62,12 @@ showIf: () => user.isAdminOfCurrentInst(), sectionTitle: 'INSTITUIÇÃO', topDivider: true, - onClick: () => $state.go(STATES.MANAGE_INST_EDIT, {institutionKey: getInstitutionKey()}), + onClick: () => { + const state = Utils.selectFieldBasedOnScreenSize( + STATES.MANAGE_INST_EDIT, STATES.MANAGE_INST_MENU_MOB, SCREEN_SIZES.SMARTPHONE + ); + $state.go(state, {institutionKey: getInstitutionKey()}); + }, }, { icon: 'account_circle', diff --git a/frontend/sideMenu/factories/manageInstItems.factory.js b/frontend/sideMenu/factories/manageInstItems.factory.js index 39704a451..d85f6437a 100644 --- a/frontend/sideMenu/factories/manageInstItems.factory.js +++ b/frontend/sideMenu/factories/manageInstItems.factory.js @@ -3,18 +3,19 @@ (function () { angular .module('app') - .factory('ManageInstItemsFactory', function ($state, STATES, $mdDialog) { + .factory('ManageInstItemsFactory', function ($state, STATES, $mdDialog, SCREEN_SIZES) { const factory = {}; const removeInstitution = (event, institution) => { - $mdDialog.show({ - templateUrl: 'app/institution/removeInstDialog.html', - targetEvent: event, - clickOutsideToClose:true, - locals: { institution }, - controller: "RemoveInstController", - controllerAs: 'removeInstCtrl' - }); + $mdDialog.show({ + templateUrl: Utils.selectFieldBasedOnScreenSize( + 'app/institution/removeInstDialog.html', 'app/institution/remove_inst_mobile.html', SCREEN_SIZES.SMARTPHONE), + targetEvent: event, + clickOutsideToClose:true, + locals: { institution }, + controller: "RemoveInstController", + controllerAs: 'removeInstCtrl' + }); }; factory.getItems = institution => { @@ -36,7 +37,14 @@ icon: 'account_balance', description: 'Vínculos Institucionais', stateName: 'MANAGE_INST_INVITE_INST', - onClick: () => $state.go(STATES.MANAGE_INST_INVITE_INST, {institutionKey}) + onClick: () => { + const state = Utils.selectFieldBasedOnScreenSize( + STATES.MANAGE_INST_INVITE_INST, + STATES.MANAGE_INST_LINKS, + SCREEN_SIZES.SMARTPHONES + ); + $state.go(state, {institutionKey}); + } }, { icon: 'delete', diff --git a/frontend/sideMenu/sideMenu.component.js b/frontend/sideMenu/sideMenu.component.js index 5fd094a6a..9270e29cd 100644 --- a/frontend/sideMenu/sideMenu.component.js +++ b/frontend/sideMenu/sideMenu.component.js @@ -16,6 +16,14 @@ HomeItemsFactory, ManageInstItemsFactory, InstitutionService, SIDE_MENU_TYPES) { const sideMenuCtrl = this; + const colorPickerButton = { + text: 'Gerenciar cores', + icon: 'color_lens', + }; + const backButton = { + text: 'Voltar', + icon: 'keyboard_arrow_left', + }; sideMenuCtrl.user = AuthService.getCurrentUser(); @@ -42,7 +50,7 @@ setItems(); }) .catch(err => { - MessageService.showToast("Um erro ocorreu. Não foi possível carregar a instituição."); + MessageService.showErrorToast("Um erro ocorreu. Não foi possível carregar a instituição."); }); }; @@ -92,17 +100,94 @@ return type === sideMenuCtrl.type; }; - sideMenuCtrl.openColorPicker = () => { + /** + * Store (internally) colorPicker's active state, + * allowing a single dynamic view for both mobile and desktop. + * When it's on: avatar is replaced with that institution's color; + * clicking on a institution changes that to current; + * last button on menu shows "Voltar" and toggles this variable; + * When it's off: institution's avatar is shown; + * clicking on a institution shows a dialog to pick a new color for that; + * last button on menu shows "Gerenciar cores". + */ + sideMenuCtrl._isColorPickerActive = false; + + /** + * Toggle colorPicker's active state. + */ + sideMenuCtrl.toggleColorPicker = () => { + sideMenuCtrl._isColorPickerActive = !sideMenuCtrl._isColorPickerActive; + } + + /** + * Gets user's current_institution profile. + * Needed to provide a default profile to #openColorPicker (desktop behavior). + */ + sideMenuCtrl.getCurrentInstitutionProfile = () => { + return _.find(sideMenuCtrl.user.institution_profiles, ['institution_key', sideMenuCtrl.user.current_institution.key]); + } + + /** + * Calls the correct function based on if it's a mobile screen, + * and current colorPicker's active state. + * The color picker dialog should only open here when on mobile + * AND the color picker is active. + * Otherwise, that should be made the current institution on the user. + * + * @param {Object} profile - institution profile to be made current or have its color changed + */ + sideMenuCtrl.institutionButtonAction = (profile) => { + sideMenuCtrl.isMobileScreen && sideMenuCtrl.isColorPickerActive ? + sideMenuCtrl.openColorPicker(profile) : + sideMenuCtrl.changeInstitution(profile); + } + + /** + * Defines a property .currentMenuOption, + * returning the current button based on colorPicker's active state. + */ + Object.defineProperty(sideMenuCtrl, 'currentMenuOption', { + get: function() { + return sideMenuCtrl.isColorPickerActive ? backButton : colorPickerButton; + } + }) + + /** + * Defines a property .isColorPickerActive, + * that always return true on desktop. + * On mobile, maps to internal _isColorPickerActive variable. + */ + Object.defineProperty(sideMenuCtrl, 'isColorPickerActive', { + get: function() { + return sideMenuCtrl.isMobileScreen ? sideMenuCtrl._isColorPickerActive : true; + } + }); + + /** + * Defines a property .isMobileScreen, + * shorthand for Utils.isMobileScreen(). + * Needed by the view to provide adequate buttons on desktop and mobile. + */ + Object.defineProperty(sideMenuCtrl, 'isMobileScreen', { + get: function() { + return Utils.isMobileScreen(); + }, + }); + + sideMenuCtrl.openColorPicker = (institution = sideMenuCtrl.getCurrentInstitutionProfile()) => { $mdDialog.show({ controller: "ColorPickerController", controllerAs: "colorPickerCtrl", - templateUrl: 'app/home/color_picker.html', + templateUrl: Utils.selectFieldBasedOnScreenSize('app/home/color_picker.html', + 'app/home/color_picker_mobile.html'), parent: angular.element(document.body), clickOutsideToClose: true, locals: { - user : sideMenuCtrl.user + user : sideMenuCtrl.user, + institution, }, - bindToController: true + bindToController: true, + onComplete: function() { sideMenuCtrl._isColorPickerActive = false }, }); }; } diff --git a/frontend/sideMenu/side_menu.css b/frontend/sideMenu/side_menu.css index 7e4520798..890f2c776 100644 --- a/frontend/sideMenu/side_menu.css +++ b/frontend/sideMenu/side_menu.css @@ -7,4 +7,25 @@ font-size: 12px; font-weight: 700; color: #019587; -} \ No newline at end of file +} + +img.avatar-icon { + padding: 0; + display: inline-block; + background-repeat: no-repeat no-repeat; + pointer-events: none; + width: 2em; + height: 2em; + border-radius: 50%; + margin-right: 0.6em; +} + +button.color-picker-button { + text-overflow: ellipsis; +} + +md-icon.color-picker-icon { + font-size: 2em; + margin-bottom: 0.3em !important; + margin-right: 0.5em !important; +} diff --git a/frontend/sideMenu/side_menu.html b/frontend/sideMenu/side_menu.html index 35213b44f..d144a4955 100644 --- a/frontend/sideMenu/side_menu.html +++ b/frontend/sideMenu/side_menu.html @@ -18,16 +18,21 @@ - - brightness_1 + + + brightness_1 {{ profile.institution.name }} - + - - color_lens + + color_lens GERENCIAR CORES + + {{ sideMenuCtrl.currentMenuOption.icon }} + {{ sideMenuCtrl.currentMenuOption.text }} + diff --git a/frontend/styles/custom.css b/frontend/styles/custom.css index 3551eab00..01e156495 100644 --- a/frontend/styles/custom.css +++ b/frontend/styles/custom.css @@ -5,6 +5,11 @@ height: 100vh; } +.fill-width { + width: 100%; + min-width: 100%; +} + @media screen and (max-width: 1366px) { .fill-screen { min-height: 0; @@ -212,10 +217,6 @@ background-color:#F5F5F5; } -.search-field{ - height: 75px; -} - a:link { text-decoration: none; } @@ -536,6 +537,15 @@ a:active { border: 2px solid #EFEBE9; } +@media screen and (max-width: 420px) { + .notification-badge[data-badge]:after { + background: #84C45E; + width: 11px; + height: 11px; + border: none; + } +} + .counter-of-notifications { position:relative; } @@ -696,12 +706,6 @@ a:active { border-radius: 50%; } -.survey-card{ - margin-top: -1px; - margin-left: 40px; - margin-right: 40px; -} - .sm-label { font-size: 0.9em; opacity: 0.75; @@ -722,10 +726,10 @@ a:active { margin-right: -16px; text-align: center; width: 78px; - height: 20px; + height: 17px; color: #616161; padding-top: 16px; - padding-bottom: 16px; + padding-bottom: 15px; } .percentage-selected{ @@ -862,10 +866,44 @@ md-radio-button.md-default-theme.md-checked .md-off, md-radio-button.md-checked border: 2px solid; } +.expired-survey { + background-color: rgba(190, 186, 186, 0.966); + text-align: center; + font-size: 15px; +} + @media only screen and (max-width: 600px) { .small-text { font-size: 15px; } + + .hyperlink { + color: #009688; + } + + .option { + margin: 0 12px; + } + + .post-details-container { + display: block; + width: 100%; + overflow: hidden; + } + + .expired-survey { + font-size: 13px; + padding: 4px 0; + background-color: rgb(0, 150, 136) + } + + #post-container { + margin: 8px 0; + } + + .hide-scrollbar-mobile::-webkit-scrollbar { + display: none; + } } @media only screen and (max-width: 450px) { @@ -894,19 +932,6 @@ md-radio-button.md-default-theme.md-checked .md-off, md-radio-button.md-checked box-shadow:0 0 12px #9E9E9E; } -.dialog-transparent-without-shadow { - background-color: rgba(0, 0, 0, 0); - box-shadow: 0 0 0; -} - -@media screen and (max-width: 960px) { - .dialog-transparent-without-shadow { - max-width: 100%; - max-height: 100%; - border-radius: 0; - } -} - .share-post{ max-height: 250px; overflow: auto; @@ -937,15 +962,18 @@ md-radio-button.md-default-theme.md-checked .md-off, md-radio-button.md-checked font-size: 10px; } -md-input-container:not(.md-input-invalid).md-input-has-value .inputEmail { +md-input-container:not(.md-input-invalid).md-input-focused .green-input, +md-input-container:not(.md-input-invalid).md-input-has-value.md-input-focused .green-input { border-color:#009688; border-width: 0 0 2px; } -.expired-survey { - background-color: rgba(190, 186, 186, 0.966); - text-align: center; - font-size: 15px; +md-radio-button:not([disabled]).md-primary .md-on { + background-color: teal; +} + +md-radio-group:not([disabled]) .md-primary.md-checked .md-off { + border-color: teal; } .shared-survey{ @@ -1115,6 +1143,15 @@ md-input-container:not(.md-input-invalid).md-input-has-value .inputEmail { border-bottom-color: #009688 !important; } +.custom-title { + font-size: 20px; + font-weight: 500; +} + +.zero-margin{ + margin: 0px; +} + /* Smartphones */ @media screen and (max-width: 420px) { .custom-card { @@ -1156,4 +1193,26 @@ md-input-container:not(.md-input-invalid).md-input-has-value .inputEmail { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -} \ No newline at end of file +} + +#post { + width: 100%; +} + +#post-page-container { + height: 100%; + overflow: hidden; +} + +#post-content { + max-height: 100%; +} + +#post-content > div { + max-height: 100%; + overflow-y: auto; +} + +side-menu { + z-index: 10; +} diff --git a/frontend/survey/survey.component.js b/frontend/survey/survey.component.js index 143a72eb6..cdb13ee77 100644 --- a/frontend/survey/survey.component.js +++ b/frontend/survey/survey.component.js @@ -46,11 +46,15 @@ return screen.width < 600; }; - /* This method add ids in each option and remove the options that are empty.*/ - function modifyOptions(){ - let id = 0; - surveyCtrl.options.map(option => option.text ? option.id = id++ : surveyCtrl.removeOption(option)); - } + /** + * Remove empty objects in the options array and add 'id' property in all objects. + * @private + */ + surveyCtrl._processOptions = () => { + surveyCtrl.options = surveyCtrl.options + .filter(option => option.text) + .map((option, index) => {option.id = index; return option;}); + }; function formateDate(){ var date = surveyCtrl.post.deadline.toISOString(); @@ -62,7 +66,7 @@ } function createSurvey(){ - modifyOptions(); + surveyCtrl._processOptions(); getTypeSurvey(); surveyCtrl.post.deadline && formateDate(); surveyCtrl.post.options = surveyCtrl.options; @@ -75,7 +79,7 @@ var promise = PostService.createPost(survey).then(function success(response) { surveyCtrl.resetSurvey(); $rootScope.$emit(POST_EVENTS.NEW_POST_EVENT_TO_UP, new Post(response)); - MessageService.showToast('Postado com sucesso!'); + MessageService.showInfoToast('Postado com sucesso!'); surveyCtrl.callback(); const postAuthorPermissions = ["remove_post"]; surveyCtrl.user.addPermissions(postAuthorPermissions, response.key); @@ -89,7 +93,7 @@ }); return promise; } else { - MessageService.showToast("Enquete deve ter no mínimo 2 opções e data limite definida"); + MessageService.showErrorToast("Enquete deve ter no mínimo 2 opções e data limite definida"); } }; diff --git a/frontend/survey/survey.css b/frontend/survey/survey.css index d39c0133b..fe4f801eb 100644 --- a/frontend/survey/survey.css +++ b/frontend/survey/survey.css @@ -38,6 +38,8 @@ .survey-card{ margin-top: -1px; + margin-left: 40px; + margin-right: 40px; } .survey-title-placeholder { @@ -65,6 +67,10 @@ grid-template-columns: auto 65px; } +.vote-btn { + display: grid; +} + @media screen and (max-width: 959px) { .survey-title-placeholder, { font-size: 0.84375em !important; @@ -193,6 +199,10 @@ .survey-title-placeholder, .survey-options { font-size: 0.75em !important; } + + .survey-card { + margin: 0; + } } @media screen and (max-width: 450px) { diff --git a/frontend/survey/surveyDetailsDirective.js b/frontend/survey/surveyDetailsDirective.js index 86f401bd3..5b93bf716 100644 --- a/frontend/survey/surveyDetailsDirective.js +++ b/frontend/survey/surveyDetailsDirective.js @@ -67,11 +67,11 @@ surveyCtrl.reloadPost(); }); }, function() { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); return dialog; } else { - MessageService.showToast('Você precisa escolher alguma alternativa'); + MessageService.showErrorToast('Você precisa escolher alguma alternativa'); } }; @@ -80,7 +80,7 @@ promise.then(function sucess(response){ surveyCtrl.post = response; addVote(surveyCtrl.optionsSelected); - MessageService.showToast('Voto computado'); + MessageService.showInfoToast('Voto computado'); }); return promise; }; diff --git a/frontend/survey/survey_details.html b/frontend/survey/survey_details.html index c64e19e2d..71f60e6d7 100644 --- a/frontend/survey/survey_details.html +++ b/frontend/survey/survey_details.html @@ -13,7 +13,7 @@ + ng-class="surveyCtrl.votedOption(option) || option.selected ?'option-selected':''" class="option"> @@ -30,10 +30,15 @@ -
    +
    VOTAR
    +
    + + VOTAR + +
    diff --git a/frontend/sw.js b/frontend/sw.js index 4bca0fe8a..8ac468170 100644 --- a/frontend/sw.js +++ b/frontend/sw.js @@ -9,6 +9,8 @@ // if the line number of the code below changes, modify the /ecis script. const CACHE_SUFIX = 'master'; + const openedNotifications = {}; + let messaging; function setupFirebase() { @@ -56,12 +58,23 @@ options.data = { url: options.click_action }; - } - options.vibrate = [100, 50, 100]; - options.badge = options.icon; + const body = JSON.parse(options.body); + + options.tag = body.type; + options.vibrate = [100, 50, 100]; + options.badge = options.icon; + + if(!openedNotifications[options.tag]) { + openedNotifications[options.tag] = 1; + } else { + openedNotifications[options.tag] +=1 + } - event.waitUntil(self.registration.showNotification(options.title, options)); + options.body = `${body.data} (${openedNotifications[options.tag]})`; + + event.waitUntil(self.registration.showNotification(options.title, options)); + } }); /** @@ -74,11 +87,13 @@ const { notification } = event; const { action } = event; + if(action !== 'close') { const { url } = notification.data; clients.openWindow(url); } - + + openedNotifications[notification.tag] = 0; notification.close(); }); diff --git a/frontend/test/specs/auth/configProfileControllerSpec.js b/frontend/test/specs/auth/configProfileControllerSpec.js deleted file mode 100644 index adb933065..000000000 --- a/frontend/test/specs/auth/configProfileControllerSpec.js +++ /dev/null @@ -1,361 +0,0 @@ -'use strict'; - -(describe('Test ConfigProfileController', function() { - var configCtrl, httpBackend, deffered, scope, userService, createCrtl, state, - mdToast, authService, imageService, mdDialog, cropImageService, states; - - var institution = { - name: 'institution', - key: '987654321' - }; - - var other_institution = { - name: 'other_institution', - key: '3279847298' - }; - - var user = { - name: 'User', - cpf: '121.445.044-07', - email: 'teste@gmail.com', - institutions: [institution], - uploaded_images: [], - institutions_admin: [], - state: 'active' - }; - - var newUser = { - name: 'newUser', - cpf: '121.115.044-07', - email: 'teste@gmail.com', - institutions: [institution], - institutions_admin: [] - }; - - beforeEach(module('app')); - - beforeEach(inject(function($controller, $httpBackend, $rootScope, $q, $state, STATES, - $mdToast, $mdDialog, UserService, AuthService, ImageService, CropImageService) { - - httpBackend = $httpBackend; - httpBackend.when('GET', 'main/main.html').respond(200); - httpBackend.when('GET', 'home/home.html').respond(200); - httpBackend.when('GET', 'auth/login.html').respond(200); - scope = $rootScope.$new(); - state = $state; - states = STATES; - imageService = ImageService; - mdToast = $mdToast; - mdDialog = $mdDialog; - deffered = $q.defer(); - userService = UserService; - cropImageService = CropImageService; - - authService = AuthService; - - authService.login(user); - - createCrtl = function() { - return $controller('ConfigProfileController', { - scope: scope, - authService: authService, - userService: userService, - imageService: imageService, - cropImageService : cropImageService - }); - }; - configCtrl = createCrtl(); - })); - - afterEach(function() { - httpBackend.verifyNoOutstandingExpectation(); - httpBackend.verifyNoOutstandingRequest(); - }); - - describe('main()', function() { - - it("should delete name from user if that is Unknown", function() { - var unknownUser = { - name: 'Unknown' - }; - - expect(unknownUser.name).not.toBeUndefined(); - - authService.getCurrentUser = function() { - return new User(unknownUser); - }; - - configCtrl = createCrtl(); - - expect(configCtrl.newUser.name).toBeUndefined(); - }); - }); - - describe('finish()', function(){ - - it("Should call mdToast.show", function(){ - spyOn(mdToast, 'show'); - - var userInvalid = { - name: 'Invalid User', - cpf: '', - email: 'invalidUser@gmail', - institutions: [institution] - }; - - configCtrl.newUser = new User(userInvalid); - expect(configCtrl.newUser.isValid()).toEqual(false); - - configCtrl.finish().should.be.rejected; - expect(mdToast.show).toHaveBeenCalled(); - }); - - it('Should change informations of user from system', function(done) { - spyOn(state, 'go'); - spyOn(userService, 'save').and.callThrough(); - - spyOn(authService, 'save'); - - - expect(configCtrl.newUser.name).toEqual(user.name); - expect(configCtrl.newUser.email).toEqual(user.email); - expect(configCtrl.newUser.cpf).toEqual(user.cpf); - - httpBackend.expect('PATCH', '/api/user').respond(newUser); - - var promise = configCtrl.finish(); - - promise.should.be.fulfilled.then(function() { - expect(state.go).toHaveBeenCalledWith(states.HOME); - expect(userService.save).toHaveBeenCalled(); - expect(authService.save).toHaveBeenCalled(); - }).should.notify(done); - - httpBackend.flush(); - scope.$apply(); - }); - }); - - describe('addImage()', function() { - beforeEach(function() { - var image = createImage(100); - spyOn(imageService, 'compress').and.callFake(function() { - return { - then: function(callback) { - return callback(image); - } - }; - }); - - spyOn(imageService, 'readFile').and.callFake(function() { - configCtrl.newUser.photo_url = "Base64 data of photo"; - }); - - spyOn(imageService, 'saveImage').and.callFake(function() { - return { - then: function(callback) { - return callback({ - url : "imagens/test" - }); - } - }; - }); - }); - - it('Should add new image in post', function() { - spyOn(userService, 'save').and.callThrough(); - - spyOn(authService, 'reload').and.callFake(function() { - return { - then: function(callback) { - return callback(newUser); - } - }; - }); - - httpBackend.expect('PATCH', '/api/user').respond(newUser); - - var image = createImage(100); - configCtrl.addImage(image); - configCtrl.finish(); - - httpBackend.flush(); - scope.$apply(); - - expect(imageService.compress).toHaveBeenCalled(); - expect(imageService.readFile).toHaveBeenCalled(); - expect(imageService.saveImage).toHaveBeenCalled(); - }); - }); - - describe('cropImage()', function() { - beforeEach(function() { - var image = createImage(100); - - spyOn(cropImageService, 'crop').and.callFake(function() { - return { - then : function(callback) { - return callback("Image"); - } - }; - }); - - spyOn(imageService, 'compress').and.callFake(function() { - return { - then: function(callback) { - return callback(image); - } - }; - }); - - spyOn(imageService, 'readFile').and.callFake(function() { - configCtrl.newUser.photo_url = "Base64 data of photo"; - }); - }); - - it('should crop image in config user', function() { - spyOn(configCtrl, 'addImage'); - var image = createImage(100); - configCtrl.cropImage(image); - expect(cropImageService.crop).toHaveBeenCalled(); - expect(configCtrl.addImage).toHaveBeenCalled(); - }); - }); - - describe('removeInstitution()', function() { - - var promise; - - beforeEach(function() { - spyOn(configCtrl.newUser, 'isAdmin'); - - spyOn(mdDialog, 'show').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - spyOn(userService, 'deleteInstitution').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - spyOn(authService, 'logout').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - spyOn(authService, 'save').and.callThrough(); - promise = configCtrl.removeInstitution('$event', institution); - }); - - it('Should call user.isAdmin()', function(done) { - promise.then(function() { - expect(configCtrl.newUser.isAdmin).toHaveBeenCalled(); - done(); - }); - }); - - it('Should call mdDialog.show()', function(done) { - promise.then(function() { - expect(mdDialog.show).toHaveBeenCalled(); - done(); - }); - }); - - it('Should call userService.deleteInstitution()', function(done) { - promise.then(function() { - expect(userService.deleteInstitution).toHaveBeenCalledWith(institution.key); - done(); - }); - }); - - it('Should call authService.logout()', function(done) { - promise.then(function() { - expect(authService.logout).toHaveBeenCalled(); - done(); - }); - }); - - it('Should call authService.save()', function(done) { - user.institutions.push(other_institution); - promise = configCtrl.removeInstitution('$event', institution); - - promise.then(function() { - expect(user.institutions).toEqual([other_institution]); - expect(authService.save).toHaveBeenCalled(); - done(); - }); - }); - }); - - describe('deleteAccount()', function() { - - var promise; - - beforeEach(function() { - spyOn(mdDialog, 'show').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - spyOn(userService, 'deleteAccount').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - spyOn(authService, 'logout').and.callFake(function() { - return { - then: function(callback) { - return callback(); - } - }; - }); - - promise = configCtrl.deleteAccount(); - }); - - it('Should call mdDialog.show()', function(done) { - promise.then(function() { - expect(mdDialog.show).toHaveBeenCalled(); - done(); - }); - }); - - it('Should call userService.deleteAccount()', function(done) { - promise.then(function() { - expect(userService.deleteAccount).toHaveBeenCalled(); - done(); - }); - }); - - it('Should call authService.logout()', function(done) { - promise.then(function() { - expect(authService.logout).toHaveBeenCalled(); - done(); - }); - }); - }); - - describe('editProfile', function() { - it('should call mdDialog.show', function() { - spyOn(mdDialog, 'show'); - configCtrl.editProfile(institution, '$event'); - expect(mdDialog.show).toHaveBeenCalled(); - }); - }); -})); \ No newline at end of file diff --git a/frontend/test/specs/auth/editProfileControllerSpec.js b/frontend/test/specs/auth/editProfileControllerSpec.js deleted file mode 100644 index 7c515bf95..000000000 --- a/frontend/test/specs/auth/editProfileControllerSpec.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -(describe('Test EditProfileController', function() { - - var httpBackend, scope, mdDialog, authService, profileService, editProfileCtrl, createCrtl, userToEdit; - - var institution = { - name: 'INSTITUTION', - key: '987654321' - }; - - var user = { - name: 'User', - email: 'teste@gmail', - institutions: [institution], - institution_profiles: [{ - office: 'developer', - phone: '(99) 99999-9999', - email: 'teste@gmail.com', - institution_key: institution.key - }], - state: 'active' - }; - - beforeEach(module('app')); - - beforeEach(inject(function($controller, $httpBackend, $rootScope, ProfileService, - $mdDialog, AuthService, MessageService) { - - httpBackend = $httpBackend; - httpBackend.when('GET', 'main/main.html').respond(200); - httpBackend.when('GET', 'home/home.html').respond(200); - httpBackend.when('GET', 'user/edit_profile.html').respond(200); - httpBackend.when('GET', 'auth/login.html').respond(200); - profileService = ProfileService; - scope = $rootScope.$new(); - mdDialog = $mdDialog; - authService = AuthService; - - authService.login(user); - - userToEdit = authService.getCurrentUser(); - - createCrtl = function() { - return $controller('EditProfileController', { - scope: scope, - institution: institution, - user: userToEdit, - profileService: profileService, - authService: authService, - mdDialog: mdDialog, - MessageService: MessageService - }); - }; - editProfileCtrl = createCrtl(); - })); - - describe('edit', function() { - it('should call editProfile() and save()', function() { - spyOn(profileService, 'editProfile').and.callThrough(); - spyOn(authService, 'save').and.callThrough(); - httpBackend.expect('PATCH', '/api/user').respond(userToEdit); - userToEdit.institution_profiles[0].office = 'Developer'; - editProfileCtrl.edit(); - httpBackend.flush(); - expect(profileService.editProfile).toHaveBeenCalled(); - expect(authService.save).toHaveBeenCalled(); - }); - }); - - describe('closeDialog', function() { - it('should call hide()', function() { - spyOn(mdDialog, 'hide'); - editProfileCtrl.closeDialog(); - expect(mdDialog.hide).toHaveBeenCalled(); - }); - }); -})); \ No newline at end of file diff --git a/frontend/test/specs/comment/commentControllerSpec.js b/frontend/test/specs/comment/commentControllerSpec.js index 9d6019424..4ac3af98b 100644 --- a/frontend/test/specs/comment/commentControllerSpec.js +++ b/frontend/test/specs/comment/commentControllerSpec.js @@ -211,7 +211,7 @@ commentCtrl.saving = true; spyOn(commentService, 'like').and.returnValue(deferred.promise); spyOn(commentCtrl, 'addLike').and.callThrough(); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); expect(commentCtrl.numberOfLikes()).toEqual(0); }); @@ -235,7 +235,7 @@ expect(commentService.like).toHaveBeenCalledWith(post.key, comment.id, null); expect(commentCtrl.addLike).not.toHaveBeenCalled(); expect(commentCtrl.numberOfLikes()).toEqual(0); - expect(messageService.showToast).toHaveBeenCalledWith("Não foi possível curtir o comentário"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Não foi possível curtir o comentário"); }); it('should like the reply', function() { @@ -260,7 +260,7 @@ expect(commentService.like).toHaveBeenCalledWith(post.key, comment.id, reply.id); expect(commentCtrl.addLike).not.toHaveBeenCalled(); expect(commentCtrl.numberOfLikes()).toEqual(0); - expect(messageService.showToast).toHaveBeenCalledWith("Não foi possível curtir o comentário"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Não foi possível curtir o comentário"); }); }); @@ -269,7 +269,7 @@ commentCtrl.saving = true; spyOn(commentService, 'dislike').and.returnValue(deferred.promise); spyOn(commentCtrl, 'removeLike').and.callThrough(); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); }); afterEach(function() { @@ -300,7 +300,7 @@ expect(commentService.dislike).toHaveBeenCalledWith(post.key, comment.id, null); expect(commentCtrl.removeLike).not.toHaveBeenCalled(); expect(commentCtrl.numberOfLikes()).toEqual(1); - expect(messageService.showToast).toHaveBeenCalledWith("Não foi possível descurtir o comentário"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Não foi possível descurtir o comentário"); }); it('should dislike the reply', function() { @@ -327,7 +327,7 @@ expect(commentService.dislike).toHaveBeenCalledWith(post.key, comment.id, null); expect(commentCtrl.removeLike).not.toHaveBeenCalled(); expect(commentCtrl.numberOfLikes()).toEqual(1); - expect(messageService.showToast).toHaveBeenCalledWith("Não foi possível descurtir o comentário"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Não foi possível descurtir o comentário"); }); }); @@ -368,14 +368,14 @@ commentCtrl.setReplyId(); expect(commentCtrl.comment.replies).toEqual(replies); spyOn(commentService, 'deleteReply').and.callThrough(); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); httpBackend.expect( 'DELETE', POSTS_URI + '/' + post.key + '/comments/'+ comment.id +'/replies/'+ reply.id ).respond(reply); commentCtrl.deleteReply(); httpBackend.flush(); expect(commentService.deleteReply).toHaveBeenCalledWith(post.key, comment.id, reply.id); - expect(messageService.showToast).toHaveBeenCalledWith('Comentário excluído com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Comentário excluído com sucesso'); expect(commentCtrl.comment.replies).toEqual({'nil-key': nilReply}); }); }); @@ -385,14 +385,14 @@ commentCtrl.post.data_comments = [comment]; expect(commentCtrl.post.data_comments).toEqual([comment]); spyOn(commentService, 'deleteComment').and.callThrough(); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); httpBackend.expect( 'DELETE', POSTS_URI + '/' + post.key + '/comments/' + comment.id ).respond(comment); commentCtrl.deleteComment(); httpBackend.flush(); expect(commentService.deleteComment).toHaveBeenCalledWith(post.key, comment.id); - expect(messageService.showToast).toHaveBeenCalledWith('Comentário excluído com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Comentário excluído com sucesso'); expect(commentCtrl.post.data_comments).toEqual([]); }); }); diff --git a/frontend/test/specs/event/canceledEventHeaderComponentSpec.js b/frontend/test/specs/event/canceledEventHeaderComponentSpec.js new file mode 100644 index 000000000..16a17fb83 --- /dev/null +++ b/frontend/test/specs/event/canceledEventHeaderComponentSpec.js @@ -0,0 +1,29 @@ +"use strict"; + +(describe("CanceledEventHeaderComponent", () => { + + let componentController, rootScope, + scope, event, canceledEventCtrl; + + event = { + last_modified_by: 'User Test', + }; + + beforeEach(module('app')); + + beforeEach(inject(($componentController, $rootScope) => { + + componentController = $componentController; + rootScope = $rootScope; + scope = rootScope.$new(); + canceledEventCtrl = componentController("canceledEventHeader", scope, + {event: event}); + })); + + describe('getNameOfLastModified()', () => { + it('Should return the first name of who modified the event by last', () => { + expect(canceledEventCtrl.event.last_modified_by).toEqual('User Test'); + expect(canceledEventCtrl.getNameOfLastModified()).toEqual('User'); + }); + }); +})); \ No newline at end of file diff --git a/frontend/test/specs/event/eventCardComponentSpec.js b/frontend/test/specs/event/eventCardComponentSpec.js new file mode 100644 index 000000000..df24f8417 --- /dev/null +++ b/frontend/test/specs/event/eventCardComponentSpec.js @@ -0,0 +1,51 @@ +"use strict"; + +(describe("EventCardComponent", () => { + + let componentController, authService, rootScope, + scope, institution, user, event, eventCardCtrl; + + institution = { + key: 'inst-key', + }; + + user = { + institution_profiles: [ + { + institution_key: institution.key, + color: 'pink' + } + ] + }; + + event = { + 'institution_key': institution.key, + }; + + beforeEach(module('app')); + + beforeEach(inject(($componentController, AuthService, $rootScope) => { + + componentController = $componentController; + authService = AuthService; + rootScope = $rootScope; + scope = rootScope.$new(); + authService.login(user); + eventCardCtrl = componentController("eventCard", scope, + {event: event, user: user}); + eventCardCtrl.user = user; + eventCardCtrl.event = event; + })); + + describe('getProfileColor()', () => { + + it('Should return the color if user is member of institution of event', () => { + expect(eventCardCtrl.getProfileColor()).toEqual(_.first(user.institution_profiles).color); + }); + + it('Should return a default color "teal" if user is not a member of institution of event', () => { + eventCardCtrl.user = {institution_profiles: []}; + expect(eventCardCtrl.getProfileColor()).toEqual('teal'); + }); + }); +})); \ No newline at end of file diff --git a/frontend/test/specs/event/eventControllerSpec.js b/frontend/test/specs/event/eventControllerSpec.js index fb5b9070a..b512a65d1 100644 --- a/frontend/test/specs/event/eventControllerSpec.js +++ b/frontend/test/specs/event/eventControllerSpec.js @@ -39,6 +39,8 @@ 'start_time': startDate, 'end_time': endDate, 'institution_key': institution.key, + 'institution_name': institution.name, + 'last_modified_by': 'User Test', 'key': '12345' }, other_event = { @@ -49,6 +51,7 @@ 'start_time': startDate, 'end_time': endDate, 'institution_key': other_institution.key, + 'institution_name': institution.name, 'key': '54321' }, requestEvent = { @@ -268,19 +271,6 @@ }); }); - describe('getProfileColor()', () => { - - it('Should return the color if user is member of institution of event', () => { - eventCtrl.user = user; - expect(eventCtrl.getProfileColor(event)).toEqual(_.first(user.institution_profiles).color); - }); - - it('Should return a default color "teal" if user is not a member of institution of event', () => { - eventCtrl.user = {institution_profiles: []}; - expect(eventCtrl.getProfileColor(event)).toEqual('teal'); - }); - }); - describe('loadFilteredEvents()', () => { it('Should reset moreEvents, actualPage and isAnotherMonth', () => { @@ -314,20 +304,26 @@ expect(eventCtrl._loadEvents).toHaveBeenCalled(); }); - it('Should call _loadEvents with eventService.getEvents', () => { + it('Should call _loadEvents with eventService.getEvents when key is null', () => { spyOn(eventCtrl, '_loadEvents'); + const params = { + page: eventCtrl._actualPage, month: december, year: testYear + } eventCtrl.institutionKey = null; eventCtrl.loadMoreEvents(); expect(eventCtrl._loadEvents) - .toHaveBeenCalledWith(eventService.getEvents, december, testYear); + .toHaveBeenCalledWith(eventService.getEvents, params); }); - it('Should call _loadEvents with eventService.getInstEvents', () => { + it("Should call _loadEvents with eventService.getEvents when key isn't null", () => { spyOn(eventCtrl, '_loadEvents'); eventCtrl.institutionKey = institution.key; + const params = { + page: eventCtrl._actualPage, institutionKey: eventCtrl.institutionKey + } eventCtrl.loadMoreEvents(); expect(eventCtrl._loadEvents) - .toHaveBeenCalledWith(eventService.getInstEvents, december, testYear); + .toHaveBeenCalledWith(eventService.getInstEvents, params); }); }); @@ -367,19 +363,27 @@ }); it('Should to increase the events of controller if not is another month', () => { - eventCtrl._isAnotherMonth = false; - eventCtrl.events = requestEvent.events; - expect(eventCtrl.events.length).toEqual(2); - eventCtrl._loadEvents(eventService.getEvents, december, testYear); - expect(eventCtrl.events.length).toEqual(4); + spyOn(Utils, 'isMobileScreen').and.callFake(() => true); + const ctrl = createCtrl(); + ctrl.showImage = true; + ctrl.$onInit(); + ctrl._isAnotherMonth = false; + ctrl.events = requestEvent.events; + expect(ctrl.events.length).toEqual(2); + ctrl._loadEvents(eventService.getEvents, december, testYear); + expect(ctrl.events.length).toEqual(4); }); it('Should update the events of controller if is another month', () => { - eventCtrl._isAnotherMonth = true; - eventCtrl.events = []; - eventCtrl._loadEvents(eventService.getEvents, december, testYear); - expect(eventCtrl.events).toEqual(requestEvent.events); - expect(eventCtrl._isAnotherMonth).toBeFalsy(); + spyOn(Utils, 'isMobileScreen').and.callFake(() => true); + const ctrl = createCtrl(); + ctrl.showImage = true; + ctrl.$onInit(); + ctrl._isAnotherMonth = true; + ctrl.events = []; + ctrl._loadEvents(eventService.getEvents, december, testYear); + expect(ctrl.events).toEqual(requestEvent.events); + expect(ctrl._isAnotherMonth).toBeFalsy(); }); }); diff --git a/frontend/test/specs/event/eventDetailsControllerSpec.js b/frontend/test/specs/event/eventDetailsControllerSpec.js index 709d4d76b..08ac4027e 100644 --- a/frontend/test/specs/event/eventDetailsControllerSpec.js +++ b/frontend/test/specs/event/eventDetailsControllerSpec.js @@ -2,7 +2,8 @@ (describe('Test EventDetailsController', function () { - let eventCtrl, scope, httpBackend, rootScope, deffered, eventService, messageService, mdDialog, state; + let eventCtrl, scope, httpBackend, rootScope, deffered, eventService, + messageService, mdDialog, state, clipboard, q, states; const splab = { name: 'Splab', key: '098745' }, @@ -38,7 +39,7 @@ beforeEach(module('app')); beforeEach(inject(function ($controller, $httpBackend, $http, $q, AuthService, - $rootScope, EventService, MessageService, $mdDialog, $state) { + $rootScope, EventService, MessageService, $mdDialog, $state, ngClipboard, STATES) { scope = $rootScope.$new(); httpBackend = $httpBackend; rootScope = $rootScope; @@ -47,6 +48,9 @@ messageService = MessageService; mdDialog = $mdDialog; state = $state; + clipboard = ngClipboard; + q = $q; + states = STATES; AuthService.login(user); eventCtrl = $controller('EventDetailsController', { @@ -72,6 +76,7 @@ describe('confirmDeleteEvent()', function () { beforeEach(function () { spyOn(mdDialog, 'confirm').and.callThrough(); + spyOn(state, 'go').and.callThrough(); spyOn(mdDialog, 'show').and.callFake(function () { return { then: function (callback) { @@ -91,6 +96,7 @@ expect(eventService.deleteEvent).toHaveBeenCalledWith(other_event); expect(mdDialog.confirm).toHaveBeenCalled(); expect(mdDialog.show).toHaveBeenCalled(); + expect(state.go).toHaveBeenCalledWith(states.EVENTS); }); }); @@ -192,8 +198,9 @@ eventCtrl.user.permissions = {}; eventCtrl.user.permissions['remove_post'] = {}; eventCtrl.user.permissions['remove_post'][event.key] = true; - - let returnedValue = eventCtrl.canChange(event); + eventCtrl.event = event; + + let returnedValue = eventCtrl.canChange(); expect(returnedValue).toBeTruthy(); eventCtrl.user.permissions = {}; @@ -250,4 +257,115 @@ expect(returnedHours).toEqual(hours); }); }); + + describe('copyLink()', () => { + it('should call toClipboard', () => { + spyOn(clipboard, 'toClipboard'); + spyOn(messageService, 'showInfoToast'); + + eventCtrl.event = new Event({key: 'aposdkspoakdposa'}); + eventCtrl.copyLink(); + + expect(clipboard.toClipboard).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalled(); + }); + }); + + describe('generateToolbarMenuOptions()', () => { + it('should set defaultToolbarOptions', () => { + expect(eventCtrl.defaultToolbarOptions).toBeFalsy(); + + eventCtrl.generateToolbarMenuOptions(); + + expect(eventCtrl.defaultToolbarOptions).toBeTruthy(); + expect(eventCtrl.defaultToolbarOptions.length).toEqual(5); + }); + }); + + describe('isFollower()', () => { + beforeEach(() => { + eventCtrl.event = new Event({ + followers: [] + }); + }); + + it('should return true when the user is following the event', () => { + eventCtrl.event.addFollower(user.key); + expect(eventCtrl.isFollower()).toEqual(true); + }); + + it('should return false when the user is not following the event', () => { + expect(eventCtrl.isFollower()).toEqual(false); + }); + }); + + describe('addFollower()', () => { + it('should call addFollower', () => { + spyOn(eventService, 'addFollower').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + eventCtrl.event = new Event({ key: 'aopskdopas-OKAPODKAOP', followers: [] }); + spyOn(eventCtrl.event, 'addFollower').and.callThrough(); + + eventCtrl.addFollower(); + scope.$apply(); + + expect(eventService.addFollower).toHaveBeenCalledWith(eventCtrl.event.key); + expect(messageService.showInfoToast).toHaveBeenCalled(); + expect(eventCtrl.event.addFollower).toHaveBeenCalled(); + expect(eventCtrl.event.followers).toEqual([user.key]); + }); + + it('should not add the user as follower when the service crashes', () => { + spyOn(eventService, 'addFollower').and.callFake(() => { + return q.reject(); + }); + + eventCtrl.event = new Event({ key: 'aopskdopas-OKAPODKAOP', followers: [] }); + spyOn(eventCtrl.event, 'addFollower').and.callThrough(); + + const promise = eventCtrl.addFollower(); + + promise.catch(() => { + expect(eventService.addFollower).toHaveBeenCalledWith(eventCtrl.event.key); + expect(eventCtrl.event.addFollower).not.toHaveBeenCalled(); + expect(eventCtrl.event.followers).toEqual([]); + }); + }); + }); + + describe('removeFollower()', () => { + it('should call removeFollower', () => { + spyOn(eventService, 'removeFollower').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + eventCtrl.event = new Event({ key: 'aopskdopas-OKAPODKAOP', followers: [] }); + spyOn(eventCtrl.event, 'removeFollower').and.callThrough(); + + eventCtrl.removeFollower(); + scope.$apply(); + + expect(eventService.removeFollower).toHaveBeenCalledWith(eventCtrl.event.key); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Você não receberá as atualizações desse evento.'); + expect(eventCtrl.event.removeFollower).toHaveBeenCalled(); + }); + + it('should not add the user as follower when the service crashes', () => { + spyOn(eventService, 'removeFollower').and.callFake(() => { + return q.reject(); + }); + + eventCtrl.event = new Event({ key: 'aopskdopas-OKAPODKAOP', followers: [] }); + spyOn(eventCtrl.event, 'removeFollower').and.callThrough(); + + const promise = eventCtrl.removeFollower(); + + promise.catch(() => { + expect(eventService.removeFollower).toHaveBeenCalledWith(eventCtrl.event.key); + expect(eventCtrl.event.removeFollower).not.toHaveBeenCalled(); + }); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/event/eventDialogCtrlSpec.js b/frontend/test/specs/event/eventDialogCtrlSpec.js index 72d8678af..46a877784 100644 --- a/frontend/test/specs/event/eventDialogCtrlSpec.js +++ b/frontend/test/specs/event/eventDialogCtrlSpec.js @@ -3,7 +3,7 @@ (describe('Test EventDialogController', function() { let controller, scope, httpBackend, rootScope, imageService, eventService, - messageService, newCtrl, state, mdDialog, states, deferred; + messageService, newCtrl, state, mdDialog, states, deferred, stateLinkRequestService, stateLinks; const splab = {name: 'Splab', key: '098745'}, @@ -48,7 +48,8 @@ beforeEach(module('app')); beforeEach(inject(function($controller, $httpBackend, AuthService, - $rootScope, ImageService, EventService, MessageService, $state, $mdDialog, STATES, $q) { + $rootScope, ImageService, EventService, MessageService, $state, $mdDialog, STATES, $q, + StateLinkRequestService, STATE_LINKS) { imageService = ImageService; scope = $rootScope.$new(); httpBackend = $httpBackend; @@ -60,6 +61,8 @@ mdDialog = $mdDialog; states = STATES; deferred = $q.defer(); + stateLinkRequestService = StateLinkRequestService; + stateLinks = STATE_LINKS; AuthService.login(user); controller = newCtrl('EventDialogController', { scope: scope, @@ -73,6 +76,7 @@ controller.events = []; controller.$onInit(); httpBackend.when('GET', 'app/institution/countries.json').respond(200); + httpBackend.when('GET', 'app/email/stateLinkRequest/stateLinkRequestDialog.html').respond(200); httpBackend.flush(); })); @@ -159,23 +163,23 @@ expect(eventService.createEvent).toHaveBeenCalledWith(event); }); - describe('MessageService.showToast()', () => { + describe('MessageService.showErrorToast()', () => { it('should be invalid, because title is undefined', () => { controller.event.title = undefined; - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); controller.save(); scope.$apply(); - expect(messageService.showToast).toHaveBeenCalledWith('Evento inválido!'); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Evento inválido!'); }); it('should be invalid, because local is undefined', () => { controller.event.title = "Inauguration"; controller.event.local = undefined; - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); controller.save(); scope.$apply(); - expect(messageService.showToast).toHaveBeenCalledWith('Evento inválido!'); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Evento inválido!'); }); }); @@ -255,11 +259,11 @@ controller.steps = [true, false, false]; }); - it('should call showToast', () => { - spyOn(messageService, 'showToast'); + it('should call showErrorToast', () => { + spyOn(messageService, 'showErrorToast'); controller.event.address = {country: 'Brasil'}; controller.nextStep(); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showErrorToast).toHaveBeenCalled(); }); it('should not pass from first step', () => { @@ -546,15 +550,15 @@ }); describe('in fail case', () => { - it('Should call messageService.showToast and state.go', () => { + it('Should call messageService.showErrorToast and state.go', () => { spyOn(eventService, 'getEvent').and.returnValue(deferred.promise); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); spyOn(state, 'go'); deferred.reject(); controller._loadEvent(event.key); scope.$apply(); expect(state.go).toHaveBeenCalledWith(states.HOME); - expect(messageService.showToast).toHaveBeenCalledWith("Erro ao carregar evento."); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Erro ao carregar evento."); }); }); }); @@ -627,6 +631,11 @@ country: "Brasil" }}); }); + it('should call showLinkRequestDialog', function () { + spyOn(stateLinkRequestService, 'showLinkRequestDialog'); + controller.$onInit(); + expect(stateLinkRequestService.showLinkRequestDialog).toHaveBeenCalledWith(stateLinks.CREATE_EVENT, states.EVENTS); + }); }); }); })); \ No newline at end of file diff --git a/frontend/test/specs/event/eventServiceSpec.js b/frontend/test/specs/event/eventServiceSpec.js index 7a3188fa1..014778464 100644 --- a/frontend/test/specs/event/eventServiceSpec.js +++ b/frontend/test/specs/event/eventServiceSpec.js @@ -133,5 +133,25 @@ httpBackend.flush(); expect($http.patch).toHaveBeenCalledWith(EVENT_URI + '/' + event.key, patch); }); + + describe('addFollower', () => { + it('should call post', () => { + spyOn($http, 'post'); + + service.addFollower('aposkpdoskpodkapd'); + + expect($http.post).toHaveBeenCalledWith('/api/events/aposkpdoskpodkapd/followers'); + }); + }); + + describe('removeFollower', () => { + it('should call delete', () => { + spyOn($http, 'delete'); + + service.removeFollower('aposkpdoskpodkapd'); + + expect($http.delete).toHaveBeenCalledWith('/api/events/aposkpdoskpodkapd/followers'); + }); + }); }); })); \ No newline at end of file diff --git a/frontend/test/specs/event/eventSpec.js b/frontend/test/specs/event/eventSpec.js index fe3022987..e51ae4a44 100644 --- a/frontend/test/specs/event/eventSpec.js +++ b/frontend/test/specs/event/eventSpec.js @@ -13,7 +13,8 @@ title: 'event test', local: 'test', start_time, - end_time + end_time, + followers: [] }; }); @@ -54,4 +55,33 @@ expect(event.end_time).toEqual(end_time_conv); }); }); + + describe('addFollower()', () => { + it('should add the user in followers array', () => { + const event = new Event(eventData, institution_key); + + expect(event.followers).toEqual([]); + + const mockedKey = 'aopkdopkasop-AKPDFKOSPAF'; + event.addFollower(mockedKey); + + expect(event.followers).toEqual([mockedKey]); + }); + }); + + describe('removeFollower()', () => { + it('should remove a follower', () => { + const event = new Event(eventData, institution_key); + + expect(event.followers).toEqual([]); + + const mockedKey = 'aopkdopkasop-AKPDFKOSPAF'; + event.addFollower(mockedKey); + + expect(event.followers).toEqual([mockedKey]); + + event.removeFollower(mockedKey); + expect(event.followers).toEqual([]); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/event/filterEvents/filterEventsByInstitutionControllerSpec.js b/frontend/test/specs/event/filterEvents/filterEventsByInstitutionControllerSpec.js new file mode 100644 index 000000000..e832decf7 --- /dev/null +++ b/frontend/test/specs/event/filterEvents/filterEventsByInstitutionControllerSpec.js @@ -0,0 +1,131 @@ +'use strict'; + +(describe('Test FilterEventsByInstitutionController', function() { + beforeEach(module('app')); + + let filterCtrl, inst, other_inst, filterList; + + beforeEach(inject(function($controller) { + inst = { + name: 'institution', + enable: true + }; + + other_inst = { + name: 'institution', + enable: true + }; + + filterList = [inst, other_inst]; + + filterCtrl = $controller('FilterEventsByInstitutionController'); + filterCtrl.filterList = filterList; + filterCtrl.$onInit(); + })); + + + describe('test checkChange()', function() { + it('Should be change filterCtrl.enableAll to false', function() { + inst.enable = false; + other_inst.enable = true; + filterCtrl.checkChange(); + expect(filterCtrl.enableAll).toBeFalsy(); + + inst.enable = true; + other_inst.enable = false; + filterCtrl.checkChange(); + expect(filterCtrl.enableAll).toBeFalsy(); + + inst.enable = false; + other_inst.enable = false; + filterCtrl.checkChange(); + expect(filterCtrl.enableAll).toBeFalsy(); + }); + + it('Should be change filterCtrl.enableAll to true', function() { + inst.enable = true; + other_inst.enable = true; + filterCtrl.checkChange(); + expect(filterCtrl.enableAll).toBeTruthy(); + }); + }); + + describe('test enableOrDisableAll', function() { + it('Should be enable all filters', function() { + inst.enable = false; + other_inst.enable = false; + filterCtrl.enableAll = true; + + filterCtrl.enableOrDisableAll(); + expect(inst.enable).toBeTruthy(); + expect(other_inst.enable).toBeTruthy(); + + inst.enable = false; + other_inst.enable = true; + filterCtrl.enableAll = true; + + filterCtrl.enableOrDisableAll(); + expect(inst.enable).toBeTruthy(); + expect(other_inst.enable).toBeTruthy(); + }); + + it('Should be disable all filters', function() { + inst.enable = true; + other_inst.enable = true; + filterCtrl.enableAll = false; + + filterCtrl.enableOrDisableAll(); + expect(inst.enable).toBeFalsy(); + expect(other_inst.enable).toBeFalsy(); + + inst.enable = true; + other_inst.enable = false; + filterCtrl.enableAll = false; + + filterCtrl.enableOrDisableAll(); + expect(inst.enable).toBeFalsy(); + expect(other_inst.enable).toBeFalsy(); + }); + }); + + describe('test cancel()', function() { + it('Should be return to original configs', function() { + filterCtrl.cancelAction = () => {}; + spyOn(filterCtrl, 'cancelAction'); + + const originalList = [ + { + name: 'institution', + enable: true + }, + { + name: 'institution', + enable: true + } + ]; + + inst.enable = false; + other_inst.enable = false; + + expect(originalList).toEqual(filterCtrl.originalList); + expect(originalList).not.toEqual(filterCtrl.filterList); + + filterCtrl.cancel(); + + expect(originalList).toEqual(filterCtrl.filterList); + expect(filterCtrl.cancelAction).toHaveBeenCalled(); + }); + }); + + describe('test $onInit', function() { + it('Should be clone the original filterList', function() { + spyOn(filterCtrl, 'checkChange'); + + filterCtrl.originalList = []; + filterCtrl.$onInit(); + + expect(filterCtrl.originalList).toEqual(filterList); + expect(filterCtrl.checkChange).toHaveBeenCalled(); + }); + }); +})); \ No newline at end of file diff --git a/frontend/test/specs/home/colorPickerControllerSpec.js b/frontend/test/specs/home/colorPickerControllerSpec.js index a25027f38..a9789295a 100644 --- a/frontend/test/specs/home/colorPickerControllerSpec.js +++ b/frontend/test/specs/home/colorPickerControllerSpec.js @@ -8,7 +8,15 @@ var institution = { 'email' : 'institution@gmail.com', 'key': '123456', - 'institution_key' : '123456' + 'institution_key' : '123456', + 'color' : 'teal', + }; + + const secondInstitution = { + 'email' : 'institution2@gmail.com', + 'key': '1234567', + 'institution_key' : '1234567', + 'color' : 'teal', }; var colors = [{'value' : 'red'}, {'value':'purple'}, {'value':'blue'}]; @@ -17,10 +25,10 @@ 'name' : 'user', 'key': '12345', 'state' : 'active', - 'institution_profiles': [institution], - 'current_institution' : institution + 'institution_profiles': [institution, secondInstitution], + 'current_institution' : institution, }; - + beforeEach(inject(function ($controller, $httpBackend, HttpService, $mdDialog, AuthService, $rootScope, ProfileService) { scope = $rootScope.$new(); @@ -31,7 +39,8 @@ profileService = ProfileService; colorPickerCtrl = $controller('ColorPickerController', { - user: user + user, + institution, }); AuthService.login(user); @@ -54,25 +63,49 @@ describe('saveColor()', function() { beforeEach(function() { spyOn(profileService, 'editProfile').and.callThrough(); - }); - it('Should return true', function(done) { - var change = { + it('should change first institutions color', function(done) { + const change = { 'color' : 'blue', 'email' : 'institution@gmail.com', 'key': '123456', 'institution_key' : '123456' }; - colorPickerCtrl.newProfile = change; - colorPickerCtrl.newUser.institution_profiles = [change]; + colorPickerCtrl.newUser.institution_profiles = [change, secondInstitution]; + const diff = jsonpatch.compare(colorPickerCtrl.user, colorPickerCtrl.newUser); httpBackend.expect('PATCH', '/api/user').respond(200); - var promise = colorPickerCtrl.saveColor(); + const promise = colorPickerCtrl.saveColor(); promise.should.be.fulfilled.then(function() { - expect(colorPickerCtrl.user.getProfileColor()).toBe('blue'); - expect(colorPickerCtrl.user.institution_profiles).toHaveBeenCalled(change); - }).should.notify(done); + expect(colorPickerCtrl.user).toEqual(colorPickerCtrl.newUser); + expect(colorPickerCtrl.user.institution_profiles[0]).toEqual(change); + expect(profileService.editProfile).toHaveBeenCalledWith(diff); + done(); + }); + httpBackend.flush(); + scope.$apply(); + }); + + it('should change second institutions color', (done) => { + const change = { + 'color': 'red', + 'email' : 'institution2@gmail.com', + 'key': '1234567', + 'institution_key' : '1234567' + } + + colorPickerCtrl.newUser.institution_profiles = [institution, change]; + const diff = jsonpatch.compare(colorPickerCtrl.user, colorPickerCtrl.newUser); + + httpBackend.expect('PATCH', '/api/user').respond(200); + const promise = colorPickerCtrl.saveColor(); + promise.should.be.fulfilled.then(function() { + expect(colorPickerCtrl.user).toEqual(colorPickerCtrl.newUser); + expect(colorPickerCtrl.user.institution_profiles[1]).toEqual(change); + expect(profileService.editProfile).toHaveBeenCalledWith(diff); + done(); + }); httpBackend.flush(); scope.$apply(); }); diff --git a/frontend/test/specs/home/homeControllerSpec.js b/frontend/test/specs/home/homeControllerSpec.js index 529f89560..43e679d3d 100644 --- a/frontend/test/specs/home/homeControllerSpec.js +++ b/frontend/test/specs/home/homeControllerSpec.js @@ -63,6 +63,7 @@ spyOn($rootScope, '$on').and.callThrough(); homeCtrl = createCtrl(); + homeCtrl.$onInit(); httpBackend.flush(); expect($rootScope.$on).toHaveBeenCalled(); diff --git a/frontend/test/specs/institution/configInstDirectiveSpec.js b/frontend/test/specs/institution/configInstDirectiveSpec.js index d19e7467f..6ff56ca9e 100644 --- a/frontend/test/specs/institution/configInstDirectiveSpec.js +++ b/frontend/test/specs/institution/configInstDirectiveSpec.js @@ -3,7 +3,7 @@ describe('Test ConfigInstDirective', function() { var editInstCtrl, scope, institutionService, state, deferred; var mdToast, mdDialog, http, inviteService, httpBackend, imageService; - let authService, createCtrl, pdfService, messageService, states; + let authService, createCtrl, pdfService, messageService, states, stateLinkRequestService; var address = { cep: "11111-000", @@ -84,7 +84,8 @@ describe('Test ConfigInstDirective', function() { beforeEach(module('app')); beforeEach(inject(function($controller, $httpBackend, $q, $state, $mdToast, STATES, - $rootScope, $mdDialog, $http, InstitutionService, InviteService, AuthService, PdfService, ImageService, MessageService) { + $rootScope, $mdDialog, $http, InstitutionService, InviteService, AuthService, PdfService, ImageService, MessageService, + StateLinkRequestService) { httpBackend = $httpBackend; httpBackend.expectGET('app/institution/legal_nature.json').respond(legal_nature); httpBackend.expectGET('app/institution/actuation_area.json').respond(actuation_area); @@ -93,6 +94,8 @@ describe('Test ConfigInstDirective', function() { httpBackend.when('GET', 'main/main.html').respond(200); httpBackend.when('GET', 'home/home.html').respond(200); httpBackend.when('GET', 'auth/login.html').respond(200); + httpBackend.when('GET', 'app/email/stateLinkRequest/stateLinkRequestDialog.html').respond(200); + httpBackend.when('GET', '/api/institutions/inst-key').respond(institution); scope = $rootScope.$new(); state = $state; deferred = $q.defer(); @@ -106,6 +109,7 @@ describe('Test ConfigInstDirective', function() { pdfService = PdfService; http = $http; states = STATES; + stateLinkRequestService = StateLinkRequestService; authService.login(userData); state.params.institutionKey = institution.key; @@ -160,6 +164,13 @@ describe('Test ConfigInstDirective', function() { expect(state.go).toHaveBeenCalledWith(states.SIGNIN); }); + it('should call showLinkRequestDialog', function () { + spyOn(stateLinkRequestService, 'showLinkRequestDialog'); + editInstCtrl.initController(); + expect(stateLinkRequestService.showLinkRequestDialog).toHaveBeenCalled(); + httpBackend.flush(); + }); + afterEach(function() { editInstCtrl.institutionKey = institution.key; editInstCtrl.user.state = 'active'; @@ -305,11 +316,11 @@ describe('Test ConfigInstDirective', function() { expect(editInstCtrl.steps).toEqual([false, false, true]); }); - it('should call showToast', function() { - spyOn(messageService, 'showToast'); + it('should call showErrorToast', function() { + spyOn(messageService, 'showErrorToast'); editInstCtrl.newInstitution.address = {}; editInstCtrl.nextStep(); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Campos obrigatórios não preenchidos corretamente.'); }); it('should not pass from first step', function() { diff --git a/frontend/test/specs/institution/createInvitedInstitutionSpec.js b/frontend/test/specs/institution/createInvitedInstitutionSpec.js new file mode 100644 index 000000000..f404113cf --- /dev/null +++ b/frontend/test/specs/institution/createInvitedInstitutionSpec.js @@ -0,0 +1,337 @@ +'use strict'; + +describe('Test CreateInvitedInstitutionController', function() { + let state, statesConst, scope, institutionService, inviteService, + authService, ctrl, imageService, mdDialog, observerRecorderService; + + const address = { + country: 'Brasil', + street: 'Street', + federal_state: 'State', + neighbourhood: 'Neighbourhood', + city: 'City', + cep: '12345-768' + } + + const institution = { + name: "name", + photo_url: "imagens/test", + email: "email", + state: "pending", + key: "inst-key", + acronym: "INST", + legal_nature: "public", + actuation_area: "government agencies", + phone_number: "phone", + cnpj: "cnpj", + address: new Address(address), + leader: "leader name", + institutional_email: "email@institutional.com", + description: "teste" + } + + const emptyInstitution = { + name: "name", + key: "inst-key", + } + + const institutions = [{ + name: 'Splab', + key: 'institution_key', + portfolio_url: '', + followers: [], + members: [] + }]; + + const invite = { + 'invitee': 'user@email.com', + 'suggestion_institution_name': "Suggested Name", + 'type_of_invite': "INSTITUTION", + status: 'sent', + key: 'invite-key' + }; + + const userData = { + name: 'name', + key: 'user-key', + current_institution: {key: "institution_key"}, + institutions: institutions, + institutions_admin: [], + follows: institutions, + institution_profiles: [], + email: ['test@test.com'], + invites: [invite], + state: 'active' + } + + beforeEach(module('app')); + + beforeEach(inject(($controller, $httpBackend, $state, STATES, InviteService, InstitutionService, AuthService, ImageService, $rootScope, $mdDialog, ObserverRecorderService) => { + state = $state; + scope = $rootScope.$new(); + statesConst = STATES; + authService = AuthService; + imageService = ImageService; + institutionService = InstitutionService; + mdDialog = $mdDialog; + observerRecorderService = ObserverRecorderService; + authService.login(userData); + state.params.institutionKey = institution.key; + + ctrl = $controller('CreateInvitedInstitutionController', { + scope, + authService, + institutionService, + imageService + }); + })); + + describe('$onInit', () => { + it('should call initialization methods when theres a inst key', () => { + spyOn(ctrl, 'loadInstitution').and.callFake(() => Promise.resolve()); + spyOn(authService, 'getCurrentUser').and.callFake(() => Promise.resolve()); + + ctrl.$onInit(); + expect(authService.getCurrentUser).toHaveBeenCalled(); + expect(ctrl.loadInstitution).toHaveBeenCalled(); + }); + + it('should redirect to STATES.HOME when theres no institution key', () => { + state.params.institutionKey = ''; + spyOn(state, 'go').and.callThrough(); + ctrl.$onInit(); + expect(state.go).toHaveBeenCalledWith(statesConst.HOME); + }); + }); + + describe('loadInstitution', () => { + it('should load default institution data', (done) => { + spyOn(institutionService, 'getInstitution').and.callFake(() => Promise.resolve(emptyInstitution)); + ctrl.institutionKey = 'inst-key'; + + ctrl.loadInstitution().then(() => { + expect(institutionService.getInstitution).toHaveBeenCalledWith(institution.key); + expect(ctrl.newInstitution).toBe(emptyInstitution); + expect(ctrl.suggestedName).toEqual(emptyInstitution.name); + expect(ctrl.newInstitution.photo_url).toEqual('app/images/institution.png'); + const newAddress = ctrl.newInstitution.address; + _.mapKeys(newAddress, (value, key) => { + if (key === 'country') { + expect(value).toEqual('Brasil'); + } else { + expect(value).toEqual(''); + } + }); + + done(); + }); + }); + }); + + describe('isCurrentStepValid', () => { + beforeEach(() => { + // Assign a valid institution, + // so we can both test acceptance, + // and strip values to test for rejections + ctrl.newInstitution = _.cloneDeep(institution); + }); + + describe('first step', () => { + describe('when country is Brasil', () => { + beforeEach(() => { + ctrl.currentStep = 0; + }); + + it('should reject empty street', () => { + ctrl.newInstitution.address.street = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject empty city', () => { + ctrl.newInstitution.address.city = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject empty state', () => { + ctrl.newInstitution.address.federal_state = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject empty neighbourhood', () => { + ctrl.newInstitution.address.cep = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject empty cep', () => { + ctrl.newInstitution.address.cep = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should accept a complete address', () => { + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeTruthy(); + }); + }); + + describe('when its a foreign country', () => { + beforeEach(() => { + ctrl.newInstitution.address = { + country: 'Argentina', + street: '', + federal_state: '', + neighbourhood: '', + city: '', + cep: '' + }; + ctrl.currentStep = 0; + }); + + it('should reject an empty country', () => { + ctrl.newInstitution.address.country = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should accept an address with only its country present', () => { + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeTruthy(); + }); + }); + }); + + describe('second step', () => { + beforeEach(() => { + ctrl.currentStep = 1; + }); + + it('should reject an empty name', () => { + ctrl.newInstitution.name = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject an empty actuation_area', () => { + ctrl.newInstitution.actuation_area = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject an empty legal_nature', () => { + ctrl.newInstitution.legal_nature = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject an empty institutional_email', () => { + ctrl.newInstitution.institutional_email = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should accept a complete institution', () => { + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeTruthy(); + }); + }); + + describe('third step', () => { + beforeEach(() => { + ctrl.currentStep = 2; + }); + + it('should reject an empty description', () => { + ctrl.newInstitution.description = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should reject an empty leader', () => { + ctrl.newInstitution.description = ''; + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeFalsy(); + }); + + it('should accept a complete institution', () => { + const validation = ctrl.isCurrentStepValid(); + expect(validation).toBeTruthy(); + }); + }); + }); + + describe('submit', () => { + let patch; + + beforeEach(() => { + ctrl.newInstitution = _.cloneDeep(institution); + ctrl.photoSrc = 'some_image_data'; + ctrl.institutionKey = ctrl.newInstitution.key; + + // Hard code photo_url so the returned patch is equal to later patch + ctrl.newInstitution.photo_url = 'imageurl'; + patch = jsonpatch.compare(emptyInstitution, ctrl.newInstitution); + + spyOn(mdDialog, 'show').and.callFake(() => Promise.resolve()); + spyOn(angular, 'element'); + spyOn(observerRecorderService, 'generate').and.returnValues(patch); + spyOn(imageService, 'saveImage').and.callFake(() => { + return Promise.resolve({ url: 'imageurl' }); + }); + + spyOn(institutionService, 'save').and.callFake(() => { + return Promise.resolve(); + }); + + spyOn(institutionService, 'update').and.callFake(() => { + return Promise.resolve(ctrl.newInstitution); + }); + + spyOn(state, 'go') + spyOn(authService, 'save'); + spyOn(authService, 'reload').and.callFake(() => { + return Promise.resolve(); + }); + + ctrl.user = new User(userData); + spyOn(ctrl.user, 'removeInvite'); + spyOn(ctrl.user, 'follow'); + spyOn(ctrl.user, 'addProfile'); + spyOn(ctrl.user, 'changeInstitution'); + }); + + it('correctly save institution data', (done) => { + ctrl.submit({}).then(() => { + expect(imageService.saveImage).toHaveBeenCalledWith('some_image_data'); + expect(ctrl.newInstitution.photo_url).toEqual('imageurl'); + expect(observerRecorderService.generate).toHaveBeenCalled(); + expect(institutionService.save).toHaveBeenCalled(); + + // Needed here so image url replacing is correctly tested + patch = jsonpatch.compare(emptyInstitution, ctrl.newInstitution); + expect(institutionService.update).toHaveBeenCalledWith(ctrl.newInstitution.key, patch); + expect(state.go).toHaveBeenCalled(); + expect(authService.reload).toHaveBeenCalled(); + done(); + }); + }); + + it('updates user data', (done) => { + state.params.inviteKey = invite.key; + + ctrl.submit({}).then(() => { + expect(ctrl.user.removeInvite).toHaveBeenCalledWith(invite.key); + expect(ctrl.user.follow).toHaveBeenCalledWith(ctrl.newInstitution); + expect(ctrl.user.addProfile).toHaveBeenCalled(); + expect(ctrl.user.changeInstitution).toHaveBeenCalledWith(ctrl.newInstitution); + expect(ctrl.user.institutions).toContain(ctrl.newInstitution); + expect(ctrl.user.institutions_admin).toContain(ctrl.newInstitution.key); + done(); + }); + }); + }); +}); + diff --git a/frontend/test/specs/institution/editDescriptionControllerSpec.js b/frontend/test/specs/institution/editDescriptionControllerSpec.js new file mode 100644 index 000000000..ccf631000 --- /dev/null +++ b/frontend/test/specs/institution/editDescriptionControllerSpec.js @@ -0,0 +1,79 @@ +'use strict'; + +describe('Test Edit Description Institution', function() { + beforeEach(module('app')); + + var data, institution, editDescriptionCtrl, httpBackend, + observerRecorderService, scope, state, mdDialog, institutionService; + + var user = new User({ + institutions: [], + follows: [] + }); + + const fakeCallback = function(){ + const fakeResponse = callback => callback(); + return { + then: fakeResponse, + catch: fakeResponse, + finally: fakeResponse + }; + }; + + beforeEach(inject(function($controller, $httpBackend, $rootScope, $state, AuthService, + ObserverRecorderService, $mdDialog, InstitutionService) { + httpBackend = $httpBackend; + scope = $rootScope.$new(); + state = $state; + mdDialog = $mdDialog; + institutionService = InstitutionService; + observerRecorderService = ObserverRecorderService; + + AuthService.login(user); + + institution = { + name: 'InstName', + address: { + street: 'StreetName', + number: 1, + neighbourhood: 'NeighbourhoddName', + city: 'CityName', + federal_state: 'FederalStateName', + country: 'Brasil' + }, + state: 'active', + leader: 'LeaderName', + legal_nature: 'Public', + actuation_area: 'Laboratory', + description: 'institutionDescription', + sent_invitations: [], + parent_institution: null, + children_institutions: [], + key: 'instKey' + }; + + institution = new Institution(data); + + state.params.institution = institution; + editDescriptionCtrl = $controller('EditDescriptionController',{ + scope: scope, + institutionService: institutionService, + institution: institution + }); + editDescriptionCtrl.$onInit(); + })); + + describe('save()', function () { + beforeEach(function() { + spyOn(institutionService, 'update').and.callFake(fakeCallback); + spyOn(mdDialog, 'hide').and.callThrough(); + }); + + it('should update and call functions', function () { + editDescriptionCtrl.institution.description = "edit description"; + editDescriptionCtrl.save(); + expect(institutionService.update).toHaveBeenCalled(); + expect(mdDialog.hide).toHaveBeenCalled(); + }); + }); +}); \ No newline at end of file diff --git a/frontend/test/specs/institution/institutionControllerSpec.js b/frontend/test/specs/institution/institutionControllerSpec.js index a84eb2c95..d6e5efeec 100644 --- a/frontend/test/specs/institution/institutionControllerSpec.js +++ b/frontend/test/specs/institution/institutionControllerSpec.js @@ -255,20 +255,33 @@ expect(institutionService.update).toHaveBeenCalled(); }); }); + describe('goToEvents', function() { - it('should call state.go with the right params', function(){ + it('should call state.go with the INST_EVENTS on desktop', function(){ spyOn(utilsService, 'selectNavOption'); - institutionCtrl.posts = posts; + spyOn(Utils, 'isMobileScreen').and.returnValue(false); institutionCtrl.goToEvents(first_institution.key); expect(utilsService.selectNavOption).toHaveBeenCalledWith( - states.INST_EVENTS, + states.INST_EVENTS, + { + institutionKey: first_institution.key, + } + ); + }); + + it('should call state.go with the EVENTS on mobile', function(){ + spyOn(utilsService, 'selectNavOption'); + spyOn(Utils, 'isMobileScreen').and.returnValue(true); + institutionCtrl.goToEvents(first_institution.key); + expect(utilsService.selectNavOption).toHaveBeenCalledWith( + states.EVENTS, { institutionKey: first_institution.key, - posts: posts } ); }); }); + describe('goToLinks()', function() { it('should call state.go', function() { spyOn(state, 'go'); diff --git a/frontend/test/specs/institution/manageInstMenuControllerSpec.js b/frontend/test/specs/institution/manageInstMenuControllerSpec.js new file mode 100644 index 000000000..8bf2d7e2c --- /dev/null +++ b/frontend/test/specs/institution/manageInstMenuControllerSpec.js @@ -0,0 +1,108 @@ +"use strict"; + +describe('ManageInstMenuController', () => { + + let manageInstItemsFactory, manageInstMenuCtrl, + user, instA, instB, profileA, profileB; + + const initModels = () => { + instA = new Institution({ + key: "instA-key", + name: "instA" + }); + + instB = new Institution({ + key: "instB-key", + name: "instB" + }); + + profileA = { + institution: instA, + institution_key: instA.key + }; + + profileB = { + institution: instB, + institution_key: instB.key + }; + + user = new User({ + key: "user-key", + institution_profiles: [profileA, profileB], + current_institution: instA, + institutions_admin: [ + `http://localhost/api/key/${instA.key}`, + `http://localhost/api/key/${instB.key}`, + ] + }) + }; + + beforeEach(module("app")); + + beforeEach(inject(function(AuthService, ManageInstItemsFactory, $controller) { + manageInstItemsFactory = ManageInstItemsFactory; + initModels(); + AuthService.login(user); + manageInstMenuCtrl = $controller("ManageInstMenuController"); + manageInstMenuCtrl.$onInit(); + })); + + describe('onInit()', () => { + it('should load the institution and the switchInstOption', () => { + spyOn(manageInstMenuCtrl, '_loadSwitchInstOptions'); + spyOn(manageInstMenuCtrl, '_loadInstitution'); + manageInstMenuCtrl.$onInit(); + expect(manageInstMenuCtrl._loadSwitchInstOptions).toHaveBeenCalled(); + expect(manageInstMenuCtrl._loadInstitution).toHaveBeenCalled(); + }); + }); + + describe('_loadInstitution()', () => { + it('should set the institution and load the menu options', () => { + spyOn(manageInstMenuCtrl, '_loadMenuOptions'); + manageInstMenuCtrl._loadInstitution(); + expect(manageInstMenuCtrl.institution).toBe(instA); + expect(manageInstMenuCtrl._loadMenuOptions).toHaveBeenCalled(); + }); + }); + + describe('_loadMenuOptions()', () => { + it('should call the ManageInstItemsFactory getItems function', () => { + spyOn(manageInstItemsFactory, 'getItems').and.callThrough(); + manageInstMenuCtrl._loadMenuOptions(); + expect(manageInstItemsFactory.getItems).toHaveBeenCalledWith(manageInstMenuCtrl.institution); + }); + }); + + describe('_getIcon()', () => { + it('should return the radio_button_checked icon', () => { + expect(manageInstMenuCtrl._getIcon(instA.key)).toBe('radio_button_checked'); + }); + + it('should return the radio_button_unchecked icon', () => { + expect(manageInstMenuCtrl._getIcon(instB.key)).toBe('radio_button_unchecked'); + }); + }); + + describe('_switchInstitution()', () => { + it('should have called changeInstitution and _loadInstitution', () => { + spyOn(manageInstMenuCtrl.user, 'changeInstitution'); + spyOn(manageInstMenuCtrl, '_loadInstitution'); + manageInstMenuCtrl._switchInstitution(instB); + expect(manageInstMenuCtrl.user.changeInstitution).toHaveBeenCalledWith(instB); + expect(manageInstMenuCtrl._loadInstitution).toHaveBeenCalled(); + }); + }); + + describe('_getProfilesAdmin()', () => { + it(`should return just the profiles in which the user is admin + of the correspondent institution`, () => { + const instC = new Institution({key: 'instC'}); + const profileC = {institution: instC, institution_key: instC.key}; + manageInstMenuCtrl.user.institution_profiles.push(profileC); + expect(manageInstMenuCtrl.user.institution_profiles).toEqual([profileA, profileB, profileC]); + expect(manageInstMenuCtrl._getProfilesAdmin()).toEqual([profileA, profileB]); + }); + }); + +}); \ No newline at end of file diff --git a/frontend/test/specs/institution/managementMembersControllerSpec.js b/frontend/test/specs/institution/managementMembersControllerSpec.js index 0503f30c1..d3fcc254a 100644 --- a/frontend/test/specs/institution/managementMembersControllerSpec.js +++ b/frontend/test/specs/institution/managementMembersControllerSpec.js @@ -337,10 +337,9 @@ }); it('should call Utils.groupUsersByInitialLetter if is mobile screen', () => { - spyOn(Utils, 'isMobileScreen').and.returnValue(true); - spyOn(Utils, 'groupUsersByInitialLetter'); + spyOn(manageMemberCtrl,'_getAdmin'); manageMemberCtrl._getMembers(); - expect(Utils.groupUsersByInitialLetter).toHaveBeenCalledWith([member, user]); + expect(manageMemberCtrl._getAdmin).toHaveBeenCalledWith([member, user]); }); }); }); diff --git a/frontend/test/specs/institution/registeredInstitutionsControllerSpec.js b/frontend/test/specs/institution/registeredInstitutionsControllerSpec.js index 04d38b683..5b0dfeedc 100644 --- a/frontend/test/specs/institution/registeredInstitutionsControllerSpec.js +++ b/frontend/test/specs/institution/registeredInstitutionsControllerSpec.js @@ -12,6 +12,7 @@ describe('registeredInstitutionController test', () => { }); const institution = new Institution({ + name: 'institution', key: 'sopdkfap-OPAKOPAKFPO', creation_date: new Date() }); @@ -66,13 +67,13 @@ describe('registeredInstitutionController test', () => { } }); - spyOn(msgService, 'showToast'); + spyOn(msgService, 'showInfoToast'); spyOn(authService, 'save'); regInstCtrl.follow(regInstCtrl.institution.key); - expect(msgService.showToast).toHaveBeenCalled(); + expect(msgService.showInfoToast).toHaveBeenCalledWith('Seguindo institution'); expect(authService.save).toHaveBeenCalled(); expect(instService.follow).toHaveBeenCalled(); diff --git a/frontend/test/specs/institution/removeInstControllerSpec.js b/frontend/test/specs/institution/removeInstControllerSpec.js index bbf3f432b..14fb33c4d 100644 --- a/frontend/test/specs/institution/removeInstControllerSpec.js +++ b/frontend/test/specs/institution/removeInstControllerSpec.js @@ -86,14 +86,14 @@ spyOn(authService, 'save'); spyOn(removeInstCtrl, 'closeDialog'); spyOn(state, 'go'); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); removeInstCtrl.removeInst(); expect(institutionService.removeInstitution).toHaveBeenCalled(); expect(removeInstCtrl.user.institutions).toEqual([sec_institution]); expect(authService.save).toHaveBeenCalled(); expect(removeInstCtrl.closeDialog).toHaveBeenCalled(); expect(state.go).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Instituição removida com sucesso.'); }); it('should call authService.logout()', function() { @@ -146,4 +146,24 @@ expect(removeInstCtrl.closeDialog).toHaveBeenCalled(); }); }); + + describe('getTitle()', () => { + beforeEach(() => { + spyOn(removeInstCtrl, 'hasOneInstitution').and.callThrough(); + }); + + afterEach(() => { + expect(removeInstCtrl.hasOneInstitution).toHaveBeenCalled(); + }); + + it('should return the first option when the user has only one institution', () => { + removeInstCtrl.user.institutions = [first_institution]; + expect(removeInstCtrl.getTitle()).toEqual("Ao remover essa instituição você perderá o acesso a plataforma. Deseja remover?"); + }); + + it('should return the second option when the user has more than one institution', () => { + removeInstCtrl.user.institutions = [first_institution, sec_institution]; + expect(removeInstCtrl.getTitle()).toEqual("Deseja remover esta instituição permanentemente ?"); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/institution/transferAdminControllerSpec.js b/frontend/test/specs/institution/transferAdminControllerSpec.js index 219c35d8f..a24aaa0ec 100644 --- a/frontend/test/specs/institution/transferAdminControllerSpec.js +++ b/frontend/test/specs/institution/transferAdminControllerSpec.js @@ -83,7 +83,8 @@ }); spyOn(mdDialog, 'hide').and.callFake(function() {}); - spyOn(messageService, 'showToast').and.callFake(function() {}); + spyOn(messageService, 'showErrorToast').and.callFake(function() {}); + spyOn(messageService, 'showInfoToast').and.callFake(function() {}); }); it('Should not send the invitation.', function() { @@ -103,7 +104,7 @@ transferAdminCtrl.selectMember(user); transferAdminCtrl.confirm(); - expect(messageService.showToast).toHaveBeenCalledWith("Você já é administrador da instituição, selecione outro membro!"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Você já é administrador da instituição, selecione outro membro!"); }); it('Should must send the invitation.', function() { @@ -125,14 +126,14 @@ expect(inviteService.sendInviteUser).toHaveBeenCalledWith({invite_body: invite}); expect(mdDialog.hide).toHaveBeenCalledWith(invite); - expect(messageService.showToast).toHaveBeenCalledWith("Convite enviado com sucesso!"); + expect(messageService.showInfoToast).toHaveBeenCalledWith("Convite enviado com sucesso!"); }); it('Should not be sent if there is no member selected.', function() { transferAdminCtrl.confirm(); expect(inviteService.sendInviteUser).not.toHaveBeenCalled(); expect(mdDialog.hide).not.toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalledWith("Selecione um memebro!"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Selecione um membro!"); }); }); })); \ No newline at end of file diff --git a/frontend/test/specs/invites/inviteInstHierarchieControllerSpec.js b/frontend/test/specs/invites/inviteInstHierarchieControllerSpec.js index ca3b47245..c747cea13 100644 --- a/frontend/test/specs/invites/inviteInstHierarchieControllerSpec.js +++ b/frontend/test/specs/invites/inviteInstHierarchieControllerSpec.js @@ -104,6 +104,7 @@ state.params.institutionKey = institution.key; inviteInstHierarchieCtrl = createCtrl(); + inviteInstHierarchieCtrl.$onInit(); expect(requestInvitationService.getParentRequests).toHaveBeenCalled(); expect(requestInvitationService.getChildrenRequests).toHaveBeenCalled(); @@ -124,20 +125,20 @@ describe('checkInstInvite', function() { beforeEach(function() { - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); }); - it('should call showToast with invalid invite message', function () { + it('should call showErrorToast with invalid invite message', function () { inviteInstHierarchieCtrl.invite = {}; inviteInstHierarchieCtrl.checkInstInvite('$event'); - expect(messageService.showToast).toHaveBeenCalledWith('Convite inválido!'); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Convite inválido!'); }); - it('should call showToast with institution has already have a parent message', function() { + it('should call showErrorToast with institution has already have a parent message', function() { inviteInstHierarchieCtrl.invite = invite; inviteInstHierarchieCtrl.hasParent = true; inviteInstHierarchieCtrl.checkInstInvite('$event'); - expect(messageService.showToast).toHaveBeenCalledWith("Já possui instituição superior"); + expect(messageService.showErrorToast).toHaveBeenCalledWith("Já possui instituição superior"); }); it('should call searchInstitutions', function(done) { @@ -184,12 +185,12 @@ }); it('should call sendInviteHierarchy', function() { - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); inviteInstHierarchieCtrl.institution.sent_invitations = []; inviteInstHierarchieCtrl.sendInstInvite(invite); expect(inviteInstHierarchieCtrl.showParentHierarchie).toBeTruthy(); expect(inviteService.sendInviteHierarchy).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Convite enviado com sucesso!'); }); }); @@ -252,11 +253,11 @@ }); it('should not go', function() { - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); spyOn(state, 'go'); institution.state = 'inactive'; inviteInstHierarchieCtrl.goToActiveInst(institution); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showErrorToast).toHaveBeenCalledWith('Institutição inativa!'); expect(state.go).not.toHaveBeenCalled(); }); }); diff --git a/frontend/test/specs/invites/inviteInstitutionControllerSpec.js b/frontend/test/specs/invites/inviteInstitutionControllerSpec.js index 9c9c2a73e..7674f884c 100644 --- a/frontend/test/specs/invites/inviteInstitutionControllerSpec.js +++ b/frontend/test/specs/invites/inviteInstitutionControllerSpec.js @@ -3,6 +3,7 @@ (describe('Test InviteInstitutionController', function() { var inviteinstitutionCtrl, httpBackend, scope, inviteService, createCtrl, state, instService, mdDialog, requestInvitationService; + let stateLinkRequestService, states, stateLinks; var institution = { name: 'institution', @@ -32,6 +33,11 @@ status: 'sent', } + const form = { + '$setPristine': () => {}, + '$setUntouched': () => {} + }; + var INSTITUTION_SEARCH_URI = '/api/search/institution?value='; var invite = new Invite({invitee: "user@gmail.com", suggestion_institution_name : "New Institution", key: '123'}, 'institution', institution.key); @@ -39,7 +45,7 @@ beforeEach(module('app')); beforeEach(inject(function($controller, $httpBackend, $rootScope, $state, $mdDialog, - InviteService, AuthService, InstitutionService, RequestInvitationService) { + InviteService, AuthService, InstitutionService, RequestInvitationService, StateLinkRequestService, STATE_LINKS, STATES) { httpBackend = $httpBackend; scope = $rootScope.$new(); state = $state; @@ -47,6 +53,9 @@ inviteService = InviteService; instService = InstitutionService; requestInvitationService = RequestInvitationService; + stateLinkRequestService = StateLinkRequestService; + stateLinks = STATE_LINKS; + states = STATES; AuthService.login(user); @@ -56,6 +65,7 @@ httpBackend.when('GET', "main/main.html").respond(200); httpBackend.when('GET', "home/home.html").respond(200); httpBackend.when('GET', "auth/login.html").respond(200); + httpBackend.when('GET', 'app/email/stateLinkRequest/stateLinkRequestDialog.html').respond(200); createCtrl = function() { return $controller('InviteInstitutionController', @@ -66,6 +76,8 @@ }; state.params.institutionKey = institution.key; inviteinstitutionCtrl = createCtrl(); + inviteinstitutionCtrl.$onInit(); + inviteinstitutionCtrl.inviteInstForm = form; httpBackend.flush(); })); @@ -94,6 +106,7 @@ } }; }); + spyOn(inviteinstitutionCtrl, 'resetForm'); inviteinstitutionCtrl.invite = invite; }); @@ -102,6 +115,7 @@ var promise = inviteinstitutionCtrl.sendInstInvite(invite); promise.then(function() { expect(inviteService.sendInviteInst).toHaveBeenCalledWith(invite); + expect(inviteinstitutionCtrl.resetForm).toHaveBeenCalled(); done(); }); }); @@ -202,12 +216,42 @@ } }; }); - inviteinstitutionCtrl.sent_requests = [request]; inviteinstitutionCtrl.showPendingRequestDialog('$event', request); expect(mdDialog.show).toHaveBeenCalled(); - expect(request.status).toBe('accepted'); + }); + }); + + describe('updateRequest', () => { + beforeEach(() => { + inviteinstitutionCtrl.sent_requests = [request]; + }); + + afterEach(() => { expect(inviteinstitutionCtrl.sent_requests).toEqual([]); + }) + + it(`should set the request status to 'rejected' + and remove it from the requests sent`, () => { + inviteinstitutionCtrl._updateRequest(request, "rejected"); + expect(request.status).toBe('rejected'); + }); + + it(`should set the request status to 'accepted' + and remove it from the requests sent`, () => { + inviteinstitutionCtrl._updateRequest(request, "accepted"); + expect(request.status).toBe('accepted'); + }); + }); + + describe('$onInit', function () { + it('should call showLinkRequestDialog if in mobile screen', function () { + spyOn(inviteinstitutionCtrl, '_loadSentRequests'); + spyOn(inviteinstitutionCtrl, '_loadSentInvitations'); + inviteinstitutionCtrl.$onInit(); + expect(inviteinstitutionCtrl._loadSentRequests).toHaveBeenCalled(); + expect(inviteinstitutionCtrl._loadSentInvitations).toHaveBeenCalled(); }); }); }); + })); \ No newline at end of file diff --git a/frontend/test/specs/invites/processInviteUserAdmControllerSpec.js b/frontend/test/specs/invites/processInviteUserAdmControllerSpec.js index b60f2e366..495f7d989 100644 --- a/frontend/test/specs/invites/processInviteUserAdmControllerSpec.js +++ b/frontend/test/specs/invites/processInviteUserAdmControllerSpec.js @@ -102,7 +102,7 @@ }; }); - spyOn(messageService, 'showToast').and.callFake(function(){}); + spyOn(messageService, 'showInfoToast').and.callFake(function(){}); }); it('Should accept the invitation to become an administrator', function() { @@ -117,7 +117,7 @@ expect(processInviteUserAdmCtrl.typeOfDialog).toEqual('VIEW_ACCEPTED_INVITATION_INVITEE'); expect(processInviteUserAdmCtrl.isAccepting).toBeTruthy(); expect(inviteService.acceptInviteUserAdm).toHaveBeenCalledWith(invite.key); - expect(messageService.showToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); }); it('Should add super user permissions of old admin', function() { @@ -141,7 +141,7 @@ expect(processInviteUserAdmCtrl.typeOfDialog).toEqual('VIEW_ACCEPTED_INVITATION_INVITEE'); expect(processInviteUserAdmCtrl.isAccepting).toBeTruthy(); expect(inviteService.acceptInviteUserAdm).toHaveBeenCalledWith(invite.key); - expect(messageService.showToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); }); it('Should not add super user permissions of old admin', function() { @@ -165,7 +165,7 @@ expect(processInviteUserAdmCtrl.typeOfDialog).toEqual('VIEW_ACCEPTED_INVITATION_INVITEE'); expect(processInviteUserAdmCtrl.isAccepting).toBeTruthy(); expect(inviteService.acceptInviteUserAdm).toHaveBeenCalledWith(invite.key); - expect(messageService.showToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Convite aceito com sucesso!'); }); }); @@ -179,7 +179,7 @@ }; }); - spyOn(messageService, 'showToast').and.callFake(function(){}); + spyOn(messageService, 'showInfoToast').and.callFake(function(){}); spyOn(mdDialog, 'hide').and.callFake(function(){}); }); @@ -188,7 +188,7 @@ user = JSON.parse(window.localStorage.userInfo); expect(user.institutions_admin).toEqual([]); - expect(messageService.showToast).toHaveBeenCalledWith('Convite recusado!'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Convite recusado!'); expect(inviteService.rejectInviteUserAdm).toHaveBeenCalledWith(invite.key); expect(mdDialog.hide).toHaveBeenCalled(); }); diff --git a/frontend/test/specs/invites/suggestInstitutionControllerSpec.js b/frontend/test/specs/invites/suggestInstitutionControllerSpec.js index c0c62d963..6342a2c69 100644 --- a/frontend/test/specs/invites/suggestInstitutionControllerSpec.js +++ b/frontend/test/specs/invites/suggestInstitutionControllerSpec.js @@ -43,15 +43,6 @@ inviteService: InviteService, }); - httpBackend.expect('GET', '/api/invites/institution').respond([]); - httpBackend.expect('GET', '/api/institutions/requests/institution/1239').respond([]); - httpBackend.when('GET', "main/main.html").respond(200); - httpBackend.when('GET', "error/user_inactive.html").respond(200); - httpBackend.when('GET', 'invites/existing_institutions.html').respond(200); - httpBackend.when('GET', "home/home.html").respond(200); - httpBackend.when('GET', "auth/login.html").respond(200); - httpBackend.when('GET', "app/user/user_inactive.html").respond(200); - createCtrl = function() { return $controller('SuggestInstitutionController', { scope: scope, @@ -65,14 +56,8 @@ }; suggestInstCtrl = createCtrl(); - httpBackend.flush(); })); - afterEach(function() { - httpBackend.verifyNoOutstandingExpectation(); - httpBackend.verifyNoOutstandingRequest(); - }); - describe('cancel()', function() { it('should call mdDialog.cancel()', function() { spyOn(mdDialog, 'cancel'); diff --git a/frontend/test/specs/main/mainControllerSpec.js b/frontend/test/specs/main/mainControllerSpec.js index db050fafa..4c2f5e2c4 100644 --- a/frontend/test/specs/main/mainControllerSpec.js +++ b/frontend/test/specs/main/mainControllerSpec.js @@ -2,8 +2,9 @@ (describe('Test MainController', function() { let mainCtrl, httpBackend, scope, createCtrl, state, states, mainToolbar; - let authService, requestInvitationService, notificationListenerService, utilsService; + let authService, requestInvitationService, notificationListenerService, utilsService, pushNotificationService; + const window = {'location': {'reload': function(){}}}; const user = { name: 'user', key: 'user-key', @@ -45,7 +46,7 @@ beforeEach(module('app')); beforeEach(inject(function($controller, $httpBackend, $rootScope, $state, AuthService, - RequestInvitationService, NotificationListenerService, STATES, UtilsService) { + RequestInvitationService, NotificationListenerService, STATES, UtilsService, PushNotificationService) { httpBackend = $httpBackend; scope = $rootScope.$new(); state = $state; @@ -54,6 +55,7 @@ requestInvitationService = RequestInvitationService; notificationListenerService = NotificationListenerService; utilsService = UtilsService; + pushNotificationService = PushNotificationService; mainToolbar = document.createElement('div'); mainToolbar.setAttribute("id", "main-toolbar"); @@ -78,7 +80,7 @@ spyOn(requestInvitationService, 'getParentRequests').and.callFake(callFake); spyOn(requestInvitationService, 'getChildrenRequests').and.callFake(callFake); spyOn(NotificationListenerService, 'multipleEventsListener').and.callFake(eventsListenerFake); - + spyOn(pushNotificationService, 'setupPushNotificationPermission').and.callFake(callFake); authService.login(user); @@ -87,10 +89,12 @@ httpBackend.when('GET', "error/user_inactive.html").respond(200); httpBackend.when('GET', "home/home.html").respond(200); httpBackend.when('GET', "auth/login.html").respond(200); + createCtrl = function() { return $controller('MainController', { scope: scope, - AuthService: authService + AuthService: authService, + $window: window }); }; mainCtrl = createCtrl(); @@ -110,7 +114,8 @@ invites: [], institutions: [otherInstitution], permissions: {}, - state: 'active' + state: 'active', + key: 'user-key' }; authService.getCurrentUser = function() { @@ -121,7 +126,7 @@ mainCtrl = createCtrl(); - expect(state.go).toHaveBeenCalledWith(states.CONFIG_PROFILE); + expect(state.go).toHaveBeenCalledWith(states.CONFIG_PROFILE, {userKey: unknownUser.key}); }); it("should create observer", function() { @@ -216,4 +221,12 @@ expect(authService.reload).toHaveBeenCalled(); }); }); + + describe('updateVersion', () => { + it('should call reload()', () => { + spyOn(authService, 'reload'); + mainCtrl.updateVersion(); + expect(authService.reload).toHaveBeenCalled(); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/notification/pushNotificationServiceSpec.js b/frontend/test/specs/notification/pushNotificationServiceSpec.js index bf9374eb3..1234ea6c8 100644 --- a/frontend/test/specs/notification/pushNotificationServiceSpec.js +++ b/frontend/test/specs/notification/pushNotificationServiceSpec.js @@ -1,7 +1,7 @@ 'use strict'; (describe('Test PushNotificationService', function () { - let service, messaging, defaultToken, notificationsRef, messageService, scope, $qMock; + let service, messaging, defaultToken, notificationsRef, messageService, scope, $qMock, authService; const fakeCallback = function fakeCallback(data) { return { @@ -11,9 +11,11 @@ }; }; + const TOKEN_OBJECT = {token: 'token'}; + beforeEach(module('app')); - beforeEach(inject(function (PushNotificationService, MessageService, $q, $rootScope) { + beforeEach(inject(function (PushNotificationService, MessageService, $q, $rootScope, AuthService) { service = PushNotificationService; messaging = firebase.messaging(); messageService = MessageService; @@ -22,12 +24,95 @@ defaultToken = 'oaspkd-OPASKDAPO'; scope = $rootScope.$new(); $qMock = $q; + authService = AuthService; + + spyOn(authService, 'getCurrentUser').and.callFake(() => new User({ + key: 'aopskdpoaAPOSDKAPOKDPK' + })); })); - describe('requestNotificationPermission', () => { + describe('setupPushNotificationPermission', () => { + it('should call _initFirebaseArray', () => { + spyOn(service, '_initFirebaseArray'); + service.setupPushNotificationPermission(); + expect(service._initFirebaseArray).toHaveBeenCalled(); + }); + }); + + describe('isPushNotificationBlockedOnBrowser', () => { + it('should return true when the user has blocked notifications', () => { + Notification = {permission: 'denied'}; + + const result = service.isPushNotificationBlockedOnBrowser(); + + expect(result).toEqual(true); + }); + + it('should return false when the user has not blocked notifications', () => { + Notification = {permission: 'ask'}; + + const result = service.isPushNotificationBlockedOnBrowser(); + + expect(result).toEqual(false); + }); + }); + + describe('isPushNotificationActive', () => { + it('should return true if the browser token is included in the firebaseArray', () => { + spyOn(service, '_getTokenObjectInFirebaseArray').and.callFake(() => $qMock.when(TOKEN_OBJECT)); + let result; + service.isPushNotificationActive().then((isActive) => { + result = isActive; + }); + scope.$apply(); + expect(service._getTokenObjectInFirebaseArray).toHaveBeenCalled(); + expect(result).toBe(true); + }); + + it('should return false if the browser token is not included in the firebaseArray', () => { + spyOn(service, '_getTokenObjectInFirebaseArray').and.callFake(() => $qMock.when()); + + let result; + service.isPushNotificationActive().then((isActive) => { + result = isActive; + }); + scope.$apply(); + expect(service._getTokenObjectInFirebaseArray).toHaveBeenCalled(); + expect(result).toBe(false); + }); + }); + + describe('unsubscribeUserNotification', () => { + it('should call _removeTokenFromFirebaseArray', () => { + spyOn(service, '_removeTokenFromFirebaseArray'); + service.unsubscribeUserNotification(); + expect(service._removeTokenFromFirebaseArray).toHaveBeenCalled(); + }); + }); + + describe('_removeTokenFromFirebaseArray', () => { + it('should call _getTokenObjectInFirebaseArray and remove object from firebase array', () => { + service._initFirebaseArray(); + spyOn(service, '_getTokenObjectInFirebaseArray').and.callFake(() => $qMock.when(TOKEN_OBJECT)); + spyOn(service.firebaseArrayNotifications, '$remove'); + service.unsubscribeUserNotification(); + scope.$apply(); + expect(service._getTokenObjectInFirebaseArray).toHaveBeenCalled(); + expect(service.firebaseArrayNotifications.$remove).toHaveBeenCalledWith(TOKEN_OBJECT); + }); + }); + + describe('subscribeUserNotification', () => { + it('should call _requestNotificationPermission', () => { + spyOn(service, '_requestNotificationPermission'); + service.subscribeUserNotification(); + expect(service._requestNotificationPermission).toHaveBeenCalled(); + }); + }); + + describe('_requestNotificationPermission', () => { beforeEach(() => { - spyOn(service, '_hasNotificationPermission').and.returnValue(false); - spyOn(service._isMobile, 'any').and.returnValue(true); + spyOn(service, 'isPushNotificationBlockedOnBrowser').and.returnValue(false); spyOn(messaging, 'requestPermission'); spyOn(messaging, 'getToken'); spyOn(service, '_saveToken'); @@ -38,7 +123,7 @@ messaging.getToken.and.callFake(fakeCallback); service._saveToken.and.callFake(fakeCallback); - service.requestNotificationPermission(new User({})); + service._requestNotificationPermission(); scope.$digest(); expect(messaging.requestPermission).toHaveBeenCalled(); @@ -49,7 +134,7 @@ it('should not call saveToken when the user does not enable notification', () => { messaging.requestPermission.and.callFake(() => $qMock.reject()); - service.requestNotificationPermission(); + service._requestNotificationPermission(); scope.$digest(); expect(messaging.requestPermission).toHaveBeenCalled(); @@ -70,24 +155,17 @@ }); }); - describe('initFirebaseArray', () => { + describe('_initFirebaseArray', () => { it('should starts a firebaseArray', () => { expect(service.firebaseArrayNotifications).toBe(undefined); - service.currentUser = new User({ - key: 'aopskdpoaAPOSDKAPOKDPK' - }); - service._initFirebaseArray(); - + expect(service.firebaseArrayNotifications).not.toBe(undefined); }); }); - describe('setToken', () => { + describe('_setToken', () => { beforeEach(() => { - service.currentUser = new User({ - key: 'aopskdpoaAPOSDKAPOKDPK' - }); service._initFirebaseArray(); }); @@ -102,21 +180,21 @@ }); }); - describe('hasNotificationPermission', () => { - it('should return true when the user has enabled notifications', () => { - Notification = {permission: 'granted'}; - - const result = service._hasNotificationPermission(); - - expect(result).toEqual(true); - }); + describe('_getTokenObjectInFirebaseArray', () => { + it('should return the object token corresponding to the messaging token', () => { + service._initFirebaseArray(); + spyOn(service.firebaseArrayNotifications, '$loaded').and.callFake(() => $qMock.when([TOKEN_OBJECT])); + spyOn(messaging, 'getToken').and.callFake(() => $qMock.when(TOKEN_OBJECT.token)); - it('should return false when the user has not enabled notifications', () => { - Notification = {permission: 'ask'}; - - const result = service._hasNotificationPermission(); + let tokenObject; + service._getTokenObjectInFirebaseArray().then((result) => { + tokenObject = result; + }); + scope.$apply(); - expect(result).toEqual(false); + expect(tokenObject).toBe(TOKEN_OBJECT); + expect(messaging.getToken).toHaveBeenCalled(); + expect(service.firebaseArrayNotifications.$loaded).toHaveBeenCalled(); }); }); })); \ No newline at end of file diff --git a/frontend/test/specs/post/postDetailsControllerSpec.js b/frontend/test/specs/post/postDetailsControllerSpec.js index 54ca02451..f69d3f662 100644 --- a/frontend/test/specs/post/postDetailsControllerSpec.js +++ b/frontend/test/specs/post/postDetailsControllerSpec.js @@ -4,7 +4,7 @@ beforeEach(module('app')); let postDetailsCtrl, scope, httpBackend, rootScope, mdDialog, postService, mdToast, http, - commentService, state, posts, rootscope, states; + commentService, state, posts, rootscope, states, q, eventService, messageService; var user = { name: 'name', key: 'asd234jk2l', @@ -46,7 +46,8 @@ beforeEach(inject(function($controller, $httpBackend, HttpService, $mdDialog, STATES, - PostService, AuthService, $mdToast, $rootScope, CommentService, $state) { + PostService, AuthService, $mdToast, $rootScope, CommentService, $state, $q, + EventService, MessageService) { scope = $rootScope.$new(); rootscope = $rootScope; httpBackend = $httpBackend; @@ -58,6 +59,9 @@ state = $state; states = STATES; commentService = CommentService; + q = $q; + eventService = EventService; + messageService = MessageService; commentService.user = user; postService.user = user; var mainPost = new Post({ @@ -613,4 +617,81 @@ expect(returnedValue).toBeFalsy(); }); }); + + describe('isSharedEvent()', () => { + it('should be truthy when the post is a shared_event', () => { + postDetailsCtrl.post = new Post({shared_event : {}}); + expect(postDetailsCtrl.isSharedEvent()).toBeTruthy(); + }); + + it('should be falsy when the post is not a shared_event', () => { + postDetailsCtrl.post = new Post({ }); + expect(postDetailsCtrl.isSharedEvent()).toBeFalsy(); + }); + }); + + describe('followEvent()', () => { + it('should call addFollower', () => { + spyOn(eventService, 'addFollower').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + postDetailsCtrl.post = new Post({ + shared_event: new Event({followers: [], key: 'akaspo'}) + }); + + postDetailsCtrl.followEvent(); + scope.$apply(); + + expect(eventService.addFollower).toHaveBeenCalledWith('akaspo'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Você receberá as atualizações desse evento.'); + expect(postDetailsCtrl.post.shared_event.followers).toEqual([user.key]); + }); + }); + + describe('unfollowEvent()', () => { + it('should call removeFollower', () => { + spyOn(eventService, 'removeFollower').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + postDetailsCtrl.post = new Post({ + shared_event: new Event({ followers: [postDetailsCtrl.user.key], key:'aposkd' }) + }); + + postDetailsCtrl.unFollowEvent(); + scope.$apply(); + + expect(eventService.removeFollower).toHaveBeenCalledWith('aposkd'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Você não receberá as atualizações desse evento.'); + }); + }); + + describe('isFollowingEvent()', () => { + it('should return true', () => { + postDetailsCtrl.post = new Post({ + shared_event: new Event({ followers: [postDetailsCtrl.user.key] }) + }); + + expect(postDetailsCtrl.isFollowingEvent()).toEqual(true); + }); + + it('should return false', () => { + postDetailsCtrl.post = new Post({ + shared_event: new Event({ followers: [] }) + }); + + expect(postDetailsCtrl.isFollowingEvent()).toEqual(false); + }); + }); + + describe('isMobileScreen()', () => { + it('should call Utils.isMobileScreen', () => { + spyOn(Utils, 'isMobileScreen'); + + postDetailsCtrl.isMobileScreen(); + + expect(Utils.isMobileScreen).toHaveBeenCalled(); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/post/postPageControllerSpec.js b/frontend/test/specs/post/postPageControllerSpec.js index 0672ffc09..5eca0a3a0 100644 --- a/frontend/test/specs/post/postPageControllerSpec.js +++ b/frontend/test/specs/post/postPageControllerSpec.js @@ -2,7 +2,7 @@ (describe('Test PostPageController', function () { - var postCtrl, scope, httpBackend, postService, state; + let postCtrl, scope, httpBackend, postService, state, clipboard, messageService, mdDialog, q; var institutions = [ { name: 'Splab', key: '098745' }, @@ -13,18 +13,29 @@ 'title': 'Shared Post', 'text': 'This post will be shared', 'photo_url': null, - 'key': '12300' + 'key': '12300', + subscribers: [] }, institutions[1].institution_key); beforeEach(module('app')); - beforeEach(inject(function ($controller, $httpBackend, PostService, $state) { + beforeEach(inject(function ($controller, $httpBackend, PostService, $state, ngClipboard, + MessageService, $mdDialog, $q, AuthService, $rootScope) { httpBackend = $httpBackend; state = $state; postService = PostService; + clipboard = ngClipboard; + messageService = MessageService; + mdDialog = $mdDialog; + q = $q; + scope = $rootScope.$new(); httpBackend.when('GET', "main/main.html").respond(200); httpBackend.when('GET', "home/home.html").respond(200); + AuthService.getCurrentUser = function () { + return new User({key: 'aopsdkopdaskospdpokdskop'}); + }; + spyOn(postService, 'getPost').and.callFake(function () { return { then: function (callback) { @@ -36,10 +47,11 @@ state.params.key = post.key postCtrl = $controller('PostPageController', { PostService: postService, - state: state + state: state, + scope: scope }); - + postCtrl.$onInit(); })); afterEach(function () { @@ -78,4 +90,95 @@ expect(result).toEqual(true); }); }); + + describe('copyLink()', () => { + it('should call toClipboard', () => { + spyOn(Utils, 'generateLink'); + spyOn(clipboard, 'toClipboard'); + spyOn(messageService, 'showInfoToast'); + + postCtrl.copyLink(); + + expect(Utils.generateLink).toHaveBeenCalled(); + expect(clipboard.toClipboard).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalled(); + }); + }); + + describe('reloadPost()', () => { + + }); + + describe('share()', () => { + it('should call show', () => { + spyOn(mdDialog, 'show'); + + postCtrl.share('$event'); + + expect(mdDialog.show).toHaveBeenCalled(); + }); + }); + + describe('addSubscriber()', () => { + it('should call addSubscriber', () => { + spyOn(postService, 'addSubscriber').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + + postCtrl.addSubscriber(); + scope.$apply(); + + expect(postService.addSubscriber).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalled(); + expect(postCtrl.post.subscribers).toEqual([postCtrl.user.key]); + }); + }); + + describe('removeSubscriber()', () => { + it('should call removeSubscriber', () => { + spyOn(postService, 'removeSubscriber').and.callFake(() => { + return q.when(); + }); + spyOn(messageService, 'showInfoToast'); + + postCtrl.removeSubscriber(); + scope.$apply(); + + expect(postService.removeSubscriber).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalled(); + }); + }); + + describe('isSubscriber()', () => { + it('should be truthy', () => { + postCtrl.post.subscribers.push(postCtrl.user.key); + expect(postCtrl.isSubscriber()).toBeTruthy(); + }); + + it('should be falsy', () => { + postCtrl.post.subscribers = []; + expect(postCtrl.isSubscriber()).toBeFalsy(); + }); + }); + + describe('generateToolbarOptions()', () => { + it('should set defaultToolbrOptions', () => { + postCtrl.defaultToolbarOptions = []; + + postCtrl.generateToolbarOptions(); + + expect(postCtrl.defaultToolbarOptions.length).toEqual(6); + }); + }); + + describe('reloadPost()', () => { + it('should call getPost', () => { + spyOn(Object, 'values'); + postCtrl.reloadPost(); + + expect(postService.getPost).toHaveBeenCalled(); + expect(Object.values).toHaveBeenCalled(); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/request/analyseHierarchyRequestControllerSpec.js b/frontend/test/specs/request/analyseHierarchyRequestControllerSpec.js index 4b245e33e..bdded6705 100644 --- a/frontend/test/specs/request/analyseHierarchyRequestControllerSpec.js +++ b/frontend/test/specs/request/analyseHierarchyRequestControllerSpec.js @@ -66,7 +66,7 @@ analyseHierReqCtrl = createCtrl(request); spyOn(requestInvitationService, 'acceptInstParentRequest').and.callFake(fakeCallback); spyOn(requestInvitationService, 'rejectInstParentRequest').and.callFake(fakeCallback); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); }); describe('Test loadInstitutions', function () { @@ -92,7 +92,7 @@ expect(requestInvitationService.rejectInstParentRequest).toHaveBeenCalledWith(request.key); expect(request.status).toEqual('rejected'); expect(mdDialog.cancel).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalledWith('Solicitação rejeitada com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Solicitação rejeitada com sucesso'); }); }); }); @@ -104,7 +104,7 @@ analyseHierReqCtrl = createCtrl(request); spyOn(requestInvitationService, 'acceptInstChildrenRequest').and.callFake(fakeCallback); spyOn(requestInvitationService, 'rejectInstChildrenRequest').and.callFake(fakeCallback); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); }); describe('Test loadInstitutions', function () { @@ -121,7 +121,7 @@ expect(requestInvitationService.rejectInstChildrenRequest).toHaveBeenCalledWith(request.key); expect(request.status).toEqual('rejected'); expect(mdDialog.cancel).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalledWith('Solicitação rejeitada com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Solicitação rejeitada com sucesso'); }); }); @@ -140,7 +140,7 @@ expect(requestInvitationService.acceptInstChildrenRequest).toHaveBeenCalledWith(request.key); expect(request.status).toEqual('accepted'); expect(mdDialog.hide).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); }); }); }); @@ -174,7 +174,7 @@ expect(requestInvitationService.acceptInstChildrenRequest).toHaveBeenCalledWith(request.key); expect(request.status).toEqual('accepted'); expect(mdDialog.hide).toHaveBeenCalled(); - expect(messageService.showToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); }); }); }); @@ -193,10 +193,10 @@ expect(mdDialog.hide).toHaveBeenCalled(); }); - it('Should call MessageService.showToast', function() { - spyOn(messageService, 'showToast'); + it('Should call MessageService.showInfoToast', function() { + spyOn(messageService, 'showInfoToast'); analyseHierReqCtrl.close(); - expect(messageService.showToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Solicitação aceita com sucesso'); }); }); diff --git a/frontend/test/specs/request/requestInvitationControllerSpec.js b/frontend/test/specs/request/requestInvitationControllerSpec.js index 91dce4c27..4995c724f 100644 --- a/frontend/test/specs/request/requestInvitationControllerSpec.js +++ b/frontend/test/specs/request/requestInvitationControllerSpec.js @@ -103,7 +103,7 @@ spyOn(requestInvCtrl.currentUser.institutions_requested, 'push'); spyOn(mdDialog, 'hide').and.callFake(fakeCallback); spyOn(authService, 'save').and.callFake(fakeCallback); - spyOn(messageService, 'showToast').and.callFake(fakeCallback); + spyOn(messageService, 'showInfoToast').and.callFake(fakeCallback); promise = requestInvCtrl.sendRequest(); }); @@ -128,9 +128,9 @@ }); }); - it('Should call MessageService.showToast()', function(done) { + it('Should call MessageService.showInfoToast()', function(done) { promise.then(function() { - expect(messageService.showToast).toHaveBeenCalledWith("Pedido enviado com sucesso!"); + expect(messageService.showInfoToast).toHaveBeenCalledWith("Pedido enviado com sucesso!"); done(); }); }); diff --git a/frontend/test/specs/request/requestProcessingControllerSpec.js b/frontend/test/specs/request/requestProcessingControllerSpec.js index d7230bb19..3b75a5040 100644 --- a/frontend/test/specs/request/requestProcessingControllerSpec.js +++ b/frontend/test/specs/request/requestProcessingControllerSpec.js @@ -19,8 +19,8 @@ "PRIVATE_COMPANY": "Empresa Privada", }; - var requestInvitationService, institutionService, requestCtrl, scope, httpBackend; - var authService, userService, messageService, request; + var requestInvitationService, institutionService, requestCtrl, scope, httpBackend, mdDialog; + var authService, userService, messageService, request, deferred; var newRequest = { key: 'request-key', @@ -56,6 +56,10 @@ } ]; + const updateRequest = (req, status) => { + req.status = status; + }; + function callFake() { return { then: function(calback) { @@ -66,8 +70,8 @@ beforeEach(module('app')); - beforeEach(inject(function($controller, $rootScope, $httpBackend, AuthService, - RequestInvitationService, InstitutionService, UserService, MessageService) { + beforeEach(inject(function($controller, $rootScope, $httpBackend, AuthService, $q, + RequestInvitationService, InstitutionService, UserService, MessageService, $mdDialog) { requestInvitationService = RequestInvitationService; institutionService = InstitutionService; @@ -76,6 +80,8 @@ httpBackend = $httpBackend; authService = AuthService; scope = $rootScope.$new(); + mdDialog = $mdDialog; + deferred = $q.defer(); AuthService.login(user); request = Object.assign({}, newRequest); @@ -91,7 +97,8 @@ AuthService: authService, UserService: UserService, MessageService: messageService, - request: request + request: request, + updateRequest: updateRequest }); httpBackend.flush(); @@ -146,7 +153,7 @@ }); spyOn(requestInvitationService, 'getRequest').and.callFake(callFake); - spyOn(messageService, 'showToast').and.callFake(callFake); + spyOn(messageService, 'showInfoToast').and.callFake(callFake); spyOn(requestCtrl, 'hideDialog').and.callFake(function() {}); }); @@ -157,17 +164,36 @@ requestCtrl.acceptRequest(); expect(authService.getCurrentUser().permissions).toEqual(permissions); - expect(messageService.showToast).toHaveBeenCalledWith("Solicitação aceita!"); + expect(messageService.showInfoToast).toHaveBeenCalledWith("Solicitação aceita!"); expect(request.status).toEqual('accepted'); }); }); describe('rejectRequest()', function() { - it('should set isRejecting to true', function() { - expect(requestCtrl.isRejecting).toBe(false); - requestCtrl.rejectRequest(); - expect(requestCtrl.isRejecting).toBe(true); + beforeEach(() => { + spyOn(mdDialog, 'confirm').and.callThrough(); + spyOn(mdDialog, 'show').and.returnValue(deferred.promise); + spyOn(requestCtrl, 'confirmReject'); + spyOn(requestCtrl, 'cancelReject'); + }); + + it('should confirm the dialog and call confirmReject', function() { + deferred.resolve(); + requestCtrl.rejectRequest({}); + scope.$apply(); + expect(mdDialog.confirm).toHaveBeenCalled(); + expect(mdDialog.show).toHaveBeenCalled(); + expect(requestCtrl.confirmReject).toHaveBeenCalled(); + }); + + it('should cancel the dialog and call cancelReject', function() { + deferred.reject(); + requestCtrl.rejectRequest({}); + scope.$apply(); + expect(mdDialog.confirm).toHaveBeenCalled(); + expect(mdDialog.show).toHaveBeenCalled(); + expect(requestCtrl.cancelReject).toHaveBeenCalled(); }); }); @@ -250,11 +276,11 @@ } }; }); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showInfoToast'); requestCtrl.children.parent_institution = {key: 'poaskdoad-OPAKSDOAP'}; requestCtrl.confirmLinkRemoval(); - expect(messageService.showToast).toHaveBeenCalled(); + expect(messageService.showInfoToast).toHaveBeenCalled(); expect(requestCtrl.children.parent_institution).toEqual(undefined); }); }); diff --git a/frontend/test/specs/search/searchControllerSpec.js b/frontend/test/specs/search/searchControllerSpec.js index 6971173d9..23b8241ab 100644 --- a/frontend/test/specs/search/searchControllerSpec.js +++ b/frontend/test/specs/search/searchControllerSpec.js @@ -95,15 +95,13 @@ } }; }); - spyOn(searchCtrl, 'showSearchFromMobile').and.callThrough(); - spyOn(mdDialog, 'show'); + spyOn(searchCtrl, 'setupResultsInMobile').and.callThrough(); searchCtrl.search_keyword = 'splab'; searchCtrl.search(); expect(searchCtrl.makeSearch).toHaveBeenCalled(); - expect(searchCtrl.showSearchFromMobile).toHaveBeenCalled(); - expect(mdDialog.show).toHaveBeenCalled(); + expect(searchCtrl.setupResultsInMobile).toHaveBeenCalled(); }); it('should call makeSearch(); not mobile screen', () => { @@ -114,17 +112,13 @@ } }; }); - spyOn(searchCtrl, 'showSearchFromMobile').and.callThrough(); - spyOn(mdDialog, 'show'); spyOn(Utils, 'isMobileScreen').and.returnValue(false); searchCtrl.search_keyword = 'splab'; searchCtrl.search(); expect(searchCtrl.makeSearch).toHaveBeenCalled(); - expect(searchCtrl.showSearchFromMobile).not.toHaveBeenCalled(); - expect(mdDialog.show).not.toHaveBeenCalled(); - }) + }); }); describe('makeSearch()', function() { @@ -138,8 +132,10 @@ } }; }); + expect(searchCtrl.hasChanges).toEqual(false); searchCtrl.makeSearch(searchCtrl.search_keyword, 'institution').then(function() { expect(instService.searchInstitutions).toHaveBeenCalledWith('splab', 'active', 'institution'); + expect(searchCtrl.hasChanges).toEqual(true); done(); }); }); @@ -181,14 +177,6 @@ }); }); - describe('showSearchFromMobile', () => { - it('should call mdDialog.show', () => { - spyOn(mdDialog, 'show'); - searchCtrl.showSearchFromMobile(); - expect(mdDialog.show).toHaveBeenCalled(); - }); - }); - describe('leaveMobileSearchPage()', () => { it('should call window.history.back', () => { spyOn(window.history, 'back'); @@ -204,5 +192,40 @@ expect(Utils.isMobileScreen).toHaveBeenCalled(); }); }); + + describe('setHasChanges', () => { + it('should set to true when seach_keyword is defined', () => { + searchCtrl.search_keyword = 'tst'; + expect(searchCtrl.hasChanges).toEqual(false); + searchCtrl.setHasChanges(); + expect(searchCtrl.hasChanges).toEqual(true); + }); + + it('should set to false when seach_keyword is not defined', () => { + searchCtrl.hasChanges = true; + searchCtrl.setHasChanges(); + expect(searchCtrl.hasChanges).toEqual(false); + }); + }); + + describe('setupResultsInMobile()', () => { + it('should unset hasNotSearched when is a mobile screen', () => { + window.screen = {width: 200}; + expect(searchCtrl.hasNotSearched).toEqual(true); + + searchCtrl.setupResultsInMobile(); + + expect(searchCtrl.hasNotSearched).toEqual(false); + }); + + it('should not unset hasNotSearched when is not a mobile screen', () => { + window.screen = { width: 1000 }; + expect(searchCtrl.hasNotSearched).toEqual(true); + + searchCtrl.setupResultsInMobile(); + + expect(searchCtrl.hasNotSearched).toEqual(true); + }); + }); }); })); \ No newline at end of file diff --git a/frontend/test/specs/survey/surveyComponentSpec.js b/frontend/test/specs/survey/surveyComponentSpec.js index 38efea37d..48a751818 100644 --- a/frontend/test/specs/survey/surveyComponentSpec.js +++ b/frontend/test/specs/survey/surveyComponentSpec.js @@ -15,6 +15,17 @@ 'voters': [] }; + const unprocessed_options = + [{ + 'text': 'Option number 1', + 'number_votes': 0, + 'voters': [] }, + { + 'text': 'Option number 2', + 'number_votes': 0, + 'voters': [] + }]; + var options = [{'id' : 0, 'text': 'Option number 1', 'number_votes': 0, @@ -112,4 +123,13 @@ expect(surveyCtrl.post).toEqual({}); }); }); + + describe('_processOptions', function() { + it('should remove empty options and add "id" property in other options', () => { + unprocessed_options.push(option_empty); + surveyCtrl.options = unprocessed_options; + surveyCtrl._processOptions(); + expect(surveyCtrl.options).toEqual(options); + }); + }); })); \ No newline at end of file diff --git a/frontend/test/specs/toolbar/defaultToolbarControllerSpec.js b/frontend/test/specs/toolbar/defaultToolbarControllerSpec.js new file mode 100644 index 000000000..292e3a0a1 --- /dev/null +++ b/frontend/test/specs/toolbar/defaultToolbarControllerSpec.js @@ -0,0 +1,33 @@ +'use strict'; + +describe('DefaultToolbarController test', () => { + beforeEach(module('app')); + + let scope, defaultToolbarCtrl, window; + + beforeEach(inject(function ($componentController, $rootScope, SCREEN_SIZES, $window) { + scope = $rootScope.$new(); + window = $window; + defaultToolbarCtrl = $componentController('defaultToolbar', null, { + scope: scope, + SCREEN_SIZES: SCREEN_SIZES, + $window: window + }); + })); + + describe('isMobileScreen()', () => { + it('should call isMobileScreen', () => { + spyOn(Utils, 'isMobileScreen'); + defaultToolbarCtrl.isMobileScreen(); + expect(Utils.isMobileScreen).toHaveBeenCalled(); + }); + }); + + describe('goBack()', () => { + it('should call back()', () => { + spyOn(window.history, 'back'); + defaultToolbarCtrl.goBack(); + expect(window.history.back).toHaveBeenCalled(); + }); + }); +}); \ No newline at end of file diff --git a/frontend/test/specs/toolbar/mainToolbarControllerSpec.js b/frontend/test/specs/toolbar/mainToolbarControllerSpec.js index f7fc322c1..8d9863a83 100644 --- a/frontend/test/specs/toolbar/mainToolbarControllerSpec.js +++ b/frontend/test/specs/toolbar/mainToolbarControllerSpec.js @@ -31,7 +31,7 @@ describe('MainToolbarController test', () => { it('should call state.go', () => { spyOn(state, 'go'); - mainToolbarCtrl.changeState('app.user.timeline', {}); + mainToolbarCtrl.changeState(); expect(state.go).toHaveBeenCalled(); }); diff --git a/frontend/test/specs/toolbar/whiteToolbarControllerSpec.js b/frontend/test/specs/toolbar/whiteToolbarControllerSpec.js new file mode 100644 index 000000000..0f44bae74 --- /dev/null +++ b/frontend/test/specs/toolbar/whiteToolbarControllerSpec.js @@ -0,0 +1,33 @@ +'use strict'; + +describe('DefaultToolbarController test', () => { + beforeEach(module('app')); + + let scope, whiteToolbarCtrl, window; + + beforeEach(inject(function ($componentController, $rootScope, SCREEN_SIZES, $window) { + scope = $rootScope.$new(); + window = $window; + whiteToolbarCtrl = $componentController('whiteToolbar', null, { + scope: scope, + SCREEN_SIZES: SCREEN_SIZES, + $window: window + }); + })); + + describe('isMobileScreen()', () => { + it('should call isMobileScreen', () => { + spyOn(Utils, 'isMobileScreen'); + whiteToolbarCtrl.isMobileScreen(); + expect(Utils.isMobileScreen).toHaveBeenCalled(); + }); + }); + + describe('goBack()', () => { + it('should call back()', () => { + spyOn(window.history, 'back'); + whiteToolbarCtrl.goBack(); + expect(window.history.back).toHaveBeenCalled(); + }); + }); +}); \ No newline at end of file diff --git a/frontend/test/specs/user/configProfileControllerSpec.js b/frontend/test/specs/user/configProfileControllerSpec.js new file mode 100644 index 000000000..5a3a0e41a --- /dev/null +++ b/frontend/test/specs/user/configProfileControllerSpec.js @@ -0,0 +1,393 @@ +'use strict'; + +(describe('Test ConfigProfileController', function() { + let configCtrl, q, scope, userService, createCrtl, + authService, imageService, mdDialog, cropImageService, messageService, + stateParams, observerRecorderService, pushNotificationService; + + let institution, other_institution, user, newUser, authUser; + + const setUpModels = () => { + institution = { + name: 'institution', + key: '987654321' + }; + + other_institution = { + name: 'other_institution', + key: '3279847298' + }; + + user = new User({ + name: 'User', + cpf: '121.445.044-07', + email: 'teste@gmail.com', + current_institution: institution, + institutions: [institution], + uploaded_images: [], + institutions_admin: [], + state: 'active' + }); + + newUser = new User({ + ...user, + name: 'newUser' + }); + }; + + const fakeCallback = response => { + return () => { + return { + then: (callback) => { + return callback(response); + } + }; + } + } + + beforeEach(module('app')); + + beforeEach(inject(function($controller, $q, $rootScope, $mdDialog, UserService, + AuthService, ImageService, CropImageService, MessageService, $stateParams, ObserverRecorderService, PushNotificationService) { + + q = $q; + scope = $rootScope.$new(); + imageService = ImageService; + mdDialog = $mdDialog; + userService = UserService; + cropImageService = CropImageService; + messageService = MessageService; + authService = AuthService; + stateParams = $stateParams; + observerRecorderService = ObserverRecorderService; + pushNotificationService = PushNotificationService; + + createCrtl = function() { + return $controller('ConfigProfileController', { + scope: scope, + authService: authService, + userService: userService, + imageService: imageService, + cropImageService : cropImageService, + messageService: messageService + }); + }; + + setUpModels(); + authService.login(user); + configCtrl = createCrtl(); + configCtrl.$onInit(); + })); + + describe('onInit()', () => { + it('should call _setupUser', () => { + spyOn(configCtrl, '_setupUser'); + configCtrl.$onInit(); + expect(configCtrl._setupUser).toHaveBeenCalled(); + }); + + it('should set configProfileCtrl.pushNotification according to PushNotificationService.isPushNotificationActive', () => { + spyOn(pushNotificationService, 'isPushNotificationActive').and.callFake(()=> q.when(true)); + configCtrl.$onInit(); + scope.$apply(); + expect(configCtrl.pushNotification).toBe(true); + expect(pushNotificationService.isPushNotificationActive).toHaveBeenCalled(); + + pushNotificationService.isPushNotificationActive.and.callFake(()=> q.when(false)); + configCtrl.$onInit(); + scope.$apply(); + expect(configCtrl.pushNotification).toBe(false); + expect(pushNotificationService.isPushNotificationActive).toHaveBeenCalled(); + }); + }); + + describe('_setupUser()', function() { + + it("should set user object and observer when the user can edit", function() { + spyOn(configCtrl, 'canEdit').and.returnValue(true); + spyOn(observerRecorderService, 'register'); + spyOn(configCtrl, '_checkUserName'); + authUser = authService.getCurrentUser(); + + configCtrl._setupUser(); + + expect(configCtrl.user).toEqual(authUser); + expect(configCtrl.newUser).toEqual(configCtrl.user); + expect(observerRecorderService.register).toHaveBeenCalledWith(authUser); + expect(configCtrl._checkUserName).toHaveBeenCalled(); + }); + + it("should get the user via when the user can not edit", function() { + spyOn(configCtrl, 'canEdit').and.returnValue(false); + spyOn(userService, 'getUser').and.callFake(fakeCallback(user)); + stateParams.userKey = "user-key"; + + configCtrl._setupUser(); + + expect(userService.getUser).toHaveBeenCalledWith(stateParams.userKey); + expect(configCtrl.user).toEqual(user); + }); + }); + + describe('_checkUserName()', () => { + + it("should not delete user and newUser name prop when it is not 'UnKnown'", () => { + configCtrl.user = user; + configCtrl.newUser = newUser; + configCtrl._checkUserName(); + expect(configCtrl.user.name).toBe(user.name); + expect(configCtrl.newUser.name).toBe(newUser.name); + }); + + it("should set the user and newUser name to an empty string when it is 'UnKnown'", () => { + configCtrl.user = {...user, name:'Unknown'}; + configCtrl.newUser = {...configCtrl.user}; + configCtrl._checkUserName(); + expect(configCtrl.user.name).toBe(""); + expect(configCtrl.newUser.name).toBe(""); + }); + }); + + describe('canEdit', () => { + it(`should be true when the loggend user is accessing + its on profile page`, () => { + user.key = "user-key"; + authService.getCurrentUser = () => user; + stateParams.userKey = user.key; + expect(configCtrl.canEdit()).toBe(true); + }); + + it(`should be false when the loggend user is accessing + the profile page of another user`, () => { + user.key = "user-key"; + authService.getCurrentUser = () => user; + stateParams.userKey = "other-user-key"; + expect(configCtrl.canEdit()).toBe(false); + }); + }); + + describe('addImage()', function() { + + it('Should set a new image to the user', function() { + const imageInput = createImage(100); + const imageOutput = createImage(800); + spyOn(imageService, 'compress').and.returnValue(q.when(imageOutput)); + spyOn(imageService, 'readFile'); + configCtrl.addImage(imageInput); + scope.$apply(); + expect(imageService.compress).toHaveBeenCalledWith(imageInput, 800); + expect(configCtrl.photo_user).toBe(imageOutput); + expect(imageService.readFile).toHaveBeenCalled(); + expect(configCtrl.file).toBe(null); + }); + }); + + describe('cropImage()', function() { + beforeEach(function() { + const image = createImage(100); + spyOn(cropImageService, 'crop').and.callFake(fakeCallback("Image")); + spyOn(imageService, 'compress').and.callFake(fakeCallback(image)); + spyOn(imageService, 'readFile').and.callFake(function() { + configCtrl.newUser.photo_url = "Base64 data of photo"; + }); + }); + + it('should crop image in config user', function() { + spyOn(configCtrl, 'addImage'); + const image = createImage(100); + configCtrl.cropImage(image); + expect(cropImageService.crop).toHaveBeenCalled(); + expect(configCtrl.addImage).toHaveBeenCalled(); + }); + }); + + describe('finish()', function(){ + + it('Should call _saveImage and _saveUser', function() { + spyOn(configCtrl, '_saveImage').and.returnValue(q.when()); + spyOn(configCtrl, '_saveUser').and.returnValue(q.when()); + configCtrl.loadingSubmission = true; + + configCtrl.finish(); + scope.$apply(); + + expect(configCtrl._saveImage).toHaveBeenCalled(); + expect(configCtrl._saveUser).toHaveBeenCalled(); + expect(configCtrl.loadingSubmission).toBe(false); + }); + }); + + describe('_saveImage', () => { + + it('should save the image if there is a new one', () => { + const userImage = createImage(50); + const data = {url: 'img-url'}; + configCtrl.photo_user = userImage; + expect(configCtrl.user.photo_url).toBeUndefined(); + spyOn(imageService, 'saveImage').and.returnValue(q.when(data)); + spyOn(configCtrl.user.uploaded_images, 'push'); + + configCtrl._saveImage(); + scope.$apply(); + + expect(imageService.saveImage).toHaveBeenCalledWith(configCtrl.photo_user); + expect(configCtrl.user.photo_url).toBe(data.url); + expect(configCtrl.user.uploaded_images.push).toHaveBeenCalledWith(data.url); + }); + + it('should do nothing when there is no image to save', () => { + configCtrl.photo_user = undefined; + spyOn(imageService, 'saveImage'); + configCtrl._saveImage(); + expect(imageService.saveImage).not.toHaveBeenCalled(); + }); + }); + + describe('_saveUser()', () => { + + it('should save the user and show a message', () => { + const patch = {name: 'newName'}; + spyOn(configCtrl.newUser, 'isValid').and.returnValue(true); + spyOn(observerRecorderService, 'generate').and.returnValue(patch); + spyOn(userService, 'save').and.returnValue(q.when()); + spyOn(authService, 'save'); + spyOn(messageService, 'showInfoToast'); + + configCtrl._saveUser(); + scope.$apply(); + + expect(observerRecorderService.generate).toHaveBeenCalled(); + expect(userService.save).toHaveBeenCalledWith(patch); + expect(authService.save).toHaveBeenCalledWith(); + expect(messageService.showInfoToast).toHaveBeenCalledWith("Edição concluída com sucesso"); + }); + + it("Should show a message when the user is invalid", function(){ + spyOn(messageService, 'showErrorToast'); + spyOn(configCtrl, '_saveImage').and.returnValue(Promise.resolve()); + spyOn(configCtrl.newUser, 'isValid').and.returnValue(false); + configCtrl._saveUser().should.be.resolved; + expect(messageService.showErrorToast).toHaveBeenCalledWith("Campos obrigatórios não preenchidos corretamente."); + }); + }); + + describe('deleteAccount()', function() { + + let promise; + + beforeEach(function() { + spyOn(mdDialog, 'show').and.callFake(fakeCallback()); + spyOn(userService, 'deleteAccount').and.callFake(fakeCallback()); + spyOn(authService, 'logout').and.callFake(fakeCallback()); + promise = configCtrl.deleteAccount(); + }); + + it('Should call mdDialog.show()', function(done) { + promise.then(function() { + expect(mdDialog.show).toHaveBeenCalled(); + done(); + }); + }); + + it('Should call userService.deleteAccount()', function(done) { + promise.then(function() { + expect(userService.deleteAccount).toHaveBeenCalled(); + done(); + }); + }); + + it('Should call authService.logout()', function(done) { + promise.then(function() { + expect(authService.logout).toHaveBeenCalled(); + done(); + }); + }); + }); + + describe('editProfile', function() { + it('should call mdDialog.show', function() { + spyOn(mdDialog, 'show'); + configCtrl.editProfile(institution, '$event'); + expect(mdDialog.show).toHaveBeenCalled(); + }); + }); + + describe('goBack()', () => { + it('should call the window back function', () => { + spyOn(window.history, 'back'); + configCtrl.goBack(); + expect(window.history.back).toHaveBeenCalled(); + }); + }); + + describe('pushChange', () => { + beforeEach( function () { + spyOn(configCtrl,'_subscribeUser'); + spyOn(configCtrl,'_unsubscribeUser'); + }); + + it('should call subscribeUser user if configProfileCtrl.pushNotification is true', () => { + configCtrl.pushNotification = true; + configCtrl.pushChange(); + expect(configCtrl._subscribeUser).toHaveBeenCalled(); + expect(configCtrl._unsubscribeUser).not.toHaveBeenCalled(); + }); + + it('should call unsubscribeUser user if configProfileCtrl.pushNotification is false', () => { + configCtrl.pushNotification = false; + configCtrl.pushChange(); + expect(configCtrl._subscribeUser).not.toHaveBeenCalled(); + expect(configCtrl._unsubscribeUser).toHaveBeenCalled() + }) + }); + + describe('_unsubscribeUser', () => { + beforeEach( function () { + spyOn(configCtrl,'_openDialog').and.callFake(() => q.when()); + spyOn(pushNotificationService, 'unsubscribeUserNotification'); + configCtrl.pushNotification = false; + }); + + it('should call PushNotificationService.unsubscribeUserNotification() if user confirm dialog', () => { + configCtrl._unsubscribeUser(); + scope.$apply(); + expect(configCtrl._openDialog).toHaveBeenCalled(); + expect(pushNotificationService.unsubscribeUserNotification).toHaveBeenCalled(); + expect(configCtrl.pushNotification).toBe(false); + }); + + it('should set configProfileCtrl.pushNotification to true if user cancel dialog', () => { + configCtrl._openDialog.and.callFake(() => q.reject()); + configCtrl._unsubscribeUser(); + scope.$apply(); + expect(configCtrl._openDialog).toHaveBeenCalled(); + expect(pushNotificationService.unsubscribeUserNotification).not.toHaveBeenCalled(); + expect(configCtrl.pushNotification).toBe(true); + }) + }); + + describe('_subscribeUser', () => { + beforeEach( function () { + spyOn(configCtrl,'_openDialog').and.callFake(() => q.when()); + spyOn(pushNotificationService, 'subscribeUserNotification'); + configCtrl.pushNotification = true; + }); + + it('should call PushNotificationService.subscribeUserNotification() if user confirm dialog', () => { + configCtrl._subscribeUser(); + scope.$apply(); + expect(configCtrl._openDialog).toHaveBeenCalled(); + expect(pushNotificationService.subscribeUserNotification).toHaveBeenCalled(); + expect(configCtrl.pushNotification).toBe(true); + }); + + it('should set configProfileCtrl.pushNotification to false if user cancel dialog', () => { + configCtrl._openDialog.and.callFake(() => q.reject()); + configCtrl._subscribeUser(); + scope.$apply(); + expect(configCtrl._openDialog).toHaveBeenCalled(); + expect(pushNotificationService.subscribeUserNotification).not.toHaveBeenCalled(); + expect(configCtrl.pushNotification).toBe(false); + }) + }); +})); \ No newline at end of file diff --git a/frontend/test/specs/user/editProfileControllerSpec.js b/frontend/test/specs/user/editProfileControllerSpec.js new file mode 100644 index 000000000..fc33a0904 --- /dev/null +++ b/frontend/test/specs/user/editProfileControllerSpec.js @@ -0,0 +1,149 @@ +'use strict'; + +(describe('Test EditProfileController', function() { + + let scope, mdDialog, authService, profileService, messageService, q, + editProfileCtrl, observerRecorderService, userToEdit; + + let institution, user, profile; + + const setupModels = () => { + institution = { + name: 'INSTITUTION', + key: '987654321' + }; + + user = { + name: 'User', + email: 'teste@gmail', + institutions: [institution], + institution_profiles: [{ + office: 'developer', + phone: '(99) 99999-9999', + email: 'teste@gmail.com', + institution_key: institution.key + }], + state: 'active' + }; + + profile = { + office: 'member', + email: user.email, + institution: institution + }; + } + + beforeEach(module('app')); + + beforeEach(inject(function($controller, $rootScope, ProfileService, + $mdDialog, AuthService, MessageService, ObserverRecorderService, $q) { + + profileService = ProfileService; + scope = $rootScope.$new(); + mdDialog = $mdDialog; + q = $q; + authService = AuthService; + observerRecorderService = ObserverRecorderService; + messageService = MessageService; + + setupModels(); + authService.login(user); + userToEdit = authService.getCurrentUser(); + + editProfileCtrl = $controller('EditProfileController', { + scope: scope, + profile: profile, + institution: institution, + user: userToEdit, + profileService: profileService, + authService: authService, + mdDialog: mdDialog, + MessageService: MessageService + }); + editProfileCtrl.$onInit(); + })); + + describe('onInit()', () => { + it('should set user, profile and observer', () => { + spyOn(authService, 'getCurrentUser').and.returnValue(user); + spyOn(observerRecorderService, 'register'); + + editProfileCtrl.$onInit(); + + expect(editProfileCtrl.user).toBe(user); + expect(editProfileCtrl.profile).toBe(profile); + expect(observerRecorderService.register).toHaveBeenCalledWith(editProfileCtrl.user); + }); + }); + + describe('getIntName()', () => { + it('should call limitString', () => { + spyOn(Utils, 'limitString'); + editProfileCtrl.getInstName(); + expect(Utils.limitString).toHaveBeenCalledWith(profile.institution.name, 67); + }); + }); + + describe('edit', function() { + it('should call editProfile() and save()', function() { + const patch = {...profile, office: 'developer'}; + spyOn(observerRecorderService, 'generate').and.returnValue(patch); + spyOn(profileService, 'editProfile').and.returnValue(q.when()); + spyOn(authService, 'save'); + spyOn(messageService, 'showInfoToast'); + spyOn(mdDialog, 'hide'); + + editProfileCtrl.edit(); + scope.$apply(); + + expect(observerRecorderService.generate).toHaveBeenCalled(); + expect(profileService.editProfile).toHaveBeenCalledWith(patch); + expect(messageService.showInfoToast).toHaveBeenCalledWith('Perfil editado com sucesso'); + expect(authService.save).toHaveBeenCalled(); + expect(mdDialog.hide).toHaveBeenCalled(); + }); + + it('should not call editProfile() if there is no alterations', function() { + const patch = {}; + spyOn(observerRecorderService, 'generate').and.returnValue(patch); + spyOn(profileService, 'editProfile'); + spyOn(mdDialog, 'hide'); + + editProfileCtrl.edit(); + + expect(observerRecorderService.generate).toHaveBeenCalled(); + expect(profileService.editProfile).not.toHaveBeenCalled(); + expect(mdDialog.hide).toHaveBeenCalled(); + }); + + it('should show a message when the edited profile is invalid', () => { + editProfileCtrl.profile.office = undefined; + spyOn(observerRecorderService, 'generate'); + spyOn(profileService, 'editProfile'); + spyOn(messageService, 'showErrorToast'); + + editProfileCtrl.edit(); + + expect(observerRecorderService.generate).not.toHaveBeenCalled(); + expect(profileService.editProfile).not.toHaveBeenCalled(); + expect(messageService.showErrorToast).toHaveBeenCalledWith('O cargo é obrigatório.'); + }); + }); + + describe('removeProfile()', () => { + it('should call the removeProfile function from ProfileService', () => { + spyOn(profileService, 'removeProfile'); + const event = {}; + editProfileCtrl.removeProfile(event); + expect(profileService.removeProfile).toHaveBeenCalledWith(event, editProfileCtrl.profile.institution); + }); + }); + + describe('closeDialog', function() { + it('should call hide()', function() { + spyOn(mdDialog, 'hide'); + editProfileCtrl.closeDialog(); + expect(mdDialog.hide).toHaveBeenCalled(); + }); + }); +})); \ No newline at end of file diff --git a/frontend/test/specs/user/profileControllerSpec.js b/frontend/test/specs/user/profileControllerSpec.js index 38bda0bab..8f744d1f4 100644 --- a/frontend/test/specs/user/profileControllerSpec.js +++ b/frontend/test/specs/user/profileControllerSpec.js @@ -33,6 +33,7 @@ }); }; profileCtrl = createCtrl(); + })); describe('goToConfigProfile()', function() { @@ -40,11 +41,12 @@ beforeEach(function() { spyOn(mdDialog, 'cancel'); spyOn(state, 'go'); + profileCtrl.user = user; profileCtrl.goToConfigProfile(); }); it('should call state.go()', function() { - expect(state.go).toHaveBeenCalledWith(states.CONFIG_PROFILE); + expect(state.go).toHaveBeenCalledWith(states.CONFIG_PROFILE, {userKey: user.key}); }); it('should call mdDialog.cancel()', function() { diff --git a/frontend/test/specs/user/profileServiceSpec.js b/frontend/test/specs/user/profileServiceSpec.js index 7f4a1ddfe..26bdfd425 100644 --- a/frontend/test/specs/user/profileServiceSpec.js +++ b/frontend/test/specs/user/profileServiceSpec.js @@ -2,20 +2,38 @@ (describe('Test ProfileService', function() { - var httpBackend, mdDialog, profileService; + const USER_URI = '/api/user'; + let mdDialog, profileService, httpService, scope, + authService, q, messageService, userService; + + let user, institution; + + const setupModels = () => { + user = new User({ + key: 'user-key' + }); + + institution = new Institution({ + key: 'inst-key' + }); + }; beforeEach(module('app')); - beforeEach(inject(function($mdDialog, $httpBackend, ProfileService) { + beforeEach(inject(function($mdDialog, ProfileService, HttpService, + AuthService, $q, MessageService, $rootScope, UserService) { mdDialog = $mdDialog; - httpBackend = $httpBackend; profileService = ProfileService; - })); + httpService = HttpService; + authService = AuthService; + messageService = MessageService; + scope = $rootScope.$new(); + q = $q; + userService = UserService; - afterEach(function() { - httpBackend.verifyNoOutstandingExpectation(); - httpBackend.verifyNoOutstandingRequest(); - }); + setupModels(); + authService.login(user); + })); describe('showProfile()', function() { @@ -26,4 +44,83 @@ expect(mdDialog.show).toHaveBeenCalled(); }); }); + + describe('editProfile()', () => { + it('should send a patch request', () => { + const data = {name: 'anotherName'}; + spyOn(JSON, 'parse').and.returnValue(data); + spyOn(httpService, 'patch'); + profileService.editProfile(data); + expect(httpService.patch).toHaveBeenCalledWith(USER_URI, data); + }); + }); + + describe('removeProfile()', () => { + beforeEach(() => { + spyOn(authService, 'getCurrentUser').and.returnValue(user); + spyOn(profileService, '_hasMoreThanOneInstitution').and.returnValue(true); + spyOn(mdDialog, 'show').and.returnValue(q.when()); + spyOn(mdDialog, 'confirm').and.callThrough(); + spyOn(profileService, '_deleteInstitution'); + spyOn(messageService, 'showErrorToast'); + }); + + it(`should show a confirm dialog and remove + the connection between user and institution `, () => { + spyOn(profileService, '_isAdmin').and.returnValue(false); + + profileService.removeProfile({}, institution); + scope.$apply(); + + expect(profileService._isAdmin).toHaveBeenCalledWith(institution); + expect(profileService._hasMoreThanOneInstitution).toHaveBeenCalled(); + expect(mdDialog.confirm).toHaveBeenCalled(); + expect(mdDialog.show).toHaveBeenCalled(); + expect(profileService._deleteInstitution).toHaveBeenCalledWith(institution.key); + }); + + it(`should show a confirm dialog and remove + the connection between user and institution `, () => { + spyOn(profileService, '_isAdmin').and.returnValue(true); + + profileService.removeProfile({}, institution); + + expect(mdDialog.confirm).not.toHaveBeenCalled(); + expect(mdDialog.show).not.toHaveBeenCalled(); + const msg = 'Desvínculo não permitido. Você é administrador dessa instituição.'; + expect(messageService.showErrorToast).toHaveBeenCalledWith(msg); + }); + }); + + describe('_deleteInstitution', () => { + it(`should call deleteInstitution and _removeConnection`, () => { + spyOn(userService, 'deleteInstitution').and.returnValue(q.when()); + spyOn(profileService, '_removeConnection'); + profileService._deleteInstitution(institution.key); + scope.$apply(); + + expect(userService.deleteInstitution).toHaveBeenCalledWith(institution.key); + expect(profileService._removeConnection).toHaveBeenCalledWith(institution.key); + }); + }); + + describe('_removeConnection', () => { + it("should save the user modifications if it has more than one institution", () => { + spyOn(profileService, '_hasMoreThanOneInstitution').and.returnValue(true); + spyOn(authService, 'save'); + + profileService._removeConnection(institution.key); + + expect(authService.save).toHaveBeenCalled(); + }) + + it("should logout the user if it does not have more than one institution", () => { + spyOn(profileService, '_hasMoreThanOneInstitution').and.returnValue(false); + spyOn(authService, 'logout'); + + profileService._removeConnection(institution.key); + + expect(authService.logout).toHaveBeenCalled(); + }) + }); })); \ No newline at end of file diff --git a/frontend/test/specs/user/userRequestFormControllerSpec.js b/frontend/test/specs/user/userRequestFormControllerSpec.js index 748b1c322..907f90562 100644 --- a/frontend/test/specs/user/userRequestFormControllerSpec.js +++ b/frontend/test/specs/user/userRequestFormControllerSpec.js @@ -103,12 +103,12 @@ it('should show an error message when the request fails', function () { expect(userReqFormCtrl.isRequestSent).toBeFalsy(); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); deferred.reject(); userReqFormCtrl.sendRequest(); scope.$apply(); const msg = "Um erro ocorreu. Verifique as informações e tente novamente"; - expect(messageService.showToast).toHaveBeenCalledWith(msg) + expect(messageService.showErrorToast).toHaveBeenCalledWith(msg) expect(userReqFormCtrl.isRequestSent).toBeFalsy(); }); }); @@ -159,10 +159,10 @@ it(`should show a message when the institution has already been requested by the user`, function () { spyOn(userReqFormCtrl, '_wasInstRequested').and.returnValue(true); - spyOn(messageService, 'showToast'); + spyOn(messageService, 'showErrorToast'); userReqFormCtrl._verifyAndSendRequest(); const msg = "Você já solicitou para fazer parte dessa instituição."; - expect(messageService.showToast).toHaveBeenCalledWith(msg) + expect(messageService.showErrorToast).toHaveBeenCalledWith(msg) }); it(`should send the request when the institution diff --git a/frontend/test/specs/utils/featureToggleServiceSpec.js b/frontend/test/specs/utils/featureToggleServiceSpec.js new file mode 100644 index 000000000..3f88638ab --- /dev/null +++ b/frontend/test/specs/utils/featureToggleServiceSpec.js @@ -0,0 +1,136 @@ +'use strict'; + +describe('Test FeatureToggleService', function() { + beforeEach(module('app')); + + let featureToggleService, httpBackend; + + const feature = { + name: 'test-feature', + enable_mobile: 'ALL', + enable_desktop: 'DISABLED' + }; + + const otherFeature = { + name: 'test-other-feature', + enable_mobile: 'DISABLED', + enable_desktop: 'ALL' + }; + + beforeEach(inject(function($httpBackend, FeatureToggleService) { + featureToggleService = FeatureToggleService; + httpBackend = $httpBackend; + + $httpBackend.whenGET(`/api/feature-toggle?name=${feature.name}`).respond([feature]); + $httpBackend.whenGET(`/api/feature-toggle?name=${otherFeature.name}`).respond([otherFeature]); + $httpBackend.whenGET('/api/feature-toggle').respond([feature, otherFeature]); + })); + + afterEach(function() { + httpBackend.verifyNoOutstandingExpectation(); + httpBackend.verifyNoOutstandingRequest(); + }); + + describe('Test _getFeature', function() { + + it('Should be return all features', function(done) { + featureToggleService._getFeatures().then(function(response) { + expect(response).toEqual([feature, otherFeature]); + done(); + }); + httpBackend.flush(); + }); + + it('Should be return feature test-feature', function(done) { + featureToggleService._getFeatures(feature.name).then(function(response) { + expect(response).toEqual([feature]); + done(); + }); + httpBackend.flush(); + }); + + it('Should be return feature test-other-feature', function(done) { + featureToggleService._getFeatures(otherFeature.name).then(function(response) { + expect(response).toEqual([otherFeature]); + done(); + }); + httpBackend.flush(); + }); + }); + + describe('Test getAllFeatures', function() { + + it('Should be return all features', function(done) { + featureToggleService.getAllFeatures().then(function(response) { + expect(response).toEqual([feature, otherFeature]); + done(); + }); + httpBackend.flush(); + }); + }); + + describe('Test getFeature', function() { + it('Should be return feature test-feature', function(done) { + featureToggleService.getFeature(feature.name).then(function(response) { + expect(response).toEqual([feature]); + done(); + }); + httpBackend.flush(); + }); + + it('Should be return feature test-other-feature', function(done) { + featureToggleService.getFeature(otherFeature.name).then(function(response) { + expect(response).toEqual([otherFeature]); + done(); + }); + httpBackend.flush(); + }); + }); + + + describe('Test isEnabled', function() { + it('Should be return true with test-feature', function(done) { + window.screen = {width: 100}; + featureToggleService.isEnabled(feature.name).then(function(response) { + expect(response).toBeTruthy(); + done(); + }); + httpBackend.flush(); + }); + + it('Should be return true with test-other-feature', function(done) { + window.screen = {width: 1000}; + featureToggleService.isEnabled(otherFeature.name).then(function(response) { + expect(response).toBeTruthy(); + done(); + }); + httpBackend.flush(); + }); + + + it('Should be return false with test-feature', function(done) { + window.screen = {width: 1000}; + featureToggleService.isEnabled(feature.name).then(function(response) { + expect(response).toEqual(false); + done(); + }); + httpBackend.flush(); + }); + + it('Should be return false with test-other-feature', function(done) { + window.screen = {width: 100}; + featureToggleService.isEnabled(otherFeature.name).then(function(response) { + expect(response).toEqual(false); + done(); + }); + httpBackend.flush(); + }); + + it('Should be generated exception', function(done) { + featureToggleService.isEnabled().catch(function(message) { + expect(message).toEqual("Required param featureName"); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/frontend/test/specs/utils/mapStateToFeatureServiceSpec.js b/frontend/test/specs/utils/mapStateToFeatureServiceSpec.js new file mode 100644 index 000000000..39a4c711e --- /dev/null +++ b/frontend/test/specs/utils/mapStateToFeatureServiceSpec.js @@ -0,0 +1,50 @@ +'use strict'; + + +describe('MapStateToFeatureService Test', function() { + beforeEach(module('app')); + + let mapStateToFeatureService; + + beforeEach(inject(function(MapStateToFeatureService) { + mapStateToFeatureService = MapStateToFeatureService; + + mapStateToFeatureService._statesToFeature = { + 'app.manage-user': 'manage-user', + 'app.edit-inst': 'edit-inst' + }; + })); + + describe('Test getFeatureByState', function() { + + it('Should be return feature', function() { + let feature = mapStateToFeatureService.getFeatureByState('app.manage-user'); + expect(feature).toEqual('manage-user'); + + feature = mapStateToFeatureService.getFeatureByState('app.edit-inst'); + expect(feature).toEqual('edit-inst'); + }); + + it('Should be return undefined with unregistred state', function() { + let feature = mapStateToFeatureService.getFeatureByState('app.manage-inst'); + expect(feature).toBeUndefined(); + }); + }); + + describe('Test containsFeature', function() { + + it('Should be return true', function() { + let contain = mapStateToFeatureService.containsFeature('app.edit-inst'); + expect(contain).toBeTruthy(); + + contain = mapStateToFeatureService.containsFeature('app.manage-user'); + expect(contain).toBeTruthy(); + }); + + + it('Should be return false', function() { + let contain = mapStateToFeatureService.containsFeature('app.manage-inst'); + expect(contain).toEqual(false); + }); + }); +}); \ No newline at end of file diff --git a/frontend/test/specs/utils/messageServiceSpec.js b/frontend/test/specs/utils/messageServiceSpec.js index 781e34314..1fe192b54 100644 --- a/frontend/test/specs/utils/messageServiceSpec.js +++ b/frontend/test/specs/utils/messageServiceSpec.js @@ -11,11 +11,34 @@ service = MessageService; })); - describe("showToast", function() { + describe("showInfoToast", function() { + it('should call mdToast.show', function() { + window.screen = { width: 2000 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showInfoToast(""); + expect(mdToast.show).toHaveBeenCalled(); + }); + + it('should not call mdToast.show', function() { + window.screen = { width: 200 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showInfoToast(""); + expect(mdToast.show).not.toHaveBeenCalled(); + }); + }); + + describe("showErrorToast", function() { + it('should call mdToast.show', function() { + window.screen = { width: 2000 }; + spyOn(mdToast, 'show').and.callThrough(); + service.showErrorToast(""); + expect(mdToast.show).toHaveBeenCalled(); + }); it('should call mdToast.show', function() { + window.screen = { width: 200 }; spyOn(mdToast, 'show').and.callThrough(); - service.showToast(""); + service.showErrorToast(""); expect(mdToast.show).toHaveBeenCalled(); }); }); diff --git a/frontend/toolbar/defaultToolbar.component.js b/frontend/toolbar/defaultToolbar.component.js new file mode 100644 index 000000000..00ff39bd7 --- /dev/null +++ b/frontend/toolbar/defaultToolbar.component.js @@ -0,0 +1,38 @@ +'use strict'; + +(function () { + const app = angular.module("app"); + + /** + * Generic component that lives in some pages that doesn't need + * the main toolbar. Only for mobile. + * {object} menuOptions -- Some options the user can choose when the menu is clicked + */ + app.component("defaultToolbar", { + templateUrl: 'app/toolbar/default_toolbar_mobile.html', + controller: ['SCREEN_SIZES', '$window', DefaultToolbarController], + controllerAs: 'defaultToolbarCtrl', + bindings: { + menuOptions: '=', + noOptions: '@' + } + }); + + function DefaultToolbarController(SCREEN_SIZES, $window) { + const defaultToolbarCtrl = this; + + /** + * Returns true if the application is being used by a mobile + */ + defaultToolbarCtrl.isMobileScreen = () => { + return Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE); + }; + + /** + * Redirect the user to the previous page. + */ + defaultToolbarCtrl.goBack = () => { + $window.history.back(); + }; + } +})(); \ No newline at end of file diff --git a/frontend/toolbar/default_toolbar_mobile.css b/frontend/toolbar/default_toolbar_mobile.css new file mode 100644 index 000000000..21f7a0c3c --- /dev/null +++ b/frontend/toolbar/default_toolbar_mobile.css @@ -0,0 +1,22 @@ +.default-toolbar-mobile { + display: grid; + grid-template-columns: 50% 50%; + grid-template-rows: 100%; + width: 100%; +} + +.toolbar-back-button { + justify-self: start; + grid-column-start: 1; + grid-column-end: 2; +} + +.toolbar-back-button md-icon { + font-size: 2.5em; +} + +.default-toolbar-menu-container { + justify-self: end; + grid-column-start: 2; + grid-column-end: 3; +} \ No newline at end of file diff --git a/frontend/toolbar/default_toolbar_mobile.html b/frontend/toolbar/default_toolbar_mobile.html new file mode 100644 index 000000000..21729e553 --- /dev/null +++ b/frontend/toolbar/default_toolbar_mobile.html @@ -0,0 +1,25 @@ + +
    + + keyboard_arrow_left + +
    + + + more_vert + + + +
    + + {{option.icon}} + + {{option.title}} +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/toolbar/mainToolbar.component.js b/frontend/toolbar/mainToolbar.component.js index 1ddf99b9e..10cc6e261 100644 --- a/frontend/toolbar/mainToolbar.component.js +++ b/frontend/toolbar/mainToolbar.component.js @@ -40,7 +40,11 @@ * @param {object} params -- the state's params */ mainToolbarCtrl.changeState = (state, params) => { - $state.go(state, params); + if ($state.current.name === STATES.EVENTS) { + $state.go(STATES.SEARCH_EVENT, {search_keyword: ''}); + } else { + $state.go(STATES.SEARCH, {search_keyword: ''}); + } }; /** diff --git a/frontend/toolbar/main_toolbar_mobile.html b/frontend/toolbar/main_toolbar_mobile.html index 71744e11a..6029d2370 100644 --- a/frontend/toolbar/main_toolbar_mobile.html +++ b/frontend/toolbar/main_toolbar_mobile.html @@ -1,4 +1,4 @@ -
    @@ -41,7 +41,7 @@
    diff --git a/frontend/toolbar/whiteToolbar.component.js b/frontend/toolbar/whiteToolbar.component.js new file mode 100644 index 000000000..6f503fd51 --- /dev/null +++ b/frontend/toolbar/whiteToolbar.component.js @@ -0,0 +1,36 @@ +'use strict'; + +(function () { + const app = angular.module("app"); + + app.component('whiteToolbar', { + templateUrl: 'app/toolbar/white_toolbar_mobile.html', + controller: ['$window', 'SCREEN_SIZES', WhiteToolbarController], + controllerAs: 'whiteToolbarCtrl', + bindings: { + title: '@', + rightButton: '=', + primaryButtonIcon: '@', + titleClass: '@', + menuOptions: '=' + } + }); + + function WhiteToolbarController($window, SCREEN_SIZES) { + const whiteToolbarCtrl = this; + + /** + * Redirect the user to the previous page. + */ + whiteToolbarCtrl.goBack = () => { + return $window.history.back(); + }; + + /** + * Returns true if the application is being used by a mobile + */ + whiteToolbarCtrl.isMobileScreen = () => { + return Utils.isMobileScreen(SCREEN_SIZES.SMARTPHONE); + }; + } +})(); \ No newline at end of file diff --git a/frontend/toolbar/white_toolbar_mobile.css b/frontend/toolbar/white_toolbar_mobile.css new file mode 100644 index 000000000..8db5d5b25 --- /dev/null +++ b/frontend/toolbar/white_toolbar_mobile.css @@ -0,0 +1,49 @@ +.white-toolbar-mobile { + background-color: white; + box-shadow: 0px 3px 6px grey; + height: 60px; + width: 100%; + font-size: 20px; + display: grid; + grid-template-rows: auto; + grid-template-columns: 20% 50% auto; + align-items: center; +} + +.toolbar-icon-alignment { + font-size: 2.5em; + line-height: inherit !important; +} + +.edit-inst-toolbar-title { + color: grey; + font-size: 0.8em; + word-break: normal; + grid-column-end: 4 !important; + text-transform: uppercase; +} + +.white-toolbar-menu-button { + grid-column-start: 3; + grid-column-end: 4; + justify-self: end; + align-self: center; +} + +.white-toolbar-title-container { + grid-column-start: 2; + grid-column-end: 3; +} + +.white-toolbar-menu-option-title { + margin-left: 0.5em; +} + +.white-toolbar-menu-content { + width: 100%; +} + +.white-toolbar__menu__item { + display: grid; + grid-template-columns: 10% auto; +} diff --git a/frontend/toolbar/white_toolbar_mobile.html b/frontend/toolbar/white_toolbar_mobile.html new file mode 100644 index 000000000..70bf6c9c2 --- /dev/null +++ b/frontend/toolbar/white_toolbar_mobile.html @@ -0,0 +1,34 @@ +
    + + {{whiteToolbarCtrl.primaryButtonIcon}} + +
    + {{whiteToolbarCtrl.title}} +
    + + {{whiteToolbarCtrl.rightButton.name}} + + {{whiteToolbarCtrl.rightButton.icon}} + + +
    + + + more_vert + + + +
    + + {{option.getIcon()}} + + {{option.title}} +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/frontend/user/configProfile/configProfileController.js b/frontend/user/configProfile/configProfileController.js index 59fa4f708..3eaa10dc4 100644 --- a/frontend/user/configProfile/configProfileController.js +++ b/frontend/user/configProfile/configProfileController.js @@ -1,50 +1,77 @@ 'use strict'; (function () { - var app = angular.module("app"); + angular + .module("app") + .controller("ConfigProfileController", [ + '$state', 'STATES', '$stateParams', 'ProfileService', 'CropImageService', 'AuthService', '$q', + 'UserService', 'ImageService', '$rootScope', 'SCREEN_SIZES', 'MessageService', '$mdDialog', 'ObserverRecorderService', + 'PushNotificationService', + ConfigProfileController + ]); + + function ConfigProfileController($state, STATES, $stateParams, ProfileService, CropImageService, AuthService, + $q, UserService, ImageService, $rootScope, SCREEN_SIZES, MessageService, $mdDialog, ObserverRecorderService, PushNotificationService) { - app.controller("ConfigProfileController", function ConfigProfileController($state, STATES, - CropImageService, AuthService, UserService, ImageService, $rootScope, $q, MessageService, $mdDialog, ObserverRecorderService) { - - var configProfileCtrl = this; + const configProfileCtrl = this; // Variable used to observe the changes on the user model. - var observer; - - configProfileCtrl.user = AuthService.getCurrentUser(); - configProfileCtrl.newUser = _.cloneDeep(configProfileCtrl.user); - configProfileCtrl.loading = false; + let observer; configProfileCtrl.cpfRegex = /^\d{3}\.\d{3}\.\d{3}\-\d{2}$/; - configProfileCtrl.photo_url = configProfileCtrl.newUser.photo_url; configProfileCtrl.loadingSubmission = false; - var HAS_ONLY_ONE_INSTITUTION_MSG = "Esta é a única instituição ao qual você é vinculado." + - " Ao remover o vínculo você não poderá mais acessar o sistema," + - " exceto por meio de novo convite. Deseja remover?"; + const DELETE_ACCOUNT_ALERT = "Ao excluir sua conta você não poderá mais acessar o sistema," + + "exceto por meio de novo convite. Deseja realmente excluir sua conta?"; - var HAS_MORE_THAN_ONE_INSTITUTION_MSG = "Ao remover o vínculo com esta instituição," + - " você deixará de ser membro" + - " e não poderá mais publicar na mesma," + - " no entanto seus posts existentes serão mantidos. Deseja remover?"; + configProfileCtrl.$onInit = () => { + configProfileCtrl._setupUser(); + configProfileCtrl.setSaveButton(); + setPushNotificationModel(); + }; - var DELETE_ACCOUNT_ALERT = "Ao excluir sua conta você não poderá mais acessar o sistema," + - "exceto por meio de novo convite. Deseja realmente excluir sua conta?"; + configProfileCtrl._setupUser = () => { + if(configProfileCtrl.canEdit()) { + configProfileCtrl.user = AuthService.getCurrentUser(); + configProfileCtrl.newUser = _.cloneDeep(configProfileCtrl.user); + observer = ObserverRecorderService.register(configProfileCtrl.user); + configProfileCtrl._checkUserName(); + } else { + UserService.getUser($stateParams.userKey) + .then(user => configProfileCtrl.user = user); + } + } + + configProfileCtrl._checkUserName = () => { + if (configProfileCtrl.user.name === 'Unknown') { + configProfileCtrl.user.name = ""; + configProfileCtrl.newUser.name = ""; + } + } + + configProfileCtrl.getPhoto = () => { + const user = configProfileCtrl.canEdit() ? configProfileCtrl.newUser : configProfileCtrl.user; + return user && user.photo_url; + } configProfileCtrl.addImage = function(image) { - var newSize = 800; + const newSize = 800; ImageService.compress(image, newSize).then(function success(data) { configProfileCtrl.photo_user = data; ImageService.readFile(data, setImage); configProfileCtrl.file = null; }, function error(error) { - MessageService.showToast(error); + MessageService.showErrorToast(error); }); }; + configProfileCtrl.canEdit = () => { + return $stateParams.userKey === AuthService.getCurrentUser().key; + }; + function setImage(image) { $rootScope.$apply(function () { - configProfileCtrl.photo_url = image.src; + configProfileCtrl.newUser.photo_url = image.src; }); } @@ -58,112 +85,66 @@ configProfileCtrl.finish = function finish() { configProfileCtrl.loadingSubmission = true; - if (configProfileCtrl.photo_user) { - configProfileCtrl.loading = true; - ImageService.saveImage(configProfileCtrl.photo_user).then(function (data) { - configProfileCtrl.user.photo_url = data.url; - configProfileCtrl.user.uploaded_images.push(data.url); - saveUser(); - configProfileCtrl.loading = false; - configProfileCtrl.loadingSubmission = false; - }); - } else { - return saveUser(); - } + configProfileCtrl._saveImage().then(_ => { + configProfileCtrl._saveUser() + .finally(_ => { + configProfileCtrl.loadingSubmission = false; + }); + }) }; - function saveUser() { - var deffered = $q.defer(); + configProfileCtrl._saveImage = () => { + if(configProfileCtrl.photo_user) { + return ImageService.saveImage(configProfileCtrl.photo_user) + .then(function (data) { + configProfileCtrl.user.photo_url = data.url; + configProfileCtrl.user.uploaded_images.push(data.url); + }) + } + return $q.when(); + } + + configProfileCtrl._saveUser = () => { if (configProfileCtrl.newUser.isValid()) { updateUser(); - var patch = ObserverRecorderService.generate(observer); - UserService.save(patch).then(function success() { - AuthService.save(); - configProfileCtrl.loadingSubmission = false; - MessageService.showToast("Edição concluída com sucesso"); - $state.go(STATES.HOME); - deffered.resolve(); - }); - } else { - MessageService.showToast("Campos obrigatórios não preenchidos corretamente."); - deffered.reject(); - } - return deffered.promise; + const patch = ObserverRecorderService.generate(observer); + return UserService.save(patch) + .then(() => { + AuthService.save(); + MessageService.showInfoToast("Edição concluída com sucesso"); + }); + } + MessageService.showErrorToast("Campos obrigatórios não preenchidos corretamente."); + return $q.when(); } function updateUser() { - var attributes = ["name", "cpf"]; + const attributes = ["name", "cpf"]; _.forEach(attributes, function(attr){ _.set(configProfileCtrl.user, attr, _.get(configProfileCtrl.newUser, attr)); }); }; - configProfileCtrl.showButton = function () { - return !configProfileCtrl.loading; + configProfileCtrl.removeProfile = (event, institution) => { + ProfileService.removeProfile(event, institution); }; - configProfileCtrl.removeInstitution = function removeInstitution(event, institution) { - if (!isAdmin(institution.key)) { - var confirm = $mdDialog.confirm(); - confirm - .clickOutsideToClose(false) - .title('Remover vínculo com ' + institution.name) - .textContent(hasMoreThanOneInstitution() ? HAS_MORE_THAN_ONE_INSTITUTION_MSG : HAS_ONLY_ONE_INSTITUTION_MSG) - .ariaLabel('Remover instituicao') - .targetEvent(event) - .ok('Sim') - .cancel('Não'); - var promise = $mdDialog.show(confirm); - promise.then(function () { - deleteInstitution(institution.key); - }, function () { - MessageService.showToast('Cancelado'); - }); - return promise; - } else { - MessageService.showToast('Desvínculo não permitido. Você é administrador dessa instituição.'); - } - }; - - configProfileCtrl.editProfile = function editProfile(inst, ev) { + configProfileCtrl.editProfile = function editProfile(profile, event) { + const templateUrl = Utils.selectFieldBasedOnScreenSize( + 'app/user/editProfile/edit_profile.html', + 'app/user/editProfile/edit_profile_mobile.html', + SCREEN_SIZES.SMARTPHONE + ); $mdDialog.show({ - templateUrl: 'app/user/edit_profile.html', + templateUrl: templateUrl, controller: 'EditProfileController', controllerAs: "editProfileCtrl", - locals: { - institution: inst - }, - targetEvent: ev, + locals: { profile }, + targetEvent: event, clickOutsideToClose: false }); }; - function isAdmin(institution_key) { - return configProfileCtrl.newUser.isAdmin(institution_key); - } - - function hasMoreThanOneInstitution() { - return _.size(configProfileCtrl.user.institutions) > 1; - } - - function deleteInstitution(institution_key) { - var promise = UserService.deleteInstitution(institution_key); - promise.then(function success() { - removeConection(institution_key); - }); - return promise; - } - - function removeConection(institution_key) { - if (_.size(configProfileCtrl.user.institutions) > 1) { - configProfileCtrl.user.removeInstitution(institution_key); - configProfileCtrl.user.removeProfile(institution_key); - AuthService.save(); - } else { - AuthService.logout(); - } - } - function isAdminOfAnyInstitution() { return !_.isEmpty(configProfileCtrl.user.institutions_admin); } @@ -172,7 +153,7 @@ configProfileCtrl.deleteAccount = function deleteAccount(event) { if (!isAdminOfAnyInstitution()) { - var confirm = $mdDialog.confirm(); + const confirm = $mdDialog.confirm(); confirm .clickOutsideToClose(false) .title('Excluir conta') @@ -181,16 +162,16 @@ .targetEvent(event) .ok('Sim') .cancel('Não'); - var promise = $mdDialog.show(confirm); + const promise = $mdDialog.show(confirm); promise.then(function () { configProfileCtrl.user.state = 'inactive'; deleteUser(); }, function () { - MessageService.showToast('Cancelado'); + MessageService.showInfoToast('Cancelado'); }); return promise; } else { - MessageService.showToast('Não é possível excluir sua conta enquanto você for administrador de uma instituição.'); + MessageService.showErrorToast('Não é possível excluir sua conta enquanto você for administrador de uma instituição.'); } }; @@ -203,21 +184,92 @@ window.history.back(); }; + /** + * Sets save button's properties. + */ + configProfileCtrl.setSaveButton = () => { + configProfileCtrl.saveButton = { + class: 'config-profile__toolbar--save', + action: configProfileCtrl.finish, + name: 'SALVAR', + isAvailable: () => !configProfileCtrl.loadingSubmission + }; + }; + function deleteUser() { - var promise = UserService.deleteAccount(); + const promise = UserService.deleteAccount(); promise.then(function success() { AuthService.logout(); }); return promise; } - - (function main() { - observer = ObserverRecorderService.register(configProfileCtrl.user); - if (configProfileCtrl.user.name === 'Unknown') { - delete configProfileCtrl.user.name; - delete configProfileCtrl.newUser.name; - } - })(); - }); + /** + * Subscribe or Unsubscribe user for push notification + * according to configProfileCtrl.pushNotification model value. + */ + configProfileCtrl.pushChange = () => { + configProfileCtrl.pushNotification && configProfileCtrl._subscribeUser(); + !configProfileCtrl.pushNotification && configProfileCtrl._unsubscribeUser(); + }; + + /** + * Set configProfileCtrl.pushNotification according to the user's + * push notification subscription. + * True if push notification is active, false otherwise. + */ + function setPushNotificationModel() { + PushNotificationService.isPushNotificationActive().then((result) => { + configProfileCtrl.pushNotification = result; + }); + } + + /** + * Stop device from receive push notification + * @returns {Promise} + * @private + */ + configProfileCtrl._unsubscribeUser = () => { + return configProfileCtrl._openDialog().then(() => { + return PushNotificationService.unsubscribeUserNotification(); + }).catch(() => { + configProfileCtrl.pushNotification = true; + }); + }; + + /** + * Allow device to receive push notification + * @returns {Promise} + * @private + */ + configProfileCtrl._subscribeUser = () => { + return configProfileCtrl._openDialog().then(() => { + return PushNotificationService.subscribeUserNotification(); + }).catch(() => { + configProfileCtrl.pushNotification = false; + }); + }; + + /** + * Dialog to double check user's choice about push notification permission. + * @param event + * @returns {*|Promise|void} + * @private + */ + configProfileCtrl._openDialog = (event) => { + const DIALOG_TEXT_SUBSCRIBE = "Deseja permitir notificação no dispositivo?"; + const DIALOG_TEXT_UNSUBSCRIBE = "Tem certeza que não deseja receber notificação no dispositivo?"; + const DIALOG_TEXT = configProfileCtrl.pushNotification? DIALOG_TEXT_SUBSCRIBE : DIALOG_TEXT_UNSUBSCRIBE; + const confirm = $mdDialog.confirm(); + confirm + .clickOutsideToClose(false) + .title('Notificação no dispositivo') + .textContent(DIALOG_TEXT) + .ariaLabel('Notificação no dispositivo') + .targetEvent(event) + .ok('Sim') + .cancel('Não'); + return $mdDialog.show(confirm); + }; + } })(); \ No newline at end of file diff --git a/frontend/user/configProfile/config_profile.html b/frontend/user/configProfile/config_profile.html index bf935746f..1c23abd23 100644 --- a/frontend/user/configProfile/config_profile.html +++ b/frontend/user/configProfile/config_profile.html @@ -14,8 +14,8 @@

    - - + @@ -59,23 +59,23 @@

    Seus vínculos institucionais: - - + +
    + ng-click="configProfileCtrl.editProfile(profile, $event)" md-colors="{background: 'light-green'}"> edit + ng-click="configProfileCtrl.removeProfile($event, profile.institution)" md-colors="{background: 'light-green'}"> delete
    diff --git a/frontend/user/configProfile/config_profile_mobile.css b/frontend/user/configProfile/config_profile_mobile.css index f77b1f3b4..dac0e43ea 100644 --- a/frontend/user/configProfile/config_profile_mobile.css +++ b/frontend/user/configProfile/config_profile_mobile.css @@ -1,47 +1,69 @@ -.user-profile__container { +#config-profile__toolbar { + box-shadow: 0px 0px 1px rgba(0,0,0,0.5); + background-color: rgb(250,250,250); + color: black; + position: fixed; +} + +#config-profile__toolbar md-icon { + color: black; +} + +.config-profile__toolbar__title { + font-weight: 700; +} + + +.config-profile__toolbar--save { + margin-left: auto; + color: #84C45E; + font-weight: 700; +} + +.config-profile__container { display: grid; grid-template-rows: 17em min-content auto; overflow-x: hidden; } -.user-profile__header { +.config-profile__header { display: grid; grid-template-columns: 1fr; grid-template-rows: 2fr 1fr; } -.user-profile__header--shadow { +.config-profile__header--shadow { background-image: linear-gradient(#02554dd2, #009688); } -.user-profile__header--background { +.config-profile__header--background { background-color: #009688; height: 100%; } -.user-profile__back__icon { +.config-profile__back__icon { color: white; } -.user-profile__avatar--position { - justify-self: center; - position: absolute; - top: 7em; +.config-profile__avatar { + border-radius: 50%; + height: 9em; + width: 9em; } -.user-profile__avatar { - border-radius: 50%; - height: 8em; - width: 8em; +.config-profile__avatar--position { + justify-self: center; + position: absolute; + top: 6.5em; } -.user-profile__info { +.config-profile__info { display: grid; grid-template-columns: 1fr; grid-template-rows: auto; } -.user-profile__info--name { +.config-profile__info--name { margin: 0 1em; text-align: center; font-size: 1.4em; @@ -50,61 +72,57 @@ text-transform: uppercase; } -.user-profile__info--data { +.config-profile__info--data { font-size: 0.8em; margin: 1em 0 1em 2.5em; } -.user-profile__info--data > span { +.config-profile__info--data > span { color: #009688; text-transform: uppercase; font-weight: 700; } -.user-profile__info--divider { +.config-profile__info--divider { border: none; background-color: #84C45E; height: 4px; width: 35%; } -.user-profile__section__title { - margin: 0.5em auto; - text-transform: uppercase; - color: #004D41; - font-weight: 500; + +#config-profile__camera__button { + justify-self: center; + margin-top: -5.5em; + width: 10.3em; + height: 10.3em; + background-color: teal; + opacity: 0.5; } -.user-profile__content { - display: grid; - grid-row-gap: 1em; - margin-top: 1em; +#config-profile__photo__icon { + color: #ffffff; + font-size: 3em; + margin: -0.4em 0 0 1em; } -.user-profile__data { - display: grid; - grid-template-columns: 20% auto; - grid-template-rows: 1fr 10%; +.config-profile__container md-input-container { + width: 100%; + margin: 0.2em 0; } -.user-profile__data > img { - height: 3em; - width: 3em; - justify-self: center +.config-profile__form > md-input-container > label { + color: #009688 !important; } -.user-profile__data > div { - min-width: 0; - max-width: 95%; +.config-profile__form > md-input-container > input { + border-color: #009688; } -.user-profile__data > div > p { - margin: 0; - font-weight: 500; - text-transform: uppercase; - font-size: 0.9em; +.config-profile__form { + margin: 0 2em; } -.user-profile__data > md-divider { - grid-column: 1/3; +.config-profile__form > md-input-container > md-switch .md-container { + margin: auto 0 auto auto; } \ No newline at end of file diff --git a/frontend/user/configProfile/config_profile_mobile.html b/frontend/user/configProfile/config_profile_mobile.html index 15aa3caf0..b410a2ab0 100644 --- a/frontend/user/configProfile/config_profile_mobile.html +++ b/frontend/user/configProfile/config_profile_mobile.html @@ -1,40 +1,67 @@ -