Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class NewProposalCubit extends Cubit<NewProposalState>
throw StateError('Cannot create draft, category not selected');
}

final category = await _campaignService.getCategory(DocumentParameters({categoryRef}));
final templateRef = category.proposalTemplateRef;
final template = await _proposalService.getProposalTemplate(ref: templateRef);
final template = await _proposalService.getProposalTemplate(category: categoryRef);
final parameters = template.metadata.parameters;

final documentBuilder = DocumentBuilder.fromSchema(schema: template.schema)
Expand All @@ -56,7 +54,7 @@ class NewProposalCubit extends Cubit<NewProposalState>

return await _proposalService.createDraftProposal(
content: documentContent,
templateRef: templateRef,
templateRef: template.metadata.selfRef.toSignedDocumentRef(),
parameters: parameters,
);
} catch (error, stackTrace) {
Expand All @@ -83,16 +81,10 @@ class NewProposalCubit extends Cubit<NewProposalState>
// right now user can start creating proposal without selecting category.
// Right now every category have the same requirements for title so we can do a fallback for
// first category from the list.
final templateRef = campaign.categories
.cast<CampaignCategory?>()
.firstWhere(
(e) => e?.selfRef == categoryRef,
orElse: () => campaign.categories.firstOrNull,
)
?.proposalTemplateRef;

final template = templateRef != null
? await _proposalService.getProposalTemplate(ref: templateRef)
categoryRef ??= campaign.categories.firstOrNull?.selfRef;

final template = categoryRef != null
? await _proposalService.getProposalTemplate(category: categoryRef)
: null;
final titleRange = template?.title?.strLengthRange;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,17 @@ final class ProposalBuilderBloc extends Bloc<ProposalBuilderEvent, ProposalBuild
throw StateError('Cannot load proposal, active campaign not found');
}
final category = campaign.categories.first;
final templateRef = category.proposalTemplateRef;
final categoryRef = category.selfRef;

final proposalTemplate = await _proposalService.getProposalTemplate(ref: templateRef);
final proposalTemplate = await _proposalService.getProposalTemplate(category: categoryRef);
final templateParameters = proposalTemplate.metadata.parameters;
final documentBuilder = DocumentBuilder.fromSchema(schema: proposalTemplate.schema);

