Fix conflicts and issues.

This commit is contained in:
Igor Kulikov
2022-08-12 15:13:53 +03:00
23 changed files with 1482 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ import 'package:intl/intl.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/core/entity/entities_base.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/utils/utils.dart';
import 'package:thingsboard_client/thingsboard_client.dart';
@@ -249,7 +250,8 @@ class _AlarmCardState extends TbContextState<AlarmCard> {
child: IconButton(
icon: Icon(Icons.done, size: 18),
padding: EdgeInsets.all(7.0),
onPressed: () => _ackAlarm(alarm))),
onPressed: () =>
_ackAlarm(alarm, context))),
if ([
AlarmStatus.ACTIVE_UNACK,
AlarmStatus.ACTIVE_ACK
@@ -262,7 +264,8 @@ class _AlarmCardState extends TbContextState<AlarmCard> {
child: IconButton(
icon: Icon(Icons.clear, size: 18),
padding: EdgeInsets.all(7.0),
onPressed: () => _clearAlarm(alarm)))
onPressed: () =>
_clearAlarm(alarm, context)))
])
],
),
@@ -277,12 +280,12 @@ class _AlarmCardState extends TbContextState<AlarmCard> {
}
}
_clearAlarm(AlarmInfo alarm) async {
_clearAlarm(AlarmInfo alarm, BuildContext context) async {
var res = await confirm(
title: 'Clear Alarm',
message: 'Are you sure you want to clear Alarm?',
cancel: 'No',
ok: 'Yes');
title: '${S.of(context).alarmClearTitle}',
message: '${S.of(context).alarmClearText}',
cancel: '${S.of(context).No}',
ok: '${S.of(context).Yes}');
if (res != null && res) {
setState(() {
loading = true;
@@ -297,12 +300,12 @@ class _AlarmCardState extends TbContextState<AlarmCard> {
}
}
_ackAlarm(AlarmInfo alarm) async {
_ackAlarm(AlarmInfo alarm, BuildContext context) async {
var res = await confirm(
title: 'Acknowledge Alarm',
message: 'Are you sure you want to acknowledge Alarm?',
cancel: 'No',
ok: 'Yes');
title: '${S.of(context).alarmAcknowledgeTitle}',
message: '${S.of(context).alarmAcknowledgeText}',
cancel: '${S.of(context).No}',
ok: '${S.of(context).Yes}');
if (res != null && res) {
setState(() {
loading = true;

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/entity/entity_details_page.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_client/thingsboard_client.dart';
class AssetDetailsPage extends EntityDetailsPage<AssetInfo> {
@@ -24,16 +25,17 @@ class AssetDetailsPage extends EntityDetailsPage<AssetInfo> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Asset name', style: labelTextStyle),
Text('${S.of(context).assetName}', style: labelTextStyle),
Text(asset.name, style: valueTextStyle),
SizedBox(height: 16),
Text('Type', style: labelTextStyle),
Text('${S.of(context).type}', style: labelTextStyle),
Text(asset.type, style: valueTextStyle),
SizedBox(height: 16),
Text('Label', style: labelTextStyle),
Text('${S.of(context).label}', style: labelTextStyle),
Text(asset.label ?? '', style: valueTextStyle),
SizedBox(height: 16),
Text('Assigned to customer', style: labelTextStyle),
Text('${S.of(context).assignedToCustomer}',
style: labelTextStyle),
Text(asset.customerTitle ?? '', style: valueTextStyle),
]));
}

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/core/entity/entities_base.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/modules/audit_log/audit_logs_base.dart';
import 'package:thingsboard_app/widgets/tb_app_bar.dart';
import 'package:thingsboard_client/thingsboard_client.dart';
@@ -39,7 +40,7 @@ class _AuditLogDetailsPageState extends TbContextState<AuditLogDetailsPage> {
fontWeight: FontWeight.w500,
fontSize: 16,
height: 20 / 16)),
Text('Audit log details',
Text('${S.of(context).auditLogDetails}',
style: TextStyle(
color: Theme.of(context)
.primaryTextTheme
@@ -56,24 +57,24 @@ class _AuditLogDetailsPageState extends TbContextState<AuditLogDetailsPage> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Entity Type', style: labelTextStyle),
Text('${S.of(context).entityType}', style: labelTextStyle),
Text(entityTypeTranslations[widget.auditLog.entityId.entityType]!,
style: valueTextStyle),
SizedBox(height: 16),
Text('Type', style: labelTextStyle),
Text('${S.of(context).type}', style: labelTextStyle),
Text(actionTypeTranslations[widget.auditLog.actionType]!,
style: valueTextStyle),
SizedBox(height: 16),
Flexible(
fit: FlexFit.loose,
child: buildBorderedText('Action data',
child: buildBorderedText('${S.of(context).actionData}',
encoder.convert(widget.auditLog.actionData))),
if (widget.auditLog.actionStatus == ActionStatus.FAILURE)
SizedBox(height: 16),
if (widget.auditLog.actionStatus == ActionStatus.FAILURE)
Flexible(
fit: FlexFit.loose,
child: buildBorderedText('Failure details',
child: buildBorderedText('${S.of(context).failureDetails}',
widget.auditLog.actionFailureDetails!))
]),
),

View File

@@ -7,6 +7,7 @@ import 'package:thingsboard_app/constants/assets_path.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/core/entity/entities_base.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/utils/services/device_profile_cache.dart';
import 'package:thingsboard_app/utils/services/entity_query_api.dart';
import 'package:thingsboard_app/utils/utils.dart';
@@ -135,7 +136,7 @@ class _AllDevicesCardState extends TbContextState<AllDevicesCard> {
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('All devices',
Text('${S.of(context).allDevices}',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14,
@@ -414,7 +415,10 @@ Widget _buildDeviceCount(BuildContext context, bool active, int count) {
],
),
SizedBox(width: 8.67),
Text(active ? 'Active' : 'Inactive',
Text(
active
? '${S.of(context).active}'
: '${S.of(context).inactive}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,

View File

@@ -7,6 +7,7 @@ import 'package:thingsboard_app/constants/assets_path.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/core/entity/entities_base.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/utils/services/device_profile_cache.dart';
import 'package:thingsboard_app/utils/services/entity_query_api.dart';
import 'package:thingsboard_app/utils/utils.dart';
@@ -266,8 +267,8 @@ class _DeviceCardState extends TbContextState<DeviceCard> {
widget.device.attribute(
'active') ==
'true'
? 'Active'
: 'Inactive',
? '${S.of(context).active}'
: '${S.of(context).inactive}',
style: TextStyle(
color: widget.device
.attribute(

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/modules/device/devices_base.dart';
import 'package:thingsboard_app/modules/device/devices_list.dart';
import 'package:thingsboard_app/widgets/tb_app_bar.dart';
@@ -41,11 +42,14 @@ class _DevicesListPageState extends TbPageState<DevicesListPage> {
_deviceQueryController.onSearchText(searchText),
);
} else {
String titleText =
widget.deviceType != null ? widget.deviceType! : 'All devices';
String titleText = widget.deviceType != null
? widget.deviceType!
: '${S.of(context).allDevices}';
String? subTitleText;
if (widget.active != null) {
subTitleText = widget.active == true ? 'Active' : 'Inactive';
subTitleText = widget.active == true
? '${S.of(context).active}'
: '${S.of(context).inactive}';
}
Column title =
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/modules/alarm/alarms_page.dart';
import 'package:thingsboard_app/modules/device/devices_main_page.dart';
import 'package:thingsboard_app/modules/home/home_page.dart';
@@ -9,7 +10,7 @@ import 'package:thingsboard_client/thingsboard_client.dart';
class TbMainNavigationItem {
final Widget page;
final String title;
String title;
final Icon icon;
final String path;
@@ -80,6 +81,26 @@ class TbMainNavigationItem {
return [];
}
}
static void changeItemsTitleIntl(
List<TbMainNavigationItem> items, BuildContext context) {
for (var item in items) {
switch (item.path) {
case '/home':
item.title = '${S.of(context).home}';
break;
case '/alarms':
item.title = '${S.of(context).alarms}';
break;
case '/devices':
item.title = '${S.of(context).devices}';
break;
case '/more':
item.title = '${S.of(context).more}';
break;
}
}
}
}
class MainPage extends TbPageWidget {
@@ -129,6 +150,7 @@ class _MainPageState extends TbPageState<MainPage>
@override
Widget build(BuildContext context) {
TbMainNavigationItem.changeItemsTitleIntl(_tabItems, context);
return WillPopScope(
onWillPop: () async {
if (_tabController.index > 0) {

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_client/thingsboard_client.dart';
class MorePage extends TbContextWidget {
@@ -42,7 +43,7 @@ class _MorePageState extends TbContextState<MorePage> {
fontSize: 20,
height: 23 / 20)),
SizedBox(height: 2),
Text(_getAuthorityName(),
Text(_getAuthorityName(context),
style: TextStyle(
color: Color(0xFFAFAFAF),
fontWeight: FontWeight.normal,
@@ -65,7 +66,7 @@ class _MorePageState extends TbContextState<MorePage> {
child: Row(mainAxisSize: MainAxisSize.max, children: [
Icon(Icons.logout, color: Color(0xFFE04B2F)),
SizedBox(width: 34),
Text('Log out',
Text('${S.of(context).logout}',
style: TextStyle(
color: Color(0xFFE04B2F),
fontStyle: FontStyle.normal,
@@ -83,7 +84,8 @@ class _MorePageState extends TbContextState<MorePage> {
}
Widget buildMoreMenuItems(BuildContext context) {
List<Widget> items = MoreMenuItem.getItems(tbContext).map((menuItem) {
List<Widget> items =
MoreMenuItem.getItems(tbContext, context).map((menuItem) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: Container(
@@ -130,20 +132,20 @@ class _MorePageState extends TbContextState<MorePage> {
return name;
}
String _getAuthorityName() {
String _getAuthorityName(BuildContext context) {
var user = tbContext.userDetails;
var name = '';
if (user != null) {
var authority = user.authority;
switch (authority) {
case Authority.SYS_ADMIN:
name = 'System Administrator';
name = '${S.of(context).systemAdministrator}';
break;
case Authority.TENANT_ADMIN:
name = 'Tenant Administrator';
name = '${S.of(context).tenantAdministrator}';
break;
case Authority.CUSTOMER_USER:
name = 'Customer';
name = '${S.of(context).customer}';
break;
default:
break;
@@ -160,7 +162,8 @@ class MoreMenuItem {
MoreMenuItem({required this.title, required this.icon, required this.path});
static List<MoreMenuItem> getItems(TbContext tbContext) {
static List<MoreMenuItem> getItems(
TbContext tbContext, BuildContext context) {
if (tbContext.isAuthenticated) {
List<MoreMenuItem> items = [];
switch (tbContext.tbClient.getAuthUser()!.authority) {
@@ -169,19 +172,25 @@ class MoreMenuItem {
case Authority.TENANT_ADMIN:
items.addAll([
MoreMenuItem(
title: 'Customers',
title: '${S.of(context).customers}',
icon: Icons.supervisor_account,
path: '/customers'),
MoreMenuItem(title: 'Assets', icon: Icons.domain, path: '/assets'),
MoreMenuItem(
title: 'Audit Logs',
title: '${S.of(context).assets}',
icon: Icons.domain,
path: '/assets'),
MoreMenuItem(
title: '${S.of(context).auditLogs}',
icon: Icons.track_changes,
path: '/auditLogs')
]);
break;
case Authority.CUSTOMER_USER:
items.addAll([
MoreMenuItem(title: 'Assets', icon: Icons.domain, path: '/assets')
MoreMenuItem(
title: '${S.of(context).assets}',
icon: Icons.domain,
path: '/assets')
]);
break;
case Authority.REFRESH_TOKEN:

View File

@@ -3,6 +3,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:thingsboard_app/core/context/tb_context.dart';
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/widgets/tb_app_bar.dart';
import 'package:thingsboard_app/widgets/tb_progress_indicator.dart';
@@ -28,7 +29,7 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
backgroundColor: Colors.white,
appBar: TbAppBar(
tbContext,
title: const Text('Change Password'),
title: Text('${S.of(context).changePassword}'),
),
body: Stack(
children: [
@@ -54,7 +55,7 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(
errorText:
'Current password is required.')
'${S.of(context).currentPasswordRequireText}')
]),
decoration: InputDecoration(
suffixIcon: IconButton(
@@ -68,7 +69,8 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
},
),
border: OutlineInputBorder(),
labelText: 'Current password *'),
labelText:
'${S.of(context).currentPasswordStar}'),
);
}),
SizedBox(height: 24),
@@ -81,7 +83,8 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
obscureText: !showPassword,
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(
errorText: 'New password is required.')
errorText:
'${S.of(context).newPasswordRequireText}')
]),
decoration: InputDecoration(
suffixIcon: IconButton(
@@ -94,7 +97,8 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
},
),
border: OutlineInputBorder(),
labelText: 'New password *'),
labelText:
'${S.of(context).newPasswordStar}'),
);
}),
SizedBox(height: 24),
@@ -108,7 +112,7 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(
errorText:
'New password again is required.')
'${S.of(context).newPassword2RequireText}')
]),
decoration: InputDecoration(
suffixIcon: IconButton(
@@ -121,7 +125,8 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
},
),
border: OutlineInputBorder(),
labelText: 'New password again *'),
labelText:
'${S.of(context).newPassword2Star}'),
);
}),
SizedBox(height: 24),
@@ -132,7 +137,9 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
onPressed: () {
_changePassword();
},
child: Center(child: Text('Change Password')))
child: Center(
child:
Text('${S.of(context).changePassword}')))
]),
))),
),
@@ -161,7 +168,7 @@ class _ChangePasswordPageState extends TbContextState<ChangePasswordPage> {
String newPassword = formValue['newPassword'];
String newPassword2 = formValue['newPassword2'];
if (newPassword != newPassword2) {
showErrorNotification('Entered passwords must be same!');
showErrorNotification('${S.of(context).passwordErrorNotification}');
} else {
_isLoadingNotifier.value = true;
try {

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:thingsboard_app/generated/l10n.dart';
import 'package:thingsboard_app/modules/profile/change_password_page.dart';
import 'package:thingsboard_app/widgets/tb_app_bar.dart';
@@ -76,27 +77,29 @@ class _ProfilePageState extends TbPageState<ProfilePage> {
name: 'email',
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(
errorText: 'Email is required.'),
errorText:
'${S.of(context).emailRequireText}'),
FormBuilderValidators.email(
errorText: 'Invalid email format.')
errorText:
'${S.of(context).emailInvalidText}')
]),
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email *'),
labelText: '${S.of(context).emailStar}'),
),
SizedBox(height: 24),
FormBuilderTextField(
name: 'firstName',
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'First Name'),
labelText: '${S.of(context).firstNameUpper}'),
),
SizedBox(height: 24),
FormBuilderTextField(
name: 'lastName',
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Last Name'),
labelText: '${S.of(context).lastNameUpper}'),
),
SizedBox(height: 24),
OutlinedButton(
@@ -106,7 +109,9 @@ class _ProfilePageState extends TbPageState<ProfilePage> {
onPressed: () {
_changePassword();
},
child: Center(child: Text('Change Password')))
child: Center(
child:
Text('${S.of(context).changePassword}')))
]),
))),
),
@@ -156,7 +161,9 @@ class _ProfilePageState extends TbPageState<ProfilePage> {
_setUser();
await Future.delayed(Duration(milliseconds: 300));
_isLoadingNotifier.value = false;
showSuccessNotification('Profile successfully updated',
showSuccessNotification('${S.of(context).profileSuccessNotification}',
duration: Duration(milliseconds: 1500));
showSuccessNotification('${S.of(context).profileSuccessNotification}',
duration: Duration(milliseconds: 1500));
}
}
@@ -166,7 +173,7 @@ class _ProfilePageState extends TbPageState<ProfilePage> {
var res = await tbContext
.showFullScreenDialog<bool>(new ChangePasswordPage(tbContext));
if (res == true) {
showSuccessNotification('Password successfully changed',
showSuccessNotification('${S.of(context).passwordSuccessNotification}',
duration: Duration(milliseconds: 1500));
}
}