Skip to content

Commit

Permalink
update layout for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
thangchung committed Feb 9, 2021
1 parent 6bf518c commit 758b0b7
Show file tree
Hide file tree
Showing 20 changed files with 887 additions and 177 deletions.
1 change: 1 addition & 0 deletions coolstore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dapr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dbcontext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dtos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=exprs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Grpc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mediat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Migrator/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
42 changes: 42 additions & 0 deletions src/BuildingBlocks/N8T.Core/Specification/GridSpecificationBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using N8T.Core.Domain;

namespace N8T.Core.Specification
{
Expand All @@ -17,16 +18,49 @@ public abstract class GridSpecificationBase<T> : IGridSpecification<T>
public int Skip { get; private set; }
public bool IsPagingEnabled { get; set; }

protected void ApplyIncludeList(IEnumerable<Expression<Func<T, object>>> includes)
{
foreach (var include in includes)
{
AddInclude(include);
}
}

protected void AddInclude(Expression<Func<T, object>> includeExpression)
{
Includes.Add(includeExpression);
}

protected void ApplyIncludeList(IEnumerable<string> includes)
{
foreach (var include in includes)
{
AddInclude(include);
}
}

protected void AddInclude(string includeString)
{
IncludeStrings.Add(includeString);
}

protected IGridSpecification<T> ApplyFilterList(IEnumerable<FilterModel> filters)
{
foreach (var (fieldName, comparision, fieldValue) in filters)
{
ApplyFilter(PredicateBuilder.Build<T>(fieldName, comparision, fieldValue));
}

return this;
}

protected IGridSpecification<T> ApplyFilter(Expression<Func<T, bool>> expr)
{
Criterias.Add(expr);

return this;
}

protected void ApplyPaging(int skip, int take)
{
Skip = skip;
Expand All @@ -43,6 +77,14 @@ protected void ApplyOrderByDescending(Expression<Func<T, object>> orderByDescend
protected void ApplyGroupBy(Expression<Func<T, object>> groupByExpression) =>
GroupBy = groupByExpression;

protected void ApplySortingList(IEnumerable<string> sorts)
{
foreach (var sort in sorts)
{
ApplySorting(sort);
}
}

protected void ApplySorting(string sort)
{
this.ApplySorting(sort, nameof(ApplyOrderBy), nameof(ApplyOrderByDescending));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Linq.Expressions;

namespace N8T.Infrastructure.LambdaExpression
namespace N8T.Core.Specification
{
/// <summary>
/// https://codereview.stackexchange.com/questions/166460/chaining-multiple-predicates
Expand Down
16 changes: 16 additions & 0 deletions src/BuildingBlocks/N8T.Core/Specification/SpecificationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ public abstract class SpecificationBase<T> : ISpecification<T>
public int Skip { get; private set; }
public bool IsPagingEnabled { get; private set; }

protected void ApplyIncludeList(IEnumerable<Expression<Func<T, object>>> includes)
{
foreach (var include in includes)
{
AddInclude(include);
}
}

protected void AddInclude(Expression<Func<T, object>> includeExpression)
{
Includes.Add(includeExpression);
}

protected void ApplyIncludeList(IEnumerable<string> includes)
{
foreach (var include in includes)
{
AddInclude(include);
}
}

protected void AddInclude(string includeString)
{
IncludeStrings.Add(includeString);
Expand Down
1 change: 0 additions & 1 deletion src/BuildingBlocks/N8T.Infrastructure.EfCore/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using N8T.Core.Domain;
using N8T.Core.Repository;
using N8T.Core.Specification;
using N8T.Infrastructure.LambdaExpression;

namespace N8T.Infrastructure.EfCore
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace ProductService.Application.Queries
{
public class GetProductById
public static class GetProductById
{
public record Query : IItemQueryInput<Guid>, IQuery<ProductDto>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using N8T.Core.Domain;
using N8T.Core.Specification;
Expand All @@ -8,17 +9,15 @@ namespace ProductService.Core.Specifications
{
public sealed class ProductByIdQuerySpec : SpecificationBase<Product>
{
private readonly IItemQueryInput<Guid> _queryInput;
private readonly Guid _id;

public ProductByIdQuerySpec(IItemQueryInput<Guid> queryInput)
public ProductByIdQuerySpec([NotNull] IItemQueryInput<Guid> queryInput)
{
_queryInput = queryInput ?? throw new ArgumentNullException(nameof(queryInput));
foreach (var include in queryInput.Includes)
{
AddInclude(include);
}
ApplyIncludeList(queryInput.Includes);

_id = queryInput.Id;
}

public override Expression<Func<Product, bool>> Criteria => p => p.Id == _queryInput.Id;
public override Expression<Func<Product, bool>> Criteria => p => p.Id == _id;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using N8T.Core.Domain;
using N8T.Core.Specification;
using N8T.Infrastructure.LambdaExpression;
using ProductService.Core.Entities;

namespace ProductService.Core.Specifications
Expand All @@ -9,20 +8,11 @@ public sealed class ProductListQuerySpec : GridSpecificationBase<Product>
{
public ProductListQuerySpec(IListQueryInput gridQueryInput)
{
foreach (var include in gridQueryInput.Includes)
{
AddInclude(include);
}
ApplyIncludeList(gridQueryInput.Includes);

foreach (var (fieldName, comparision, fieldValue) in gridQueryInput.Filters)
{
Criterias.Add(PredicateBuilder.Build<Product>(fieldName, comparision, fieldValue));
}
ApplyFilterList(gridQueryInput.Filters);

foreach (var sort in gridQueryInput.Sorts)
{
ApplySorting(sort);
}
ApplySortingList(gridQueryInput.Sorts);

ApplyPaging(gridQueryInput.Page, gridQueryInput.PageSize);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Web/assets/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
// // Vendors variables override and path
@import "vendors/vendor";
@import "base/base";

#components-layout-demo-fixed .logo {
float: left;
width: 120px;
height: 31px;
margin: 16px 24px 16px 0;
background: rgba(255, 255, 255, 0.2);
}
.site-layout .site-layout-background {
background: #fff;
}
31 changes: 18 additions & 13 deletions src/Web/layout/MainLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from "react";
import { Container, Row, Col } from "reactstrap";
import styled from "styled-components";
import { Layout, Row, Col } from "antd";

/* Components */
import NavBar from "./nav/NavBar";
import Footer from "./foot/Footer";
import MyFooter from "./foot/MyFooter";

const MyRow = styled(Row)`
margin-top: 30px;
`
const { Header, Content, Footer } = Layout;

function MainLayout(mainProps) {
const { children } = mainProps;
Expand All @@ -17,13 +14,21 @@ function MainLayout(mainProps) {

return (
<>
<NavBar {...props} />
<Container fluid>
<MyRow>
<Col>{children}</Col>
</MyRow>
</Container>
<Footer />
<Layout>
<NavBar {...props} />
<Content
className="site-layout"
style={{ padding: "0 50px", marginTop: 100 }}
>
<div
className="site-layout-background"
style={{ padding: 24, minHeight: 600 }}
>
{children}
</div>
</Content>
<MyFooter />
</Layout>
</>
);
}
Expand Down
48 changes: 0 additions & 48 deletions src/Web/layout/foot/Footer.jsx

This file was deleted.

18 changes: 18 additions & 0 deletions src/Web/layout/foot/MyFooter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import { Layout } from "antd";

const { Footer } = Layout;

function MyFooter() {
return (
<Footer style={{ textAlign: "center" }}>
Copyright 2021 | Thang Chung. Fork this on&nbsp;
<a
href="https://github.com/thangchung/practical-clean-ddd"
className="text-dark"
>Github</a>
</Footer>
);
}

export default MyFooter;
59 changes: 32 additions & 27 deletions src/Web/layout/nav/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
import React from 'react';
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
NavbarText,
} from 'reactstrap';
import React from "react";
import { Layout, Menu } from "antd";

import Link from "next/link";
import { atom, useAtom } from "jotai";

const { Header } = Layout;
const selectNavAtom = atom(["/"]);

function NavBar() {
const toggleAtom = atom(false);
const [toggle, setToggle] = useAtom(toggleAtom);
const [selectNav, setSelectNav] = useAtom(selectNavAtom);

const handleClick = (e) => {
setSelectNav(() => e.key);
};

return (
<div>
<Navbar color="light" light expand="md">
<NavbarBrand href="/"><h5><b>eCommerce</b></h5></NavbarBrand>
<NavbarToggler onClick={() => {setToggle(!toggle)}} />
<Collapse isOpen={toggle} navbar>
<Nav className="mr-auto" navbar>
<NavItem>
<NavLink href="/products">Products</NavLink>
</NavItem>
</Nav>
<NavbarText>Thang Chung</NavbarText>
</Collapse>
</Navbar>
</div>
<>
<Header
id="components-layout-demo-fixed"
style={{ position: "fixed", zIndex: 1, width: "100%" }}
>
<div className="logo">eCommerce</div>
<Menu
theme="dark"
mode="horizontal"
selectedKeys={[selectNav]}
onClick={handleClick}
>
<Menu.Item key="/">
<Link href="/">Home</Link>
</Menu.Item>
<Menu.Item key="/products">
<Link href="/products">Products</Link>
</Menu.Item>
</Menu>
</Header>
</>
);
}

Expand Down
Loading

0 comments on commit 758b0b7

Please sign in to comment.