i'm a newbie here, hope you could help me with my problem, i am having trouble with retaining the enabled status of my angular ui switch... whenever i refresh the page, it reverts back to disabled . but when i check the database, i could it has updated the value and the selected setting name for the selected ui switch. i want to retain the enabled status of my angular ui switch whenever i enabled it
here is my javascript
(function () {
'use strict';
angular.module('mainApp')
.controller('AdminSettingsController', AdminSettingsController);
function AdminSettingsController(
$scope
,$location
,AdminSettingsService
,$routeParams
) {
$scope.updateSettings = updateSettings;
$scope.getList = getList;
$scope.companyId = $routeParams.companyId;
function updateSettings(key, newStatus) {
AdminSettingsService.saveSetting(newStatus, key, $scope.companyId).then(function (responseObj) {
let data = responseObj.data;
console.log(data.settings)
let success = data.success;
$scope.settings = data.settings;
return data.settings;
});
}
function getList(key){
AdminSettingsService.getSetting(key).then(function (response) {
let data = response.data;
console.log('hardyharhar');
let success = data.success
});
}
}
})();
here is my html
<side-nav active-tab="'admin'"></side-nav>
<head-bar></head-bar>
<div class="br-mainpanel">
<div class="br-pageheader pd-y-15 pd-l-20">
<nav class="breadcrumb pd-0 mg-0 tx-12">
<a class="breadcrumb-item" href="#!/home">Dashboard</a>
<span class="breadcrumb-item active">Admin Settings</span>
</nav>
</div>
<div class="pd-x-5 pd-sm-x-30 pd-t-20 pd-sm-t-2">
<div class="d-flex align-items-center ">
<i class="icon ion-settings tx-54" style="margin-right: 1px;"></i>
<div class="mg-l-20">
<h4 class="tx-18 tx-gray-800 mg-b-5" style="size: 50px; font-weight: bold">Admin Settings</h4>
<span class="mg-b-0">Settings for company.</span>
</div>
<div id="ch5" class="ht-60 tr-y-1"></div>
</div>
</div>
<div class="br-pagebody">
<div class="br-section-wrapper">
<div class="br-pagebody pd-x-20 pd-sm-x-30">
<div class="card bd-0 shadow-base">
<div class="table-responsive">
<table class="table table-striped table-bordered mg-b-0">
<thead>
<th style="width: 10%" class="text-center">Action</th>
<th style="width: 40%" class="text-center">Settings</th>
<th style="width: 10%" class="text-center">Status</th>
</thead>
<tbody>
<tr class="text-center">
<td>
<switch ng-change="updateSettings('isReimbursementEnabled', reimbursementStatus)" id="state" name="state" ng-model="reimbursementStatus" class="blue"></switch>
</td>
<td class="text-left">
<h4>Reimbursement</h4>
<p>Allows processor to access reimbursement {{ reimbursementStatus }}.</p>
</td>
<td>
<h4> <span class= "{{ reimbursementStatus ? 'badge badge-pill badge-success' : 'badge badge-pill badge-secondary' }}">
{{ reimbursementStatus ? "Enabled" : "Disabled"}}
</span>
</h4>
</td>
</tr>
<tr class="text-center">
<td>
<switch ng-change="updateSettings('isReportsEnabled', reportsEnabled)" id="state" name="state" ng-model="reportsEnabled" class="blue"></switch>
</td>
<td class="text-left">
<h4 class="">Reports</h4>
<p>Allows processor to access reports.</p>
</td>
<td>
<h4> <span class="{{ reportsEnabled ? 'badge badge-pill badge-success' : 'badge badge-pill badge-secondary' }}" >
{{ reportsEnabled ? "Enabled" : "Disabled" }}
</span>
</h4>
</td>
</tr>
<tr class="text-center">
<td>
<switch ng-change="updateSettings('isAccountsEnabled', accountStatus)" id="state" name="state" ng-model="accountStatus" class="blue"></switch>
</td>
<td class="text-left">
<h4 class="">Accounts</h4>
<p>List of company accounts.</p>
</td>
<td>
<h4><span class="{{ accountStatus ? 'badge badge-pill badge-success' : 'badge badge-pill badge-secondary' }}" >
{{ accountStatus ? "Enabled" : "Disabled" }}
</span>
</h4>
</td>
</tr>
<tr class="text-center">
<td>
<switch ng-change="updateSettings('isReimbursementRequestLimitEnabled', requestStatus)" id="state" name="state" ng-model="requestStatus" class="blue"></switch>
</td>
<td class="text-left">
<h4 class="">Reimbursement Request Limit</h4>
<p>Sets the reimbursement request limit per year.</p>
</td>
<td>
<h4><span class="{{ requestStatus ? 'badge badge-pill badge-success' : 'badge badge-pill badge-secondary' }}">
{{ requestStatus ? "Enabled" : "Disabled" }}
</span>
</h4>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<foot-bar></foot-bar>
</div>
</div>
and here is my api controller
namespace App\Http\Controllers\Api;
use App\Criteria\LimitOffsetCriteria;
use App\Http\Controllers\Controller;
use App\Models\AdminSettings;
use App\Models\AccountSettings;
use App\Models\Account;
use App\Repositories\AccountRepositoryEloquent;
use App\Repositories\AdminSettingsRepositoryEloquent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class AdminSettingApiController extends Controller
{
private $adminSettingsRepository;
private $accountRepository;
public function __construct(
AdminSettingsRepositoryEloquent $adminSettingsRepo
,AccountRepositoryEloquent $accountRepo
)
{
$this->adminSettingsRepository = $adminSettingsRepo;
$this->accountRepository = $accountRepo;
}
public function saveSetting(Request $request) {
$newStatus = $request->input('newStatus');
$key = $request->input('key');
$companyId = $request->input('companyId');
$result = array(
'success' => false
);
$keyExist = $this->adminSettingsRepository->findByField('setting_name', $key)->first();
log::debug('thisisKeyExist.......................'.json_encode($keyExist));
$newStatusData = [
'setting_name' => $key,
'status' => $newStatus,
'company_id' => $companyId
];
try {
DB::beginTransaction();
if (!$keyExist) {
$newStatus = AdminSettings::create($newStatusData);
}
else {
$updateQuery = AdminSettings::where('setting_name', '=', $key);
$updateQuery->update($newStatusData);
}
$result['success'] = true;
$result['settings'] = $newStatusData;
DB::commit();
} catch (Exception $e) {
Log::error($e);
$result['success'] = false;
$result['messages'] = ['Server has encountered an unexpected error.'];
}
return $result;
}
public function list(Request $request){
$key = $request->input('key');
$result = array(
'success' => false
);
$keySetting = $this->adminSettingsRepository->findByField('setting_name', $key)->first();
$keyList = [];
try {
DB::beginTransaction();
$keyList = $this->adminSettingsRepository::where('status', '=', 1, 'setting_name')->get();
Log::debug('thisIsPrimarykey...................'.json_encode($keyList));
$result['key'] = $key;
$result['success'] = true;
DB::commit();
}
catch (\Exception $e){
Log::error($e);
$result['success'] = false;
}
}
}
hope you could help me thanks a lot! :)
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
Angular is one of the most powerful JavaScript frameworks out there. Google uses this platform to develop a Single Page Application (SPA). This development environment is known primarily because it provides developers with a better environment for combining JavaScript with HTML and CSS. More than half a million sites like google.com, youtube.com, etc. use Angular.
https://angular.io/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.