How do make ASP.NET React JS template usable? - c++

I have followed a Microsoft template to get an ASP.NET Core React JS project in visual studio 2022. The end product displays a list of weather forecasts with no navigability in the website. I am trying to convert the site to be more adaptable and start building my own project. I have attached a navbar file that I would like to implement, and the removal of the weather forecast. Please can someone tell me how to do this?
App.js
import React, { Component } from 'react';
import "bootstrap/dist/css/bootstrap.min.css";
import Navbar from './Navigation/Navbar.js';
export default class App extends Component {
static displayName = App.name;
constructor(props) {
super(props);
this.state = { forecasts: [], loading: true };
}
componentDidMount() {
this.populateWeatherData();
}
static renderForecastsTable(forecasts) {
return (
<table className='table table-striped' aria-labelledby="tabelLabel">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
{forecasts.map(forecast =>
<tr key={forecast.date}>
<td>{forecast.date}</td>
<td>{forecast.temperatureC}</td>
<td>{forecast.temperatureF}</td>
<td>{forecast.summary}</td>
</tr>
)}
</tbody>
</table>
);
}
render() {
let contents = this.state.loading
? <p><em>Loading... Please refresh once the ASP.NET backend has started. See https://aka.ms/jspsintegrationreact for more details.</em></p>
: App.renderForecastsTable(this.state.forecasts);
return (
<div>
<h1 id="tabelLabel" >Weather forecast</h1>
<p>This component demonstrates fetching data from the server.</p>
{contents}
</div>
);
}
async populateWeatherData() {
const response = await fetch('weatherforecast');
const data = await response.json();
this.setState({ forecasts: data, loading: false });
}
}
Index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
reportWebVitals();
Navbar.js
import React from "react";
const Navbar = () => {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<a className="navbar-brand" href="#">
Navbar
</a>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavDropdown">
<ul className="navbar-nav">
<li className="nav-item active">
<a className="nav-link" href="#">
Home <span className="sr-only">(current)</span>
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Features
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Pricing
</a>
</li>
<li className="nav-item dropdown">
<a
className="nav-link dropdown-toggle"
href="#"
id="navbarDropdownMenuLink"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Dropdown link
</a>
<div
className="dropdown-menu"
aria-labelledby="navbarDropdownMenuLink"
>
<a className="dropdown-item" href="#">
Action
</a>
<a className="dropdown-item" href="#">
Another action
</a>
<a className="dropdown-item" href="#">
Something else here
</a>
</div>
</li>
</ul>
</div>
</nav>
);
};
export default Navbar;

Related

How to show a detail page of a product with Laravel Livewire

I have a project in Laravel and Livewire.
This is my view displaying a list of projects submitted.
#forelse ($projects as $index => $project)
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<a href="#" wire:click="showProjectDetails({{ $project->slug }})"
class="block p-6 bg-white border border-gray-200 rounded-sm shadow-md hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-blue-500 dark:text-white">
{{ $project->title }}
</h5>
<p class="my-5">Bugdet Ghc500 - Ghc 700</p>
<p class="font-normal text-gray-700 dark:text-gray-400">{{ $project->description }}</p>
<ul class="flex gap-4 text-blue-600 mt-5">
<li>PHP</li>|
<li>Mobile App Development</li>|
<li>Database Management</li>|
<li>C++</li>
</ul>
</a>
</div>
#empty
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<p class="text-4xl">No Projects found</p>
</div>
#endforelse
When I click on a single project, a new view called show-project should display the details of the particular project that has been clicked.
My Livewire controller
public function showProjectDetails($slug)
{
return redirect()->route('show-project.details', $slug);
}
<a href="{{ route('show.project_details', ['slug' => $project->slug]) }}">
and web.php route can be either Controller or Livewire page.

create two users for same sub category in a box in DJANGO

