ngIf user is logged in show component - html

I'm making an app that needs to be accessible for users without an account but as soon as someone makes an account they need to be able to see additional functionality and it needs to be responsive as well.
For responsiveness I'm using material design for bootstrap and angular materialmdbootstrap. In the example bellow I'd want to change the mdb-col-size from 9 to 12 depending on if the user is logged in or not and thus not display save,... option(s).
<div>
<div class="row ">
<div class="col-lg-9 col-md-8 col-sm-6 ">
<div class="row ">
<div class="col-md-12 mb-12">
<div class="card testimonial-card ">
<div class="card-up lighten-1 ">
<div class="card-body">
<h4 class="card-title">{{ dare.title }}</h4>
<hr />
<p>{{ dare.description }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-4 col-sm-6"><!--this shouldn't be displayed when someone is not logged in-->
<div class="row">
<div class="col-12">
<button mat-raised-button class="btn btn-block">
Save
</button>
</div>
</div>
<br />
<div class="row">
<div class="col-12">
<button mat-raised-button class="btn btn-block">
Challenge someone else
</button>
</div>
</div>
<br />
<div class="row">
<div class="col-12">
<button mat-raised-button class="btn btn-block">
Create new ...
</button>
</div>
</div>
</div>
</div>
<br />
</div>
I expect to see the options only when someone is logged in and the responsiveness changing accordingly.
Thanks you in advance!

You should rather use Guards in your project, example in documentation: https://angular.io/api/router/CanActivate
To achieve it you should implement two components (one for authenticated user, another for non-authenticated user). Define routing, for example:
{
path: '',
component: AuthenticatedUserComponent,
canActivate: [AuthenticatedUserGuard]
},
{
path: '',
component: UnauthenticatedUserComponent
}
And then define guard:
#Injectable()
class AuthenticatedUserGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
return true; // here you should call a method from service, that
// that holds whether user is authenticated or not
}
}

Related

handle Onclick event from Vue to Vuex

