Compare commits

...

19 Commits

Author SHA1 Message Date
Antoine JOURDAIN 4f67b0bf0e enlever api
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 696a0bec00 dev
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN a09eab26ae Fusionnnn
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 50da11c8c1 Ajout vocabulaire
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN f414f8c385 Vocabulaire fonctionnel :)
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 095eecaaef dev
continuous-integration/drone/push Build is failing Details
1 year ago
Antoine JOURDAIN 6323707179 dev
1 year ago
Patrick BRUGIERE e13ce59447 legere modif de la page de modification
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 8bbc76c255 shit commit for future dev
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 276d9668f2 Merge branch 'blazor' of https://codefirst.iut.uca.fr/git/antoine.jourdain/SAE_2A_Anglais into blazor
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 4398571200 Déblayage pour taff
1 year ago
Patrick BRUGIERE 5786ee0e54 legere modif
continuous-integration/drone/push Build is failing Details
1 year ago
Antoine JOURDAIN 78954ae3d3 test encore
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 6ca57fb022 Revert "Encore un test docker..."
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 6163f7d4cf test
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 7fc82cf752 Encore un test docker...
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN 0221c0da46 Try fixing la CI
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN e26be60eb5 test ci
continuous-integration/drone/push Build is passing Details
1 year ago
Antoine JOURDAIN cedecba357 Test CI
continuous-integration/drone/push Build is passing Details
1 year ago

@ -74,6 +74,7 @@ steps:
CONTAINERNAME: api-in-english-please
COMMAND: create
OVERWRITE: true
CODEFIRST_CLIENTDRONE_ENV_BASE_PATH: /containers/antoinejourdain-api-in-english-please/
depends_on: [ docker-build-api ]
when:
branch:
@ -103,6 +104,7 @@ steps:
CONTAINERNAME: in-english-please
COMMAND: create
OVERWRITE: true
CODEFIRST_CLIENTDRONE_ENV_BASE_PATH: /containers/antoinejourdain-in-english-please/
depends_on: [ docker-build-app ]
when:
branch:

@ -34,7 +34,7 @@ namespace Minecraft.Crafting.Api.Controllers
/// <param name="item">The item.</param>
/// <returns>The async task.</returns>
[HttpPost]
[Route("")]
[Route("add")]
public Task Add(User item)
{
var data = JsonSerializer.Deserialize<List<User>>(System.IO.File.ReadAllText("Data/users.json"), _jsonSerializerOptions);
@ -46,6 +46,11 @@ namespace Minecraft.Crafting.Api.Controllers
// Simulate the Id
item.Id = data.Max(s => s.Id) + 1;
if(item.ImageBase64 == "string")
item.ImageBase64 = null;
if (item.Roles.FirstOrDefault() == "string")
item.Roles.Add("Student");
data.Add(item);

File diff suppressed because one or more lines are too long

@ -0,0 +1,35 @@
using adminBlazor.Models;
namespace adminBlazor.Factories;
public class TranslationFactory
{
public static Translation Create(TranslationModel model)
{
return new Translation
{
Id = model.Id,
FirstWord = model.FirstWord,
SecondWord = model.SecondWord
};
}
public static TranslationModel ToModel(Translation translation)
{
return new TranslationModel
{
Id = translation.Id,
FirstWord = translation.FirstWord,
SecondWord = translation.SecondWord
};
}
public static void Update(Translation item, TranslationModel model)
{
if (!string.IsNullOrEmpty(model.FirstWord))
item.FirstWord = model.FirstWord;
if (!string.IsNullOrEmpty(model.SecondWord))
item.SecondWord = model.SecondWord;
}
}

@ -9,34 +9,73 @@ namespace adminBlazor.Factories
{
public static class VocListFactory
{
public static VocabularyListModel ToModel(VocabularyList voc)
public static VocabularyListModel ToModel(VocabularyList voc, byte[] imageContent)
{
return new VocabularyListModel
VocabularyListModel model = new VocabularyListModel
{
Id = voc.Id,
Name = voc.Name,
Image = voc.Image,
Aut = voc.Aut
Aut = voc.Aut,
ImageBase64 = string.IsNullOrWhiteSpace(voc.ImageBase64) ? Convert.ToBase64String(imageContent) : voc.ImageBase64
};
model.Translations = new List<TranslationModel>();
foreach (var item in voc.Translations)
{
model.Translations.Add(new TranslationModel
{
Id = item.Id,
FirstWord = item.FirstWord,
SecondWord = item.SecondWord
});
}
return model;
}
public static VocabularyList Create(VocabularyListModel voc)
{
return new VocabularyList
VocabularyList model = new VocabularyList
{
Id = voc.Id,
Name = voc.Name,
Image = voc.Image,
Aut = voc.Aut
Aut = voc.Aut,
ImageBase64 = voc.Image != null ? Convert.ToBase64String(voc.Image) : null
};
model.Translations = new List<Translation>();
foreach (var item in voc.Translations)
{
model.Translations.Add(new Translation
{
Id = item.Id,
FirstWord = item.FirstWord,
SecondWord = item.SecondWord
});
}
return model;
}
public static void Update(VocabularyList item, VocabularyListModel voc)
{
if (!string.IsNullOrEmpty(voc.Name))
item.Name = voc.Name;
if (!string.IsNullOrEmpty(voc.Image))
item.Image = voc.Image;
if (voc.ImageBase64 != null && voc.Image != null)
item.ImageBase64 = Convert.ToBase64String(voc.Image);
if (voc.Aut != null)
item.Aut = voc.Aut;
if (voc.Translations == null) return;
item.Translations = new List<Translation>();
foreach (var translation in voc.Translations)
{
item.Translations.Add(new Translation
{
Id = translation.Id,
FirstWord = translation.FirstWord,
SecondWord = translation.SecondWord
});
}
}
}

@ -3,10 +3,9 @@ namespace adminBlazor.Models
{
public class Translation
{
private int id;
private string word1;
private string word2;
private int listVoc;
public int Id { get; set; }
public string FirstWord { get; set; }
public string SecondWord { get; set; }
}
}

@ -0,0 +1,15 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace adminBlazor.Models
{
public class TranslationModel
{
public int Id { get; set; }
[Required]
public string FirstWord { get; set; }
[Required]
public string SecondWord { get; set; }
}
}

@ -5,8 +5,11 @@ namespace adminBlazor.Models
{
public int Id { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public byte[] Image { get; set; }
public int? Aut { get; set; }
}
public string? ImageBase64 { get; set; }
public List<Translation>? Translations { get; set; }
}
}

@ -8,11 +8,16 @@ namespace adminBlazor.Models
[Required]
public int Id { get; set; }
[Required]
[StringLength(50, ErrorMessage = "Name length can't be more than 50.")]
public string Name { get; set; }
public string Image { get; set; }
public byte[] Image { get; set; }
public int? Aut { get; set; }
public string ImageBase64 { get; set; }
public List<TranslationModel>? Translations { get; set; }
}
}

