mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-15 04:12:30 -06:00
feat: Add functionality to delete notes
This commit is contained in:
@@ -11,9 +11,18 @@ extension WidgetPadding on Widget {
|
||||
Widget paddedSymmetrically({
|
||||
double horizontal = 0.0,
|
||||
double vertical = 0.0,
|
||||
bool sliver = false,
|
||||
}) {
|
||||
final insets =
|
||||
EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical);
|
||||
if (sliver) {
|
||||
return SliverPadding(
|
||||
padding: insets,
|
||||
sliver: this,
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
|
||||
padding: insets,
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,47 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateNote(NoteModel note) async {
|
||||
assert(state.status == LoadingStatus.loaded);
|
||||
final document = state.document!;
|
||||
final updatedNotes = document.notes.map((e) => e.id == note.id ? note : e);
|
||||
try {
|
||||
final updatedDocument = await _api.update(
|
||||
state.document!.copyWith(
|
||||
notes: updatedNotes,
|
||||
),
|
||||
);
|
||||
_notifier.notifyUpdated(updatedDocument);
|
||||
} on PaperlessApiException catch (e) {
|
||||
addError(
|
||||
TransientPaperlessApiError(
|
||||
code: e.code,
|
||||
details: e.details,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteNote(NoteModel note) async {
|
||||
assert(state.status == LoadingStatus.loaded,
|
||||
"Document data has to be loaded before calling this method.");
|
||||
assert(note.id != null, "Note id cannot be null.");
|
||||
try {
|
||||
final updatedDocument = await _api.deleteNote(
|
||||
state.document!,
|
||||
note.id!,
|
||||
);
|
||||
_notifier.notifyUpdated(updatedDocument);
|
||||
} on PaperlessApiException catch (e) {
|
||||
addError(
|
||||
TransientPaperlessApiError(
|
||||
code: e.code,
|
||||
details: e.details,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignAsn(
|
||||
DocumentModel document, {
|
||||
int? asn,
|
||||
|
||||
@@ -240,130 +240,131 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
context.read(),
|
||||
documentId: widget.id,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16,
|
||||
horizontal: 16,
|
||||
),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentOverviewWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentContentWidget(
|
||||
document: state.document!,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
}
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentMetaDataWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
metaData: state.metaData!,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
],
|
||||
),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentOverviewWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentContentWidget(
|
||||
document: state.document!,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
}
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentMetaDataWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
metaData: state.metaData!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
controller: _pagingScrollController,
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
SimilarDocumentsView(
|
||||
pagingScrollController: _pagingScrollController,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentNotesWidget(
|
||||
document: state.document!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
],
|
||||
),
|
||||
if (hasMultiUserSupport)
|
||||
CustomScrollView(
|
||||
controller: _pagingScrollController,
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
SimilarDocumentsView(
|
||||
pagingScrollController:
|
||||
_pagingScrollController,
|
||||
),
|
||||
],
|
||||
),
|
||||
CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentNotesWidget(
|
||||
LoadingStatus.loaded =>
|
||||
DocumentPermissionsWidget(
|
||||
document: state.document!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
if (state.status == LoadingStatus.loaded)
|
||||
SliverToBoxAdapter(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
AddNoteRoute($extra: state.document!)
|
||||
.push(context);
|
||||
},
|
||||
icon: Icon(Icons.note_add_outlined),
|
||||
label: Text('Add note'),
|
||||
),
|
||||
),
|
||||
),
|
||||
}
|
||||
],
|
||||
),
|
||||
if (hasMultiUserSupport)
|
||||
CustomScrollView(
|
||||
controller: _pagingScrollController,
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(
|
||||
context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentPermissionsWidget(
|
||||
document: state.document!,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
}
|
||||
],
|
||||
]
|
||||
.map(
|
||||
(child) => Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class DocumentNotesWidget extends StatelessWidget {
|
||||
final DocumentModel document;
|
||||
@@ -9,30 +14,69 @@ class DocumentNotesWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliverList.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final note = document.notes.elementAt(index);
|
||||
return ListTile(
|
||||
title: Text(note.note),
|
||||
subtitle: Text(
|
||||
DateFormat.yMMMd(Localizations.localeOf(context).toString())
|
||||
.format(note.created)),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.edit),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: document.notes.length,
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
SliverList.separated(
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
||||
itemBuilder: (context, index) {
|
||||
final note = document.notes.elementAt(index);
|
||||
return Card(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// elevation: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (note.created != null)
|
||||
Text(
|
||||
DateFormat.yMMMd(
|
||||
Localizations.localeOf(context).toString())
|
||||
.addPattern('\u2014')
|
||||
.add_jm()
|
||||
.format(note.created!),
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
note.note!,
|
||||
textAlign: TextAlign.justify,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
// Push edit page
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
context.read<DocumentDetailsCubit>().deleteNote(note);
|
||||
showSnackBar(
|
||||
context,
|
||||
S.of(context)!.documentSuccessfullyUpdated,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
).padded(16),
|
||||
);
|
||||
},
|
||||
itemCount: document.notes.length,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EditNotePage extends StatefulWidget {
|
||||
const EditNotePage({super.key});
|
||||
|
||||
@override
|
||||
State<EditNotePage> createState() => _EditNotePageState();
|
||||
}
|
||||
|
||||
class _EditNotePageState extends State<EditNotePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user