I'm switching from vue to vuex and I'm having trouble implementing an onclick event. I'm using bootstrap collapse to create 3 div. Each div has a button to show the collapsible elements inside. With vue I'm taking the data from an api request. I want every single button to open its parent div. Currently every button open all the three divs. When using vue I simply wrote this:
methods:{
//set expand to true foreach player card,
//set open to true foreach plus button
playerCardCollapse(index) {
this.teams = this.teams.map((item, i) => {
item.expanded = !item.expanded
item.open = !item.open
if (i !== index) {
item.expanded = false
item.open = false
}
return item
})
},
},
This is my template:
<!-- Container Card -->
<div v-for="(team, i) in teams" :key="i" class="col-6">
<div class="row mb-2 team-default align-items-center" style="height:106px;">
<div class="col-2 section">
<img class="rounded-circle" :src="team.team_img" style="border:2px solid #fff;box-shadow: 0 2px 31px 0 rgba(0, 0, 0, 0.23);">
</div>
<div class="col section team end">
<p class="intestazione">Team Name:</p>
<p class="result">{{team.team_name}}</p>
</div>
<div class="col-2 section end">
<button type="button" class="btnProfile" data-bs-toggle="collapse" data-bs-target="#profile-row" :aria-expanded="team.expanded" aria-controls="profile-row" #click.prevent="playerCardCollapse(i)">
<div class="plus-icon" :class="{open: team.open}"></div>
</button>
</div>
</div>
<!-- Collapsed -->
<div v-if="team.player.length>0">
<div class="collapse show" :class="{show: team.expanded}">
<div v-for="(p, j) in team.player" :key="j" class="row team-default mt-2 mb-3" id="profile-row">
<div class="col-2 section">
<div class="player-img-container">
<img class="rounded-circle player-img" :src="p.profilePic">
<img class="rounded-circle flag-img" src="https://picsum.photos/31/31">
</div>
</div>
<div class="col section team end">
<p class="intestazione">Team {{p.role}}</p>
<p class="result">{{p.name}}</p>
</div>
<div class="col-4 section end">
<button class="btnProfile-cta">Visualizza Profilo</button>
</div>
</div>
</div>
</div>
</div>
But with vuex I don't know how to implement this playerCardCollapse().
Hope someone could help (I don't know if you need more code snippets)

Order different div with Bootstrap

I can not order my different div as I wish.
First, I would like the card to be the same height as my title.
Then, I want the bottom of my 2 buttons are at the same height as the bottom of my card.
I guess this is possible but I'm stuck ... Could you help me?
<div class="container" style="width:auto;margin-top:0%">
<div class="row col-12">
<div class="5" style="margin-top:2%"><h3>Change your user profile</h3></div>
<div class="card border-primary md-5 col-6" style="width: auto; margin-left:51%">
<div class="card-header" style="font-size:22px">Attention</div>
<div class="card-body">
<p class="card-text">
The modified data must first be validated. <br /><br />
A request will be sent as soon as you click on "Submit". <br /><br />
It is normal that the old data is still displayed, it means that the validation has not been done yet.
</p>
</div>
</div>
<div>
<button type="button" class="btn btn-outline-primary" id="btnMember" onclick="hideCPY()">Personnal</button>
<button type="button" style="margin-left:1%" class="btn btn-outline-primary" id="btnShowCompany" onclick="hideMember()">Company</button>
</div>
</div>
[
You should remove the margin-left:51% given to your card as you do not need margins when working with bootstrap grid. Also, you should move the buttons into the same first column container in order to align them along with the title.
<div class="container" style="width:auto;margin-top:0%">
<div class="row col-12">
<div class="col-5" style="margin-top:2%">
<h3>Change your user profile</h3>
<div>
<button type="button" class="btn btn-outline-primary" id="btnMember" onclick="hideCPY()">Personnal</button>
<button type="button" style="margin-left:1%" class="btn btn-outline-primary" id="btnShowCompany" onclick="hideMember()">Company</button>
</div>
</div>
<div class="card border-primary md-5 col-6" style="width: auto;">
<div class="card-header" style="font-size:22px">Attention</div>
<div class="card-body">
<p class="card-text">
The modified data must first be validated. <br /><br />
A request will be sent as soon as you click on "Submit". <br /><br />
It is normal that the old data is still displayed, it means that the validation has not been done yet.
</p>
</div>
</div>
</div>
Also, I would highly recommend removing inline styles and using CSS classes instead.
Working fiddle here: http://jsfiddle.net/omxahu46/
Hope this helps.

Javascript voice control of html DOM

I work on sorting images on a website. I am given option to click either one of three buttons depending on the number of people in an image. The buttons have the below html structure and IDs.
<div>
<div class="col-6 col-md-3">
<button id="radio-0-choice-btn" class="submit-btn second-choice-btn">None</button>
</div>
<div class="col-6 col-md-3">
<button id="radio-1-choice-btn" class="submit-btn second-choice-btn">One</button>
</div>
<div class="col-6 col-md-3">
<button id="radio-2-choice-btn" class="submit-btn second-choice-btn">Two</button>
</div>
<div class="col-6 col-md-3">
<button id="radio-3-choice-btn" class="submit-btn second-choice-btn">Three +</button>
</div>
</div>
So if I decide the answer is button "Two", I want to be able to click ID "radio-2-choice-btn" using voice command.
Pardon me if I posted in the wrong group

Pages not loading in Single Page Application Angular JS

I am trying to implement Single Page Application in AngularJs. However, when I select the link ({{item.Name}} in Tree.Html). Corresponding view is not displayed in ng-View.
Any help will be appreciated
Main.html
<body ng-app="InfoModule" ng-controller="MainController" style="max-width:1000px; margin:auto">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Information</a>
</div>
<span class="pull-right navbar-text">{{UserName}}</span>
</div>
</nav>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
Info Page
<div ui-tree data-drag-enabled="false">
<ol ui-tree-nodes ng-model="itemList" class="font-weight-normal">
<li ng-repeat="item in itemList track by $index" ui-tree-node ng-include="'Tree.html'">
</li>
</ol>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div ng-include="Details"></div>
<div data-ng-view>
</div>
</div>
</div>
<div class="panel-footer">
(C) My Solutions
</div>
Tree.html
<div ui-tree-handle class="tree-node tree-node-content">
<a class="btn btn-success btn-xs" ng-if="item.nodes && item.nodes.length > 0" ng-click="toggle(this)">
<span class="glyphicon" ng-class="{'glyphicon-chevron-right': collapsed,'glyphicon-chevron-down': !collapsed}"></span>
</a>
<a href="#Details" >
{{item.Name}}
</a>
Master.js
var app = angular.module('InfoModule', ['ui.tree', 'ngRoute', 'ngStorage']);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/login', {
templateURL: 'Login.html',
controller: '/mYscriptS/LoginController.js'
})
.when('Details', {
templateURL: 'pages/Details.html',
controller: '../mYscriptS/DetailsController.js'
})
.when('/Main', {
templateURL: 'main.html',
controller: '/mYscriptS/MainController.js'
});
//.otherwise({
// redirectTo: 'pages/Main.html'
// //templateURL: '/Main.html',
// //controller: '/mYscriptS/MainController.js'
//});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$locationProvider.html5Mode(true);
}]);
Details.html
<div ng-controller="DetailsController" >
<div class="row">
<div class="col-md-6">
User Id
{{UserName}}
</div>
<div class="col-md-6">
<input type="text" name="txtUserId" />
</div>
</div>
<div class="row">
<div class="col-md-6">
Password
</div>
<div class="col-md-6">
<input type="text" name="txtPassword" />
</div>
</div>
Once I had gotten a problem that was same as yours.
I've tried to figure it out, and many people recommended using 'ui.router' instead of 'ngRoute'.
Maybe there are more differences between them specifically.
But even just this explain, could help you deciding side.
ngRoute is a angular core module which is good for basic scenarios. I believe that they will add more powerful features in upcoming releases.
Ui-router is a contributed module which is overcome the problems of ngRoute. Mainly Nested/Complex views.
URL: https://github.com/angular-ui/ui-router

Bootstrap 4 button inside card component that has click event

I have the following html code to generate a basic card using bootstrap 4.
I want to change the style of the card when the card is clicked. However, if the button is clicked, I dont want the style to change.
At the moment, when I click test1 button, I will also activate the function onCardClick().
Is there a way to do this such that when I click on the test button1 only Test1() executes
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card" (click)="onCardClick()">
<div class="card-block">
<h4 class="card-title d-inline">Some Title</h4>
<button class="btn btn-primary" (click)="onTest1()">test1</button>
<button class="btn btn-primary" (click)="onTest2()">test2</button>
</div>
</div>
</div>
You could try this to stop the event from bubbling up the dom:
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card"
(click)="onCardClick()">
<div class="card-block">
<h4 class="card-title d-inline">Some Title</h4>
<button class="btn btn-primary"
(click)="onTest1($event)">test1
</button>
<button class="btn btn-primary"
(click)="onTest2($event)">test2
</button>
</div>
</div>
</div>
</div>
</div>
And in your component:
import {Component} from "#angular/core"
#Component({
selector: 'test',
})
export class Test
{
onTest1(event)
{
event.stopPropagation();
//or event.preventDefault()
//stuff to run
}
onTest2(event)
{
event.stopPropagation();
//stuff to run
}
}