@ -1,5 +1,6 @@
@page "/add"
@page "/addUser"
@attribute [Authorize(Roles = "admin")]
@using adminBlazor.Models
<h3>Add</h3>
<EditForm Model="@user" OnValidSubmit="@HandleValidSubmit">

@ -7,7 +7,7 @@ using adminBlazor.Services;
namespace adminBlazor.Pages
{
public partial class Add
public partial class AddUser
{
[Inject]
public NavigationManager NavigationManager { get; set; }
@ -26,7 +26,7 @@ namespace adminBlazor.Pages
/// <summary>
/// The current user model
/// </summary>
private Models.UserModel user = new Models.UserModel()
private UserModel user = new UserModel()
{
Roles = new List<string>()
};

@ -0,0 +1,44 @@
@page "/addVoc"
@attribute [Authorize(Roles = "teacher")]
@using adminBlazor.Models
@using Blazorise.Extensions
<h3>Add Vocabulary List</h3>
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="name">
Name:
<InputText id="name" @bind-Value="voc.Name" />
<ValidationMessage For="@(() => voc.Name)"/>
</label>
</p>
<h4>Words:</h4>
@if (voc.Translations.IsNullOrEmpty() == false)
{
foreach (var word in voc.Translations)
{
{
<div class="word-container">
<label>
First Word:
<InputText @bind-Value="word.FirstWord"/>
</label>
<label>
Second Word:
<InputText @bind-Value="word.SecondWord"/>
</label>
</div>
<button type="button" @onclick="() => RemoveWord(word)">Remove Word</button>
}
}
}
else
{
<p>No words</p>
}
<button type="button" @onclick="AddWord">Add Word</button>
<button type="submit">Submit</button>
</EditForm>

@ -0,0 +1,40 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components;
using adminBlazor.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;
using adminBlazor.Services;
namespace adminBlazor.Pages
{
public partial class AddVoc
{
[Inject] public NavigationManager NavigationManager { get; set; }
[Inject] public IVocListService VocService { get; set; }
private VocabularyListModel voc = new VocabularyListModel();
private async void HandleValidSubmit()
{
voc.Translations ??= new List<TranslationModel>();
await VocService.Add(voc);
NavigationManager.NavigateTo("voc");
}
private void AddWord()
{
if (voc.Translations == null)
{
voc.Translations = new List<TranslationModel>();
}
voc.Translations.Add(new TranslationModel());
}
private void RemoveWord(TranslationModel word)
{
voc.Translations.Remove(word);
}
}
}

@ -54,10 +54,9 @@ namespace adminBlazor.Pages
{
var item = await DataService.GetById(Id);
var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.jpeg");
var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.jpeg");
// Set the model with the item
user = UserFactory.ToModel(item,fileContent);
}

@ -1,29 +1,55 @@
@page "/editVoc/{Id:int}"
@attribute [Authorize(Roles = "teacher")]
@using adminBlazor.Models
@using Blazorise.Extensions
<h3>Edit</h3>
<h4>Voc id : @Id</h4>
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
@if (voc != null)
{
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="name">
Name:
<InputText id="name" @bind-Value="voc.Name" />
<ValidationMessage For="@(() => voc.Name)" />
</label>
<p>
<label for="name">
Name:
<InputText id="name" @bind-Value="voc.Name" />
<ValidationMessage For="@(() => voc.Name)" />
</label>
</p>
<p>
<label for="image">
Image:
<InputText id="image" @bind-Value="voc.Image" />
<ValidationMessage For="@(() => voc.Image)" />
</label>
</p>
<button type="submit">Submit</button>
</EditForm>
</p>
<h4>Words:</h4>
@if (voc.Translations.IsNullOrEmpty() == false)
{
foreach (var word in voc.Translations)
{
{
<div class="word-container">
<label>
First Word:
<InputText @bind-Value="word.FirstWord"/>
</label>
<label>
Second Word:
<InputText @bind-Value="word.SecondWord"/>
</label>
</div>
<button type="button" @onclick="() => RemoveWord(word)">Remove Word</button>
}
}
}
else
{
<p>No words</p>
}
<button type="button" @onclick="AddWord">Add Word</button>
<button type="submit">Submit</button>
</EditForm>
}
else
{
<p>Loading...</p>
}

@ -3,7 +3,11 @@ using adminBlazor.Models;
using adminBlazor.Services;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Hosting;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace adminBlazor.Pages
@ -22,23 +26,46 @@ namespace adminBlazor.Pages
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; }
public VocabularyList currVoc;
private VocabularyListModel voc = new VocabularyListModel();
private async void HandleValidSubmit()
{
await VocListService.Update(Id, voc);
NavigationManager.NavigateTo("list");
NavigationManager.NavigateTo("voc");
}
private async Task LoadImage(InputFileChangeEventArgs e)
{
// Set the content of the image to the model
using (var memoryStream = new MemoryStream())
{
await e.File.OpenReadStream().CopyToAsync(memoryStream);
voc.Image = memoryStream.ToArray();
}
}
private void AddWord()
{
if (voc.Translations == null)
{
voc.Translations = new List<TranslationModel>();
}
voc.Translations.Add(new TranslationModel());
}
private void RemoveWord(TranslationModel word)
{
voc.Translations.Remove(word);
}
protected async Task OnInitializedAsync()
protected override async Task OnInitializedAsync()
{
var item = await VocListService.GetById(Id);
voc = VocListFactory.ToModel(item);
var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.jpeg");
voc = VocListFactory.ToModel(item,fileContent);
}
}
}
}