I have 4 Users(2 X CP_USER, 2 X CP_SCRNS) and two subgroups(Login stats and Application stats) but two of then belong to one group and another 2 belong to another group.
Here is the screenshot.
Database
How to separate two group and display in the html page in the same box.Here is the referenceHere is the reference how the index page shouls look like.
.
Here is my models page:
from django.db import models
from datetime import datetime
Create your models here.
class Kpi_Data(models.Model):
kpi_key = models.CharField(max_length=200,default="")
kpi_date = models.DateField(blank=True,null=True)
kpi_value = models.CharField(max_length=200,default="")
kpi_Group = models.CharField(max_length=200,default="")
kpi_subgroup = models.CharField(max_length=200,default="")
kpi_delta_ind = models.CharField(max_length=200,default="")
Here is my views.py file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Kpi_Data
from django.template import loader
Create your views here.
def home(request):
return render(request,"myApp/index.html")
def info(request):
ac = Kpi_Data.objects.all()
template = loader.get_template('myApp/info.html')
Context = {
'ac': ac,
}
return HttpResponse(template.render(Context, request))
Here is my info.html page.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<style>
</style>
</head>
<nav class="navbar navbar-expand-xl navbar-dark bg-dark">
<div class = "logo"></div>
<img src= "" width="190" height="70" alt="">
</div>
enter code here
<!-- Collection of nav links, forms, and other content for toggling -->
<div class="input-group search-box">
<input type="text" id="search" class="form-control"
placeholder="Search here...">
</div>
</form>
<div class="navbar-nav ml-auto">
<a href="#" class="nav-item nav-link active"><i1 class="fa fa-
home"></i1></a>
<div class="nav-item dropdown">
<a href="#" data-toggle="dropdown" class="nav-item nav-link
dropdown-toggle user-action active">{{ request.headers.uid }}
</br>{{ request.headers.role}}</a>
<div class="dropdown-menu">
<a href="#" class="dropdown-item"><i class="fa fa-user-o">
</i> Profile</a>
<a href="#" class="dropdown-item"><i class="fa fa-calendar-
o"></i> Calendar</a>
<a href="#" class="dropdown-item"><i class="fa fa-sliders">
</i> Settings</a>
<div class="divider dropdown-divider"></div>
<a href="#" class="dropdown-item"><i class="material-
icons">ξΆ¬</i> Logout</a>
</div>
</div>
</div>
</nav>
<body>
<div class="sidebar">
<a class = "nav-item nav-link" href="#">Home</a>
Reference Data
`enter code here` Report Registration
Role Management
Role maintenence
User Roles
User Management
</br>
</div>
<h1>Login statistics</h1>
<h2>Appication statictics</h2>
<div class="footer fixed-bottom">
# Copyright Maryland.gov
All rights Reserved
Contatc us
Privacy & Security
Accessbility
</div>
</body>
</html>
Thanks in advance.
I see your code.
rows = Kpi_Data.objects.objects.values('kpi_group', 'kpi_subgroup',
'kpi_key').annotate(value=sum('kpi_value'))
L_C_U = L_C_S = A_C_U = A_C_S = 0`
for row in rows
if (row[kpi_Group]=='LOGIN_STATIS' and row[kpi_subgroup]='CONSUMER_PORTAL' and row[kpi_key]='CP_USER'):
L_C_U = row[value]
elif (row[kpi_Group]=='LOGIN_STATIS' and row[kpi_subgroup]='CONSUMER_PORTAL' and row[kpi_key]='CP_SCRNS'):
L_C_S = row[value]
....
Context = {
'LCU': L_C_U,
'LCS': L_C_S,
....
}
Then, in info.html, an template file, use LCU, LCS ... to display data.
I'm glad if above code would help you.

Login with FB button Framework7

im having a problem on implementing the login FB on my framework7 code. It just doesnt display the button, as follows:
<div class="panel panel-left panel-reveal">
<div class="content-block">
<p>Left panel content goes here</p>
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<button class="btn-default" scope="public_profile,email" onlogin="checkLoginState();">Login fb</button>
</div>
</div>
Any sugestion on how to tackle this problem?
Does your project is in cordova environment ? , I would suggest You using cordova fb plugin
https://github.com/Wizcorp/phonegap-facebook-plugin
Mine work like a charm
Login page
<li class="item-link">
<a class="signin button button-raised">Sign In</a>
</li>
<li class="item-link">
<a class="registerpage button button-raised">Register</a>
</li>
<li class="item-link">
<span id="facebookLogin" class="button button-fill color-blue">Login With Facebook</span>
</li>
<li class="item-link">
<span id="googleLogin" class="button button-fill color-red">Login With Google</span>
</li>
</ul>
</div>
init function
$('#facebookLogin').on('click', function () {
facebookLogin();
})
facebookLogin function
function facebookLogin() {
facebookConnectPlugin.login(["public_profile", "user_birthday", "user_hometown", "email"],
fbLoginSuccess,
function (error) { app.app.alert(JSON.stringify(error)) }
);
var fbLoginSuccess = function (userData) {
// use token from userData to your existing login system
//userData.authResponse.accessToken
};
}

MeteorJS get data passed to the template

I am a newbie in MeteorJS. I tried to do list with download and report buttons:
List template:
<template name="myBooks">
<div class="container">
<h2>My books</h2>
<div class="list-group">
{{#each myBooks}} {{> myBookListItem}} {{/each}}
</div>
</div>
</template>
myBookListItem Template:
<template name="myBookListItem">
<a class="list-group-item">
<span class="badge badge-success">{{downloads}}</span>
<span class="badge badge-error">{{warnings}}</span>
<h4 class="list-group-item-heading "><i>{{title}}</i> - {{author}}</h4>
<p class="list-group-item-text ">{{description}}</p>
<button type="submit" id="download" class="btn btn-success">Download</button>
<button type="submit" id="report" class="btn btn-danger">Report</button>
</a>
</template>
My book collection item contains also "link" property which is url to downloadable pdf - how can I access it on #download button click?
if (Meteor.isClient) {
Template.myBookListItem.events({
'click #download': function (event) {
//What_kind_of_magic_shoud_i_use_here()
alert();
},
'click #report': function (event) {
alert();
},
});
}
Anybody can help me:)?
I just needed to use this.link.

Using Sammy.js and Knockout.js with Templates Having Multiple Parameters

I have a website using Sammy and Knockout. I am trying to route multiple views to different URLs with Sammy but I'm having some difficulty. I need to pass the data parameter as well as the templateName parameter. How would I be able to pass the data parameter? I've included relevant code below.
Javascript
var View = function (title, templateName, data) {
var self = this;
this.title = title;
this.templateName = templateName;
this.data = data;
};
var viewModel = {
views: ko.observableArray([
new View("Home", "home", homeView),
new View("Announcements", "announcements", announcementView),
new View("Calendar", "calendar", monthView),
new View("Contact Us", "contactus", contactView),
new View("Events", "events", eventsView)
]),
selectedView: ko.observable()
};
$.sammy(function () {
this.get('#:templateName', function () {
viewModel.selectedView(this.params);
});
}).run('#home');
vbhtml
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand" href="#">Events</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav" data-bind="foreach: views">
<li data-bind="css: {active: $root.selectedView == $data"><a data-bind= "text: title, click: $root.selectedView " ></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Login</li>
</ul>
</div>
</div>
</nav>
<div data-bind="with: selectedView">
<div data-bind="template: { name: templateName, data: data }"></div>
</div>
<script id="home" type="text/html">...</script>
<script id="announcements" type="text/html">...</script>
<script id="calendar" type="text/html">...</script>
<script id="contactus" type="text/html">...</script>
Use the context parameter passed into the get's callback function
this.get('#:templateName', function(context) {
var params = context.params;
});
You should then be able to append querystring params and read them from the get function.
.run('#home?param1=1&param2=2')