return _cacheAndCreateState(
proposalDocument: documentBuilder.build(),
proposalBuilder: documentBuilder,
proposalMetadata: ProposalBuilderMetadata.newDraft(
templateRef: templateRef,
templateRef: proposalTemplate.metadata.selfRef.toSignedDocumentRef(),
parameters: templateParameters,
),
category: category,
Expand Down Expand Up @@ -560,16 +560,15 @@ final class ProposalBuilderBloc extends Bloc<ProposalBuilderEvent, ProposalBuild

await _loadState(emit, () async {
final category = await _campaignService.getCategory(DocumentParameters({categoryRef}));
final templateRef = category.proposalTemplateRef;
final proposalTemplate = await _proposalService.getProposalTemplate(ref: templateRef);
final proposalTemplate = await _proposalService.getProposalTemplate(category: categoryRef);
final templateParameters = proposalTemplate.metadata.parameters;
final documentBuilder = DocumentBuilder.fromSchema(schema: proposalTemplate.schema);

return _cacheAndCreateState(
proposalDocument: documentBuilder.build(),
proposalBuilder: documentBuilder,
proposalMetadata: ProposalBuilderMetadata.newDraft(
templateRef: templateRef,
templateRef: proposalTemplate.metadata.selfRef.toSignedDocumentRef(),
parameters: templateParameters,
),
category: category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void main() {
categories: [
CampaignCategory(
selfRef: categoryRef,
proposalTemplateRef: SignedDocumentRef.generateFirstRef(),
campaignRef: SignedDocumentRef.generateFirstRef(),
categoryName: 'Test Category',
categorySubname: 'Test Subname',
Expand Down Expand Up @@ -129,7 +128,6 @@ void main() {
categories: [
CampaignCategory(
selfRef: categoryRef,
proposalTemplateRef: SignedDocumentRef.generateFirstRef(),
campaignRef: SignedDocumentRef.generateFirstRef(),
categoryName: 'Test Category',
categorySubname: 'Test Subname',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:equatable/equatable.dart';
/// Should have factory constructor from document representation.
class CampaignCategory extends Equatable {
final SignedDocumentRef selfRef;
final SignedDocumentRef proposalTemplateRef;
final SignedDocumentRef campaignRef;
final String categoryName;
final String categorySubname;
Expand All @@ -26,7 +25,6 @@ class CampaignCategory extends Equatable {

const CampaignCategory({
required this.selfRef,
required this.proposalTemplateRef,
required this.campaignRef,
required this.categoryName,
required this.categorySubname,
Expand All @@ -49,7 +47,6 @@ class CampaignCategory extends Equatable {
@override
List<Object?> get props => [
selfRef,
proposalTemplateRef,
campaignRef,
categoryName,
categorySubname,
Expand All @@ -68,7 +65,6 @@ class CampaignCategory extends Equatable {

CampaignCategory copyWith({
SignedDocumentRef? selfRef,
SignedDocumentRef? proposalTemplateRef,
SignedDocumentRef? campaignRef,
String? categoryName,
String? categorySubname,
Expand All @@ -87,7 +83,6 @@ class CampaignCategory extends Equatable {
}) {
return CampaignCategory(
selfRef: selfRef ?? this.selfRef,
proposalTemplateRef: proposalTemplateRef ?? this.proposalTemplateRef,
campaignRef: campaignRef ?? this.campaignRef,
categoryName: categoryName ?? this.categoryName,
categorySubname: categorySubname ?? this.categorySubname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ final class CampaignFilters extends Equatable {
return CampaignFilters(categoriesIds: categoriesIds);
}

factory CampaignFilters.from(Campaign campaign) {
final categoriesIds = campaign.categories.map((e) => e.selfRef.id).toSet().toList();
return CampaignFilters(categoriesIds: categoriesIds);
}

@override
List<Object?> get props => [categoriesIds];
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
final f14StaticCampaignCategories = [
CampaignCategory(
selfRef: f14ConstDocumentsRefs[0].category,
proposalTemplateRef: f14ConstDocumentsRefs[0].proposal,
campaignRef: Campaign.f14Ref,
categoryName: 'Cardano Use Case:',
categorySubname: 'Partners & Products',
Expand Down Expand Up @@ -93,7 +92,6 @@ The following will **not** be funded:
),
CampaignCategory(
selfRef: f14ConstDocumentsRefs[1].category,
proposalTemplateRef: f14ConstDocumentsRefs[1].proposal,
campaignRef: Campaign.f14Ref,
categoryName: 'Cardano Use Case:',
categorySubname: 'Concept',
Expand Down Expand Up @@ -176,7 +174,6 @@ The following will **not** be funded:
),
CampaignCategory(
selfRef: f14ConstDocumentsRefs[2].category,
proposalTemplateRef: f14ConstDocumentsRefs[2].proposal,
campaignRef: Campaign.f14Ref,
categoryName: 'Cardano Open:',
categorySubname: 'Developers',
Expand Down Expand Up @@ -261,7 +258,6 @@ The following will **not** be funded:
),
CampaignCategory(
selfRef: f14ConstDocumentsRefs[3].category,
proposalTemplateRef: f14ConstDocumentsRefs[3].proposal,
campaignRef: Campaign.f14Ref,
categoryName: 'Cardano Open:',
categorySubname: 'Ecosystem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ final f15StaticCampaignCategories = <CampaignCategory>[
//Tier-1 Enterprise Integrations
CampaignCategory(
selfRef: f15ConstDocumentsRefs[0].category,
proposalTemplateRef: f15ConstDocumentsRefs[0].proposal,
campaignRef: f15ConstDocumentsRefs[0].comment,
campaignRef: Campaign.f15Ref,
categoryName: 'Cardano Partners:',
categorySubname: 'Tier-1 Enterprise Integrations',
description:
Expand Down Expand Up @@ -139,8 +138,7 @@ Use this checklist to ensure your proposal meets all foundational and content re
//Cardano Use Cases: Prototype & Launch
CampaignCategory(
selfRef: f15ConstDocumentsRefs[1].category,
proposalTemplateRef: f15ConstDocumentsRefs[1].proposal,
campaignRef: f15ConstDocumentsRefs[1].comment,
campaignRef: Campaign.f15Ref,
categoryName: 'Cardano Use Cases:',
categorySubname: 'Prototype & Launch',
description:
Expand Down Expand Up @@ -247,8 +245,7 @@ Use this checklist to ensure your proposal meets all foundational and content re
// //Cardano Open: Ecosystem
CampaignCategory(
selfRef: f15ConstDocumentsRefs[2].category,
proposalTemplateRef: f15ConstDocumentsRefs[2].proposal,
campaignRef: f15ConstDocumentsRefs[2].comment,
campaignRef: Campaign.f15Ref,
categoryName: 'Cardano Open:',
categorySubname: 'Ecosystem',
description:
Expand Down Expand Up @@ -354,8 +351,7 @@ Use this checklist to ensure your proposal meets all foundational and content re
//Midnight: Compact DApps
CampaignCategory(
selfRef: f15ConstDocumentsRefs[3].category,
proposalTemplateRef: f15ConstDocumentsRefs[3].proposal,
campaignRef: f15ConstDocumentsRefs[3].comment,
campaignRef: Campaign.f15Ref,
categoryName: 'Midnight:',
categorySubname: 'Compact DApps',
description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:equatable/equatable.dart';

final class ActiveCampaignNotFoundException extends Equatable implements Exception {
const ActiveCampaignNotFoundException();

@override
List<Object?> get props => [];

@override
String toString() => 'ActiveCampaignNotFoundException';
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'campaign/campaign_category.dart';
export 'campaign/campaign_filters.dart';
export 'campaign/campaign_phase.dart';
export 'campaign/campaign_timeline.dart';
export 'campaign/exception/active_campaign_not_found_exception.dart';
export 'common/hi_lo/hi_lo.dart';
export 'common/hi_lo/uuid_hi_lo.dart';
export 'common/markdown_data.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@ import 'package:equatable/equatable.dart';
/// Groups related [proposal] and [comment] templates to given [category].
final class CategoryTemplatesRefs extends Equatable {
final SignedDocumentRef category;
final SignedDocumentRef proposal;
final SignedDocumentRef comment;
final SignedDocumentRef? proposal;
final SignedDocumentRef? comment;

const CategoryTemplatesRefs({
required this.category,
required this.proposal,
required this.comment,
this.proposal,
this.comment,
});

Iterable<SignedDocumentRef> get all => [category, proposal, comment];
Iterable<SignedDocumentRef> get all => [
category,
?proposal,
?comment,
];

Iterable<TypedDocumentRef> get allTyped {
return [
TypedDocumentRef(
ref: category,
type: DocumentType.categoryParametersDocument,
),
TypedDocumentRef(ref: proposal, type: DocumentType.proposalTemplate),
TypedDocumentRef(ref: comment, type: DocumentType.commentTemplate),
if (proposal case final value?)
TypedDocumentRef(ref: value, type: DocumentType.proposalTemplate),
if (comment case final value?)
TypedDocumentRef(ref: value, type: DocumentType.commentTemplate),
];
}

@override
List<Object?> get props => [category, proposal, comment];
List<Object?> get props => [
category,
proposal,
comment,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ abstract interface class DocumentsDao {
Future<List<DocumentEntity>> queryAll({
DocumentRef? ref,
DocumentType? type,
CampaignFilters? campaign,
});

/// Returns all known document refs.
Future<List<TypedDocumentRef>> queryAllTypedRefs();

Future<DocumentEntity?> queryLatestDocumentData({
DocumentType? type,
CatalystId? authorId,
DocumentRef? category,
});

/// Returns document with matching refTo and type.
Expand Down Expand Up @@ -219,6 +222,7 @@ class DriftDocumentsDao extends DatabaseAccessor<DriftCatalystDatabase>
Future<List<DocumentEntity>> queryAll({
DocumentRef? ref,
DocumentType? type,
CampaignFilters? campaign,
}) {
final query = select(documents);

Expand All @@ -228,6 +232,9 @@ class DriftDocumentsDao extends DatabaseAccessor<DriftCatalystDatabase>
if (type != null) {
query.where((doc) => doc.type.equals(type.uuid));
}
if (campaign != null) {
query.where((tbl) => tbl.metadata.isInCategoryList(campaign.categoriesIds));
}

return query.get();
}
Expand Down Expand Up @@ -285,16 +292,26 @@ class DriftDocumentsDao extends DatabaseAccessor<DriftCatalystDatabase>

@override
Future<DocumentEntity?> queryLatestDocumentData({
DocumentType? type,
CatalystId? authorId,
DocumentRef? category,
}) {
final query = select(documents)
..orderBy([(t) => OrderingTerm.desc(t.verHi)])
..limit(1);

if (type != null) {
query.where((tbl) => tbl.type.equalsValue(type));
}

if (authorId != null) {
query.where((tbl) => tbl.metadata.isAuthor(authorId));
}

if (category != null) {
query.where((tbl) => tbl.metadata.isInCategoryList([category.id]));
}

return query.getSingleOrNull();
}

Expand Down
Loading
Loading