Example #1
0
func (self *Backend) getBlobRefCollectionSelectors() map[*mongo.Collection][]string {
	return nil

	if self.imageRefCollectionSelectors == nil {
		colSel := make(map[*mongo.Collection][]string)
		for _, collection := range mongo.Collections {
			var doc BlobDoc // todo needs to be document type of collection
			collection.InitDocument(&doc)
			model.SetAllSliceLengths(&doc, 1)
			model.Visit(&doc, model.FieldOnlyVisitor(
				func(data *model.MetaData) error {
					if _, ok := data.Value.Addr().Interface().(*media.BlobRef); ok {
						if _, ok := colSel[collection]; !ok {
							colSel[collection] = nil
						}
						colSel[collection] = append(colSel[collection], data.WildcardSelector())
					}
					return nil
				},
			))
		}
		self.blobRefCollectionSelectors = colSel
	}
	return self.blobRefCollectionSelectors
}
Example #2
0
func InitRefs(document interface{}) {
	model.Visit(document, model.FieldOnlyVisitor(
		func(data *model.MetaData) error {
			if ref, ok := data.Value.Addr().Interface().(*Ref); ok && ref.CollectionName == "" {
				ref.CollectionName, ok = data.Attrib("to")
				if !ok {
					panic(data.Selector() + " is missing the 'to' meta-data tag")
				}
			}
			return nil
		},
	))
}
Example #3
0
func (self *LabeledModelView) Render(ctx *Context) (err error) {
	return model.Visit(self.Model, model.FieldOnlyVisitor(
		func(field *model.MetaData) error {
			if !self.IsFieldExcluded(field) {
				if value, ok := field.ModelValue(); ok {
					if !value.IsEmpty() || !self.HideEmpty {
						v := SPAN(Config.LabeledModelViewValueClass, value)
						label := &Label{
							Class:   Config.LabeledModelViewLabelClass,
							Content: Escape(self.FieldLabel(field)),
							For:     v,
						}
						return Views{label, v}.Render(ctx)
					}
				}
			}
			return nil
		},
	))
}
Example #4
0
func (self *query_base) UpdateSubDocument(selector string, subDocument interface{}) error {
	bsonQuery, err := bsonQuery(self.thisQuery)
	if err != nil {
		return err
	}
	if selector == "" {
		valMap := make(bson.M)
		model.VisitMaxDepth(subDocument, 1, model.FieldOnlyVisitor(
			func(field *model.MetaData) error {
				valMap[field.Name] = field.Value.Addr().Interface()
				return nil
			},
		))
		if len(valMap) == 0 {
			return nil
		}
		return self.Collection().collection.Update(bsonQuery, bson.M{"$set": valMap})
	}
	return self.Collection().collection.Update(bsonQuery, bson.M{"$set": bson.M{selector: subDocument}})
}
Example #5
0
func (self *Backend) getImageRefCollectionSelectors() map[*mongo.Collection][]string {
	if self.imageRefCollectionSelectors == nil {
		colSel := make(map[*mongo.Collection][]string)
		for _, collection := range mongo.Collections {
			doc := collection.NewDocument()
			model.SetAllSliceLengths(doc, 1)
			model.Visit(doc, model.FieldOnlyVisitor(
				func(data *model.MetaData) error {
					if _, ok := data.Value.Addr().Interface().(*media.ImageRef); ok {
						if _, ok := colSel[collection]; !ok {
							colSel[collection] = nil
						}
						colSel[collection] = append(colSel[collection], data.WildcardSelector())
					}
					return nil
				},
			))
		}
		self.imageRefCollectionSelectors = colSel
	}
	return self.imageRefCollectionSelectors
}