This commit is contained in:
ArifHilmi 2024-11-26 12:31:45 +08:00
parent 09fa8fc604
commit b378c73152
2 changed files with 60 additions and 55 deletions

View File

@ -99,24 +99,29 @@ namespace PSTW_CentralSystem.Controllers.API
return Json(qcList);
}
[HttpPost("addData")]
public async Task<IActionResult> addData([FromBody] ModuleSettingModel modelSettingList)
[HttpPost("AddModule")]
public async Task<IActionResult> AddModule([FromBody] ModuleSettingModel module)
{
var existingModule = await _authDbContext.ModuleSettings.Where(x => x.ModuleName.ToLower() == modelSettingList.ModuleName.ToLower()).FirstOrDefaultAsync();
if (existingModule != null)
if (!ModelState.IsValid)
{
return BadRequest("Module name already exists."); // Return a 400 Bad Request
return BadRequest(ModelState);
}
if (module == null)
{
return NotFound("Module is null");
}
// Add new module
modelSettingList.ModuleStatus = 1; // Default status
_authDbContext.ModuleSettings.Add(modelSettingList);
await _authDbContext.SaveChangesAsync();
return Json(modelSettingList);
try
{
_authDbContext.ModuleSettings.Add(module);
await _authDbContext.SaveChangesAsync();
var updatedList = await _authDbContext.ModuleSettings.ToListAsync();
return Json(updatedList);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}

View File

@ -50,37 +50,37 @@
</button>
</div>
<div class="form-group row">
<label class="col-md-3 mt-3">Add Method Rules</label>
<div class="col-md-9">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation" v-for="(setMethod, index) in moduleData.methodAllowedUserType" :key="index">
<a :class="['nav-link', activeTab === index ? 'active' : '']"
:id="'simple-tab-' + index"
data-bs-toggle="tab"
:href="'#simple-tabpanel-' + index"
role="tab"
:aria-controls="'simple-tabpanel-' + index"
:aria-selected="activeTab === index ? 'true' : 'false'">
{{ setMethod.methodName }}
</a>
</li>
</ul>
<div class="tab-content pt-5" id="tab-content">
<div :class="['tab-pane', activeTab === index ? 'active' : '']" :id="'simple-tabpanel-' + index" role="tabpanel" :aria-labelledby="'simple-tab-' + index" v-for="(setMethod, index) in moduleData.methodAllowedUserType" :key="index">
<p>Tab {{ setMethod.methodName }} selected</p>
<div class="form-group row">
<label class="col-md-1">Role:</label>
<div class="col-md-6">
<select class="select2 form-select shadow-none mt-3" multiple="multiple" style="height: 36px; width: 100%" v-model="moduleData.methodAllowedUserType[index].allowedUserTypesArray">
<option v-for="(roleType, index) in roleData" :key="index" :value="roleType.name">{{ roleType.name }}</option>
</select>
<label class="col-md-3 mt-3">Add Method Rules</label>
<div class="col-md-9">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation" v-for="(setMethod, index) in moduleData.methodAllowedUserType" :key="index">
<a :class="['nav-link', activeTab === index ? 'active' : '']"
:id="'simple-tab-' + index"
data-bs-toggle="tab"
:href="'#simple-tabpanel-' + index"
role="tab"
:aria-controls="'simple-tabpanel-' + index"
:aria-selected="activeTab === index ? 'true' : 'false'">
{{ setMethod.methodName }}
</a>
</li>
</ul>
<div class="tab-content pt-5" id="tab-content">
<div :class="['tab-pane', activeTab === index ? 'active' : '']" :id="'simple-tabpanel-' + index" role="tabpanel" :aria-labelledby="'simple-tab-' + index" v-for="(setMethod, index) in moduleData.methodAllowedUserType" :key="index">
<p>Tab {{ setMethod.methodName }} selected</p>
<div class="form-group row">
<label class="col-md-1">Role:</label>
<div class="col-md-6">
<select class="select2 form-select shadow-none mt-3" multiple="multiple" style="height: 36px; width: 100%" v-model="moduleData.methodAllowedUserType[index].allowedUserTypesArray">
<option v-for="(roleType, index) in roleData" :key="index" :value="roleType.name">{{ roleType.name }}</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="border-top">
<div class="card-body" v-on:click="saveData">
@ -143,7 +143,7 @@
mounted() {
this.fetchXModule();
this.fetchControllerMethodList();
},
},
watch: {
// Watching allowedUserType directly
// 'moduleData.allowedUserType'(newVal, oldVal) {
@ -158,20 +158,20 @@
fetchXModule() {
var id = @Model.SettingId
fetch('/ModuleAPI/GetXModuleInformation?id=' + id, {
method: 'POST'
})
.then(response => response.json())
.then(data => {
console.log(data);
if (data != null) {
this.moduleData = data;
this.fetchRoleList();
}
method: 'POST'
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
.then(response => response.json())
.then(data => {
console.log(data);
if (data != null) {
this.moduleData = data;
this.fetchRoleList();
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
},
fetchRoleList() {
fetch('/RoleAPI/GetRoleList', {
@ -196,7 +196,7 @@
},
fetchControllerMethodList() {
var moduleName = '@Model.ModuleName'
fetch('/AdminAPI/GetClassAndMethodInformation?moduleName=' + moduleName, {
fetch('/AdminAPI/GetClassAndMethodInformation?moduleName=' + moduleName, {
method: 'POST'
})
.then(response => response.json())
@ -277,7 +277,7 @@
filterAvailableMethods() {
const moduleMethods = this.moduleData.methodAllowedUserType.map(method => method.methodName);
this.availableMethod = this.controllerMethodData.methods.filter(method => !moduleMethods.includes(method)); // exclude methods that are already in moduleMethods
this.availableMethod = this.controllerMethodData.methods.filter(method => !moduleMethods.includes(method)); // exclude methods that are already in moduleMethods
},
}
})