@ -11,9 +11,7 @@
<h3>List</h3>
<div>
<NavLink class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
<i class="fa fa-plus"></i> Ajouter
</NavLink>
<a href="addUser" class="btn btn-primary" > <i class="fa fa-plus"></i> Ajouter </a>
</div>
<DataGrid TItem="User"

@ -10,6 +10,10 @@
<link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" />
<h3>Vocabulary Lists</h3>
<div>
<a href="addVoc" class="btn btn-primary" > <i class="fa fa-plus"></i> Ajouter </a>
</div>
<DataGrid TItem="VocabularyList"
Data="@_vocList"
ReadData="@OnReadData"
@ -18,9 +22,20 @@
ShowPager
Responsive>
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Id)" Caption="Image">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="@($"data:image/png;base64, {context.ImageBase64}")" class="img-thumbnail" style="min-width: 50px; max-width: 150px" />
}
else
{
<img src="images/words.jpg" class="img-thumbnail" style="max-width: 150px" />
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Id)" Caption="id" />
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Name)" Caption="Name" />
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Image)" Caption="Image" />
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Aut)" Caption="Author ID">
<DisplayTemplate>
@if (context is VocabularyList voc)

@ -1,5 +1,6 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Mvc.TagHelpers
@namespace adminBlazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@ -25,7 +25,6 @@ builder.Services.AddBlazoredModal();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddScoped<IDataService, DataApiService>();
builder.Services.AddScoped<IVocListService, VocListLocalService>();

@ -1,14 +1,5 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5138",
"dotnetRunMessages": true
},
"https": {
"commandName": "Project",
"launchBrowser": true,

@ -20,8 +20,8 @@
{
CurrentUser = new List<AppUser>
{
new AppUser { UserName = "Admin", Password = "123456", Roles = new List<string> { "admin" } },
new AppUser{ UserName ="Teacher1", Password = "123456", Roles = new List<string>{ "teacher" } }
new AppUser { UserName = "Admin", Password = "1", Roles = new List<string> { "admin" } },
new AppUser{ UserName = "Teacher", Password = "1", Roles = new List<string>{ "teacher" } }
};
}

@ -1,6 +1,7 @@
using adminBlazor.Components;
using adminBlazor.Factories;
using adminBlazor.Models;
using Microsoft.AspNetCore.Http.HttpResults;
using System.Reflection.Metadata.Ecma335;
namespace adminBlazor.Services
@ -24,24 +25,24 @@ namespace adminBlazor.Services
var item = UserFactory.Create(model);
// Save the data
await _http.PostAsJsonAsync("https://localhost:7234/api/User/", item);
await _http.PostAsJsonAsync("http://host.docker.internal:7234/api/User/", item);
}
public async Task<int> Count()
{
return await _http.GetFromJsonAsync<int>("https://localhost:7234/api/User/count");
return await _http.GetFromJsonAsync<int>("http://host.docker.internal:7234/api/User/count");
}
public async Task<List<User>> List(int currentPage, int pageSize)
{
_logger.LogInformation("User API : call of method LIST.");
return await _http.GetFromJsonAsync<List<User>>($"https://localhost:7234/api/User/?currentPage={currentPage}&pageSize={pageSize}");
return await _http.GetFromJsonAsync<List<User>>($"http://host.docker.internal:7234/api/User/?currentPage={currentPage}&pageSize={pageSize}");
}
public async Task<User> GetById(int id)
{
_logger.LogInformation("User API : call of method GetByID.");
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/User/{id}");
return await _http.GetFromJsonAsync<User>($"http://host.docker.internal:7234/api/User/{id}");
}
public async Task Update(int id, UserModel model)
@ -51,18 +52,18 @@ namespace adminBlazor.Services
_logger.LogInformation("User API : call of method UPDATE on User ID : {Id}.", id);
await _http.PutAsJsonAsync($"https://localhost:7234/api/User/{id}", item);
await _http.PutAsJsonAsync($"http://host.docker.internal:7234/api/User/{id}", item);
}
public async Task Delete(int id)
{
_logger.LogInformation("User API : call of method DELETE on User ID : {Id}.", id);
await _http.DeleteAsync($"https://localhost:7234/api/User/{id}");
await _http.DeleteAsync($"http://host.docker.internal:7234/api/User/{id}");
}
public async Task<List<CraftingRecipe>> GetRecipes()
{
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/User/recipe");
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("http://host.docker.internal:7234/api/User/recipe");
}
}
}

@ -49,7 +49,7 @@ namespace adminBlazor.Services
var originalList = await _http.GetFromJsonAsync<VocabularyList[]>($"{_navigationManager.BaseUri}voc.json");
await _localStorage.SetItemAsync("voc", originalList);
}
return (await _localStorage.GetItemAsync<VocabularyList[]>("voc")).Length;
}
@ -62,6 +62,7 @@ namespace adminBlazor.Services
{
// this code add in the local storage the fake data
var originalData = await _http.GetFromJsonAsync<VocabularyList[]>($"{_navigationManager.BaseUri}voc.json");
await _localStorage.SetItemAsync("voc", originalData);
}

@ -1,4 +1,5 @@
{
"https_port": 443,
"Creators": {
"Name": [
"Patrick Brugière",
@ -10,7 +11,8 @@
"Logging": {
"LogLevel": {
"Default": "Error",
"Microsoft": "Warning"
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.DataProtection": "None"
},
"Debug": {
"LogLevel": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

@ -2,13 +2,27 @@
{
"id": 1,
"name": "Entreprise",
"image": "link",
"aut": null
"image": null,
"aut": null,
"translations" : [{
"id": 1,
"firstWord" : "pain",
"secondWord" : "bread"
},
{"id": 1,
"firstWord" : "vin",
"secondWord" : "wine"
}]
},
{
"id": 2,
"name": "Animaux",
"image": "link",
"aut" : 1
"image": null,
"aut" : 1,
"translations": [{
"id": 1,
"firstWord" : "baguette",
"secondWord" : "pain"
}]
}
]
Loading…
Cancel
Save